Skip to content

Commit a3951f5

Browse files
authored
refactor!: Rename EditLabel to UpdateLabel, Split Label into CreateLabelRequest & UpdateLabelRequest and pass by value (#4400)
BREAKING CHANGE: `IssuesService.CreateLabel` now takes `CreateLabelRequest` by value (with required non-pointer `Name`); `IssuesService.EditLabel` renamed to `UpdateLabel`, taking an `UpdateLabelRequest` by value.
1 parent e5f31b2 commit a3951f5

8 files changed

Lines changed: 191 additions & 85 deletions

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ linters:
232232
- IssueComment
233233
- IssueImportRequest
234234
- Key
235-
- Label
236235
- LockIssueOptions
237236
- MaintenanceOptions
238237
- Milestone

github/github-accessors.go

Lines changed: 66 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-accessors_test.go

Lines changed: 69 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/github-stringify_test.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github/issues_labels.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,33 @@ import (
1212

1313
// Label represents a GitHub label on an Issue.
1414
type Label struct {
15-
ID *int64 `json:"id,omitempty"`
16-
URL *string `json:"url,omitempty"`
17-
Name *string `json:"name,omitempty"`
18-
Color *string `json:"color,omitempty"`
19-
Description *string `json:"description,omitempty"`
20-
Default *bool `json:"default,omitempty"`
21-
NodeID *string `json:"node_id,omitempty"`
15+
ID int64 `json:"id"`
16+
URL string `json:"url"`
17+
Name string `json:"name"`
18+
Color string `json:"color"`
19+
Description *string `json:"description"`
20+
Default bool `json:"default"`
21+
NodeID string `json:"node_id"`
2222
}
2323

2424
func (l Label) String() string {
2525
return Stringify(l)
2626
}
2727

28+
// CreateIssueLabelRequest represents a request to create a label.
29+
type CreateIssueLabelRequest struct {
30+
Name string `json:"name"`
31+
Color *string `json:"color,omitempty"`
32+
Description *string `json:"description,omitempty"`
33+
}
34+
35+
// UpdateIssueLabelRequest represents a request to update a label.
36+
type UpdateIssueLabelRequest struct {
37+
NewName *string `json:"new_name,omitempty"`
38+
Color *string `json:"color,omitempty"`
39+
Description *string `json:"description,omitempty"`
40+
}
41+
2842
// ListLabels lists all labels for a repository.
2943
//
3044
// GitHub API docs: https://docs.github.com/rest/issues/labels?apiVersion=2022-11-28#list-labels-for-a-repository
@@ -77,7 +91,7 @@ func (s *IssuesService) GetLabel(ctx context.Context, owner, repo, name string)
7791
// GitHub API docs: https://docs.github.com/rest/issues/labels?apiVersion=2022-11-28#create-a-label
7892
//
7993
//meta:operation POST /repos/{owner}/{repo}/labels
80-
func (s *IssuesService) CreateLabel(ctx context.Context, owner, repo string, body *Label) (*Label, *Response, error) {
94+
func (s *IssuesService) CreateLabel(ctx context.Context, owner, repo string, body CreateIssueLabelRequest) (*Label, *Response, error) {
8195
u := fmt.Sprintf("repos/%v/%v/labels", owner, repo)
8296
req, err := s.client.NewRequest(ctx, "POST", u, body)
8397
if err != nil {
@@ -93,12 +107,12 @@ func (s *IssuesService) CreateLabel(ctx context.Context, owner, repo string, bod
93107
return l, resp, nil
94108
}
95109

96-
// EditLabel edits a label.
110+
// UpdateLabel updates a label.
97111
//
98112
// GitHub API docs: https://docs.github.com/rest/issues/labels?apiVersion=2022-11-28#update-a-label
99113
//
100114
//meta:operation PATCH /repos/{owner}/{repo}/labels/{name}
101-
func (s *IssuesService) EditLabel(ctx context.Context, owner, repo, name string, body *Label) (*Label, *Response, error) {
115+
func (s *IssuesService) UpdateLabel(ctx context.Context, owner, repo, name string, body UpdateIssueLabelRequest) (*Label, *Response, error) {
102116
u := fmt.Sprintf("repos/%v/%v/labels/%v", owner, repo, name)
103117
req, err := s.client.NewRequest(ctx, "PATCH", u, body)
104118
if err != nil {

0 commit comments

Comments
 (0)