Skip to content

Commit

Permalink
added API to add/remove issue label
Browse files Browse the repository at this point in the history
  • Loading branch information
jstrachan committed Jul 8, 2019
1 parent a359145 commit 8a85339
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 0 deletions.
3 changes: 3 additions & 0 deletions scm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ const (
DriverBitbucket
DriverStash
DriverCoding
DriverFake
)

// String returns the string representation of Driver.
Expand All @@ -163,6 +164,8 @@ func (d Driver) String() (s string) {
return "stash"
case DriverCoding:
return "coding"
case DriverFake:
return "fake"
default:
return "unknown"
}
Expand Down
8 changes: 8 additions & 0 deletions scm/driver/bitbucket/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ type issueService struct {
client *wrapper
}

func (s *issueService) AddLabel(ctx context.Context, repo string, number int, label string) (*scm.Response, error) {
return nil, scm.ErrNotSupported
}

func (s *issueService) DeleteLabel(ctx context.Context, repo string, number int, label string) (*scm.Response, error) {
return nil, scm.ErrNotSupported
}

func (s *issueService) Find(ctx context.Context, repo string, number int) (*scm.Issue, *scm.Response, error) {
return nil, nil, scm.ErrNotSupported
}
Expand Down
8 changes: 8 additions & 0 deletions scm/driver/gitea/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ type issueService struct {
client *wrapper
}

func (s *issueService) AddLabel(ctx context.Context, repo string, number int, label string) (*scm.Response, error) {
return nil, scm.ErrNotSupported
}

func (s *issueService) DeleteLabel(ctx context.Context, repo string, number int, label string) (*scm.Response, error) {
return nil, scm.ErrNotSupported
}

func (s *issueService) Find(ctx context.Context, repo string, number int) (*scm.Issue, *scm.Response, error) {
path := fmt.Sprintf("api/v1/repos/%s/issues/%d", repo, number)
out := new(issue)
Expand Down
12 changes: 12 additions & 0 deletions scm/driver/github/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ func (s *issueService) Create(ctx context.Context, repo string, input *scm.Issue
return convertIssue(out), res, err
}

func (s *issueService) AddLabel(ctx context.Context, repo string, number int, label string) (*scm.Response, error) {
path := fmt.Sprintf("repos/%s/issues/%d/labels", repo, number)
in := []string{label}
res, err := s.client.do(ctx, "POST", path, in, nil)
return res, err
}

func (s *issueService) DeleteLabel(ctx context.Context, repo string, number int, label string) (*scm.Response, error) {
path := fmt.Sprintf("repos/%s/issues/labels/%s", repo, label)
return s.client.do(ctx, "DELETE", path, nil, nil)
}

func (s *issueService) CreateComment(ctx context.Context, repo string, number int, input *scm.CommentInput) (*scm.Comment, *scm.Response, error) {
path := fmt.Sprintf("repos/%s/issues/%d/comments", repo, number)
in := &issueCommentInput{
Expand Down
8 changes: 8 additions & 0 deletions scm/driver/gitlab/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ type issueService struct {
client *wrapper
}

func (s *issueService) AddLabel(ctx context.Context, repo string, number int, label string) (*scm.Response, error) {
return nil, scm.ErrNotSupported
}

func (s *issueService) DeleteLabel(ctx context.Context, repo string, number int, label string) (*scm.Response, error) {
return nil, scm.ErrNotSupported
}

func (s *issueService) Find(ctx context.Context, repo string, number int) (*scm.Issue, *scm.Response, error) {
path := fmt.Sprintf("api/v4/projects/%s/issues/%d", encode(repo), number)
out := new(issue)
Expand Down
8 changes: 8 additions & 0 deletions scm/driver/gogs/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ type issueService struct {
client *wrapper
}

func (s *issueService) AddLabel(ctx context.Context, repo string, number int, label string) (*scm.Response, error) {
return nil, scm.ErrNotSupported
}

func (s *issueService) DeleteLabel(ctx context.Context, repo string, number int, label string) (*scm.Response, error) {
return nil, scm.ErrNotSupported
}

func (s *issueService) Find(ctx context.Context, repo string, number int) (*scm.Issue, *scm.Response, error) {
path := fmt.Sprintf("api/v1/repos/%s/issues/%d", repo, number)
out := new(issue)
Expand Down
8 changes: 8 additions & 0 deletions scm/driver/stash/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ type issueService struct {
client *wrapper
}

func (s *issueService) AddLabel(ctx context.Context, repo string, number int, label string) (*scm.Response, error) {
return nil, scm.ErrNotSupported
}

func (s *issueService) DeleteLabel(ctx context.Context, repo string, number int, label string) (*scm.Response, error) {
return nil, scm.ErrNotSupported
}

func (s *issueService) Find(ctx context.Context, repo string, number int) (*scm.Issue, *scm.Response, error) {
return nil, nil, scm.ErrNotSupported
}
Expand Down
6 changes: 6 additions & 0 deletions scm/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,11 @@ type (

// Unlock unlocks an issue discussion.
Unlock(context.Context, string, int) (*Response, error)

// AddLabel adds a label to an issue
AddLabel(ctx context.Context, repo string, number int, label string) (*Response, error)

// DeleteLabel deletes a label from an issue
DeleteLabel(ctx context.Context, repo string, number int, label string) (*Response, error)
}
)

0 comments on commit 8a85339

Please sign in to comment.