From 70e09f3a67bab276872f27d83d8d4a9ed529eec9 Mon Sep 17 00:00:00 2001 From: Alexandre Dath Date: Wed, 9 Mar 2022 15:14:42 +0100 Subject: [PATCH 1/5] Add AddComment on Run struct --- run.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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 From 33910007818cd82905bb223bb068602c48f194dd Mon Sep 17 00:00:00 2001 From: Alexandre DATH Date: Wed, 9 Mar 2022 15:48:17 +0100 Subject: [PATCH 2/5] Update ci.yml --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b9df236f7..d22b0a9bc 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 ] + branches: [ main, releases-1.0.x, 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 From bce4235dd472893317329cc4b149a44c6bb20157 Mon Sep 17 00:00:00 2001 From: Alexandre DATH Date: Wed, 9 Mar 2022 15:48:47 +0100 Subject: [PATCH 3/5] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d22b0a9bc..d8193ca69 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, run-add-comment ] + branches: [ main, releases-1.0.x, feat/run-add-comment ] jobs: codegen: name: Codegen From ab814b548948a690d708c3e124b3cdae0580ee26 Mon Sep 17 00:00:00 2001 From: Alexandre DATH Date: Wed, 9 Mar 2022 15:49:28 +0100 Subject: [PATCH 4/5] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d8193ca69..aa3b9adb8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,6 @@ name: test on: - pull_request: + push: branches: [ main, releases-1.0.x, feat/run-add-comment ] jobs: codegen: From a4f180e728df3aad9a4d94017298ceec0db7394d Mon Sep 17 00:00:00 2001 From: Alexandre Dath Date: Wed, 9 Mar 2022 15:54:21 +0100 Subject: [PATCH 5/5] Generate mock --- mocks/run_mocks.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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()