diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b9df236f7..aa3b9adb8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,7 @@ name: test on: - pull_request: - branches: [ main, releases-1.0.x ] + push: + branches: [ main, releases-1.0.x, feat/run-add-comment ] jobs: codegen: name: Codegen @@ -40,4 +40,4 @@ jobs: - name: verify go.mod and go.sum are consistent run : go mod tidy - name: Ensure nothing changed - run: git diff --exit-code \ No newline at end of file + run: git diff --exit-code diff --git a/mocks/run_mocks.go b/mocks/run_mocks.go index 6d40fc1cf..5db134d27 100644 --- a/mocks/run_mocks.go +++ b/mocks/run_mocks.go @@ -35,6 +35,20 @@ func (m *MockRuns) EXPECT() *MockRunsMockRecorder { return m.recorder } +// AddComment mocks base method. +func (m *MockRuns) AddComment(ctx context.Context, runID string, options tfe.RunCommentOptions) error { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "AddComment", ctx, runID, options) + ret0, _ := ret[0].(error) + return ret0 +} + +// AddComment indicates an expected call of AddComment. +func (mr *MockRunsMockRecorder) AddComment(ctx, runID, options interface{}) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddComment", reflect.TypeOf((*MockRuns)(nil).AddComment), ctx, runID, options) +} + // Apply mocks base method. func (m *MockRuns) Apply(ctx context.Context, runID string, options tfe.RunApplyOptions) error { m.ctrl.T.Helper() diff --git a/run.go b/run.go index 9a069efd0..0283a3baa 100644 --- a/run.go +++ b/run.go @@ -38,6 +38,9 @@ type Runs interface { // Discard a run by its ID. Discard(ctx context.Context, runID string, options RunDiscardOptions) error + + // AddComment to add a comment on a run. + AddComment(ctx context.Context, runID string, options RunCommentOptions) error } // runs implements Runs. @@ -278,6 +281,13 @@ type RunDiscardOptions struct { Comment *string `jsonapi:"attr,comment,omitempty"` } +// RunCommentOptions represents the options for a run comment. +type RunCommentOptions struct { + Type string `jsonapi:"primary,comments"` + Body *string `jsonapi:"attr,body,omitempty"` + Run *Run `jsonapi:"relation,run"` +} + // List all the runs of the given workspace. func (s *runs) List(ctx context.Context, workspaceID string, options *RunListOptions) (*RunList, error) { if !validStringID(&workspaceID) { @@ -411,6 +421,21 @@ func (s *runs) Discard(ctx context.Context, runID string, options RunDiscardOpti return s.client.do(ctx, req, nil) } +// AddComment to add a comment on a run. +func (s *runs) AddComment(ctx context.Context, runID string, options RunCommentOptions) error { + if !validStringID(&runID) { + return ErrInvalidRunID + } + + u := fmt.Sprintf("runs/%s/comments", url.QueryEscape(runID)) + req, err := s.client.newRequest("POST", u, &options) + if err != nil { + return err + } + + return s.client.do(ctx, req, nil) +} + func (o RunCreateOptions) valid() error { if o.Workspace == nil { return ErrRequiredWorkspace