diff --git a/apps.gen.go b/apps.gen.go index 0232ae9..6fc029c 100644 --- a/apps.gen.go +++ b/apps.gen.go @@ -466,8 +466,7 @@ type AppLogDestinationSpecPapertrail struct { type AppMaintenanceSpec struct { // Indicates whether maintenance mode should be enabled for the app. Enabled bool `json:"enabled,omitempty"` - // Indicates whether the app should be archived. Setting this to true implies that enabled is set to true. - // Note that this feature is currently in closed beta. + // Indicates whether the app should be archived. Setting this to true implies that enabled is set to true. Note that this feature is currently in closed beta. Archive bool `json:"archive,omitempty"` } @@ -1004,6 +1003,7 @@ const ( DeploymentCauseDetailsDigitalOceanUserActionName_RollbackApp DeploymentCauseDetailsDigitalOceanUserActionName = "ROLLBACK_APP" DeploymentCauseDetailsDigitalOceanUserActionName_RevertAppRollback DeploymentCauseDetailsDigitalOceanUserActionName = "REVERT_APP_ROLLBACK" DeploymentCauseDetailsDigitalOceanUserActionName_UpgradeBuildpack DeploymentCauseDetailsDigitalOceanUserActionName = "UPGRADE_BUILDPACK" + DeploymentCauseDetailsDigitalOceanUserActionName_Restart DeploymentCauseDetailsDigitalOceanUserActionName = "RESTART" ) // AppDomain struct for AppDomain diff --git a/apps.go b/apps.go index 24fe738..97b0cbd 100644 --- a/apps.go +++ b/apps.go @@ -35,6 +35,7 @@ type AppsService interface { Delete(ctx context.Context, appID string) (*Response, error) Propose(ctx context.Context, propose *AppProposeRequest) (*AppProposeResponse, *Response, error) + Restart(ctx context.Context, appID string, opts *AppRestartRequest) (*Deployment, *Response, error) GetDeployment(ctx context.Context, appID, deploymentID string) (*Deployment, *Response, error) ListDeployments(ctx context.Context, appID string, opts *ListOptions) ([]*Deployment, *Response, error) CreateDeployment(ctx context.Context, appID string, create ...*DeploymentCreateRequest) (*Deployment, *Response, error) @@ -95,6 +96,11 @@ type DeploymentCreateRequest struct { ForceBuild bool `json:"force_build"` } +// AppRestartRequest represents a request to restart an app. +type AppRestartRequest struct { + Components []string `json:"components"` +} + // AlertDestinationUpdateRequest represents a request to update alert destinations. type AlertDestinationUpdateRequest struct { Emails []string `json:"emails"` @@ -285,6 +291,22 @@ func (s *AppsServiceOp) Propose(ctx context.Context, propose *AppProposeRequest) return res, resp, nil } +// Restart restarts an app. +func (s *AppsServiceOp) Restart(ctx context.Context, appID string, opts *AppRestartRequest) (*Deployment, *Response, error) { + path := fmt.Sprintf("%s/%s/restart", appsBasePath, appID) + + req, err := s.client.NewRequest(ctx, http.MethodPost, path, opts) + if err != nil { + return nil, nil, err + } + root := new(deploymentRoot) + resp, err := s.client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + return root.Deployment, resp, nil +} + // GetDeployment gets an app deployment. func (s *AppsServiceOp) GetDeployment(ctx context.Context, appID, deploymentID string) (*Deployment, *Response, error) { path := fmt.Sprintf("%s/%s/deployments/%s", appsBasePath, appID, deploymentID) diff --git a/apps_test.go b/apps_test.go index 5ffa2d9..a67ed3a 100644 --- a/apps_test.go +++ b/apps_test.go @@ -427,6 +427,46 @@ func TestApps_ProposeApp(t *testing.T) { assert.True(t, res.AppNameAvailable) } +func TestApps_Restart(t *testing.T) { + for _, tc := range []struct { + name string + components []string + }{ + { + name: "all", + components: nil, + }, + { + name: "specific", + components: []string{"service1", "service2"}, + }, + } { + t.Run(tc.name, func(t *testing.T) { + setup() + defer teardown() + + ctx := context.Background() + + mux.HandleFunc(fmt.Sprintf("/v2/apps/%s/restart", testApp.ID), func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodPost) + + var req AppRestartRequest + err := json.NewDecoder(r.Body).Decode(&req) + require.NoError(t, err) + assert.Equal(t, tc.components, req.Components) + + json.NewEncoder(w).Encode(&deploymentRoot{Deployment: &testDeployment}) + }) + + deployment, _, err := client.Apps.Restart(ctx, testApp.ID, &AppRestartRequest{ + Components: tc.components, + }) + require.NoError(t, err) + assert.Equal(t, &testDeployment, deployment) + }) + } +} + func TestApps_CreateDeployment(t *testing.T) { for _, forceBuild := range []bool{true, false} { t.Run(fmt.Sprintf("ForceBuild_%t", forceBuild), func(t *testing.T) {