Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AddComment on Run struct #354

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .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
Expand Down Expand Up @@ -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
run: git diff --exit-code
14 changes: 14 additions & 0 deletions mocks/run_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions run.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down