Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ linters:
- Key
- LockIssueOptions
- MaintenanceOptions
- Milestone
- Organization
- PagesUpdate
- PagesUpdateWithoutCNAME
Expand Down
64 changes: 64 additions & 0 deletions github/github-accessors.go

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

85 changes: 85 additions & 0 deletions github/github-accessors_test.go

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

22 changes: 19 additions & 3 deletions github/issues_milestones.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ func (m Milestone) String() string {
return Stringify(m)
}

// CreateMilestoneRequest represents a request to create a milestone.
type CreateMilestoneRequest struct {
Title string `json:"title"`
State *string `json:"state,omitempty"`
Description *string `json:"description,omitempty"`
DueOn *Timestamp `json:"due_on,omitempty"`
}

// UpdateMilestoneRequest represents a request to update a milestone.
type UpdateMilestoneRequest struct {
Title *string `json:"title,omitempty"`
State *string `json:"state,omitempty"`
Description *string `json:"description,omitempty"`
DueOn *Timestamp `json:"due_on,omitempty"`
}

// MilestoneListOptions specifies the optional parameters to the
// IssuesService.ListMilestones method.
type MilestoneListOptions struct {
Expand Down Expand Up @@ -104,7 +120,7 @@ func (s *IssuesService) GetMilestone(ctx context.Context, owner, repo string, nu
// GitHub API docs: https://docs.github.com/rest/issues/milestones?apiVersion=2022-11-28#create-a-milestone
//
//meta:operation POST /repos/{owner}/{repo}/milestones
func (s *IssuesService) CreateMilestone(ctx context.Context, owner, repo string, body *Milestone) (*Milestone, *Response, error) {
func (s *IssuesService) CreateMilestone(ctx context.Context, owner, repo string, body CreateMilestoneRequest) (*Milestone, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/milestones", owner, repo)
req, err := s.client.NewRequest(ctx, "POST", u, body)
if err != nil {
Expand All @@ -120,12 +136,12 @@ func (s *IssuesService) CreateMilestone(ctx context.Context, owner, repo string,
return m, resp, nil
}

// EditMilestone edits a milestone.
// UpdateMilestone updates a milestone.
//
// GitHub API docs: https://docs.github.com/rest/issues/milestones?apiVersion=2022-11-28#update-a-milestone
//
//meta:operation PATCH /repos/{owner}/{repo}/milestones/{milestone_number}
func (s *IssuesService) EditMilestone(ctx context.Context, owner, repo string, number int, body *Milestone) (*Milestone, *Response, error) {
func (s *IssuesService) UpdateMilestone(ctx context.Context, owner, repo string, number int, body UpdateMilestoneRequest) (*Milestone, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/milestones/%v", owner, repo, number)
req, err := s.client.NewRequest(ctx, "PATCH", u, body)
if err != nil {
Expand Down
24 changes: 12 additions & 12 deletions github/issues_milestones_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestIssuesService_CreateMilestone(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

input := &Milestone{Title: Ptr("t")}
input := CreateMilestoneRequest{Title: "t"}

mux.HandleFunc("/repos/o/r/milestones", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
Expand Down Expand Up @@ -151,15 +151,15 @@ func TestIssuesService_CreateMilestone_invalidOwner(t *testing.T) {
client, _, _ := setup(t)

ctx := t.Context()
_, _, err := client.Issues.CreateMilestone(ctx, "%", "r", nil)
_, _, err := client.Issues.CreateMilestone(ctx, "%", "r", CreateMilestoneRequest{})
testURLParseError(t, err)
}

func TestIssuesService_EditMilestone(t *testing.T) {
func TestIssuesService_UpdateMilestone(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

input := &Milestone{Title: Ptr("t")}
input := UpdateMilestoneRequest{Title: Ptr("t")}

mux.HandleFunc("/repos/o/r/milestones/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PATCH")
Expand All @@ -168,37 +168,37 @@ func TestIssuesService_EditMilestone(t *testing.T) {
})

ctx := t.Context()
milestone, _, err := client.Issues.EditMilestone(ctx, "o", "r", 1, input)
milestone, _, err := client.Issues.UpdateMilestone(ctx, "o", "r", 1, input)
if err != nil {
t.Errorf("IssuesService.EditMilestone returned error: %v", err)
t.Errorf("IssuesService.UpdateMilestone returned error: %v", err)
}

want := &Milestone{Number: Ptr(1)}
if !cmp.Equal(milestone, want) {
t.Errorf("IssuesService.EditMilestone returned %+v, want %+v", milestone, want)
t.Errorf("IssuesService.UpdateMilestone returned %+v, want %+v", milestone, want)
}

const methodName = "EditMilestone"
const methodName = "UpdateMilestone"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Issues.EditMilestone(ctx, "\n", "\n", -1, input)
_, _, err = client.Issues.UpdateMilestone(ctx, "\n", "\n", -1, input)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Issues.EditMilestone(ctx, "o", "r", 1, input)
got, resp, err := client.Issues.UpdateMilestone(ctx, "o", "r", 1, input)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}

func TestIssuesService_EditMilestone_invalidOwner(t *testing.T) {
func TestIssuesService_UpdateMilestone_invalidOwner(t *testing.T) {
t.Parallel()
client, _, _ := setup(t)

ctx := t.Context()
_, _, err := client.Issues.EditMilestone(ctx, "%", "r", 1, nil)
_, _, err := client.Issues.UpdateMilestone(ctx, "%", "r", 1, UpdateMilestoneRequest{})
testURLParseError(t, err)
}

Expand Down
Loading