From f7638673e6ef93cf2d39c43964449f4b5c6f9bf1 Mon Sep 17 00:00:00 2001 From: AGMETEOR Date: Tue, 2 Nov 2021 21:06:34 +0300 Subject: [PATCH 1/6] Add new method, RemoveMilesone on IssuesService --- github/issues.go | 19 +++++++++++++++++++ github/issues_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/github/issues.go b/github/issues.go index 46aff2954b..e5ae8c571c 100644 --- a/github/issues.go +++ b/github/issues.go @@ -299,6 +299,25 @@ func (s *IssuesService) Edit(ctx context.Context, owner string, repo string, num return i, resp, nil } +// Remove a milestone from an issue +func (s *IssuesService) RemoveMilestone(ctx context.Context, owner string, repo string, issueNumber int) (*Issue, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, issueNumber) + req, err := s.client.NewRequest("PATCH", u, &struct { + Milestone interface{} `json:"milestone"` + }{}) + if err != nil { + return nil, nil, err + } + + i := new(Issue) + resp, err := s.client.Do(ctx, req, i) + if err != nil { + return nil, resp, err + } + + return i, resp, nil +} + // LockIssueOptions specifies the optional parameters to the // IssuesService.Lock method. type LockIssueOptions struct { diff --git a/github/issues_test.go b/github/issues_test.go index 80bfb3ff6d..109acd389e 100644 --- a/github/issues_test.go +++ b/github/issues_test.go @@ -345,6 +345,41 @@ func TestIssuesService_Edit(t *testing.T) { }) } +func TestIssuesService_RemoveMilestone(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + mux.HandleFunc("/repos/o/r/issues/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PATCH") + fmt.Fprint(w, `{"number":1}`) + }) + + ctx := context.Background() + issue, _, err := client.Issues.RemoveMilestone(ctx, "o", "r", 1) + if err != nil { + t.Errorf("Issues.RemoveMilestone returned error: %v", err) + } + + want := &Issue{Number: Int(1)} + if !cmp.Equal(issue, want) { + t.Errorf("Issues.RemoveMilestone returned %+v, want %+v", issue, want) + } + + const methodName = "RemoveMilestone" + testBadOptions(t, methodName, func() (err error) { + _, _, err = client.Issues.RemoveMilestone(ctx, "\n", "\n", -1) + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Issues.RemoveMilestone(ctx, "o", "r", 1) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) + +} + func TestIssuesService_Edit_invalidOwner(t *testing.T) { client, _, _, teardown := setup() defer teardown() From dea58a79a5433a9b94507267f0cdbcb154867502 Mon Sep 17 00:00:00 2001 From: AGMETEOR Date: Tue, 2 Nov 2021 21:14:04 +0300 Subject: [PATCH 2/6] fix lint issue --- github/issues_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/github/issues_test.go b/github/issues_test.go index 109acd389e..3ed7390f5f 100644 --- a/github/issues_test.go +++ b/github/issues_test.go @@ -377,7 +377,6 @@ func TestIssuesService_RemoveMilestone(t *testing.T) { } return resp, err }) - } func TestIssuesService_Edit_invalidOwner(t *testing.T) { From 996572dbf00f1cbd519292e6ae561753feaec3f3 Mon Sep 17 00:00:00 2001 From: Allan Guwatudde Date: Wed, 3 Nov 2021 22:14:34 +0300 Subject: [PATCH 3/6] Update github/issues.go Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/issues.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/issues.go b/github/issues.go index e5ae8c571c..45b2e6c40b 100644 --- a/github/issues.go +++ b/github/issues.go @@ -301,7 +301,7 @@ func (s *IssuesService) Edit(ctx context.Context, owner string, repo string, num // Remove a milestone from an issue func (s *IssuesService) RemoveMilestone(ctx context.Context, owner string, repo string, issueNumber int) (*Issue, *Response, error) { - u := fmt.Sprintf("repos/%v/%v/issues/%d", owner, repo, issueNumber) + u := fmt.Sprintf("repos/%v/%v/issues/%v", owner, repo, issueNumber) req, err := s.client.NewRequest("PATCH", u, &struct { Milestone interface{} `json:"milestone"` }{}) From 9d83458245f623745196fc905d253201c3f65bd8 Mon Sep 17 00:00:00 2001 From: Allan Guwatudde Date: Wed, 3 Nov 2021 22:15:17 +0300 Subject: [PATCH 4/6] Update github/issues.go Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/issues.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/github/issues.go b/github/issues.go index 45b2e6c40b..f6a85d9e11 100644 --- a/github/issues.go +++ b/github/issues.go @@ -299,7 +299,11 @@ func (s *IssuesService) Edit(ctx context.Context, owner string, repo string, num return i, resp, nil } -// Remove a milestone from an issue +// Remove a milestone from an issue. +// +// This is a helper method to explicitly update an issue with a `null` milestone, thereby removing it. +// +// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#update-an-issue func (s *IssuesService) RemoveMilestone(ctx context.Context, owner string, repo string, issueNumber int) (*Issue, *Response, error) { u := fmt.Sprintf("repos/%v/%v/issues/%v", owner, repo, issueNumber) req, err := s.client.NewRequest("PATCH", u, &struct { From 33696c940d8e52f149cc417b11382acc7e58df53 Mon Sep 17 00:00:00 2001 From: AGMETEOR Date: Wed, 3 Nov 2021 22:18:34 +0300 Subject: [PATCH 5/6] use explicit type --- github/issues.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/issues.go b/github/issues.go index f6a85d9e11..4d8b2a0663 100644 --- a/github/issues.go +++ b/github/issues.go @@ -307,7 +307,7 @@ func (s *IssuesService) Edit(ctx context.Context, owner string, repo string, num func (s *IssuesService) RemoveMilestone(ctx context.Context, owner string, repo string, issueNumber int) (*Issue, *Response, error) { u := fmt.Sprintf("repos/%v/%v/issues/%v", owner, repo, issueNumber) req, err := s.client.NewRequest("PATCH", u, &struct { - Milestone interface{} `json:"milestone"` + Milestone *Milestone `json:"milestone"` }{}) if err != nil { return nil, nil, err From 7ce86cd542da28c4746955c4594522b6799ebf93 Mon Sep 17 00:00:00 2001 From: Allan Guwatudde Date: Wed, 3 Nov 2021 22:33:26 +0300 Subject: [PATCH 6/6] Update github/issues.go Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/issues.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/issues.go b/github/issues.go index 4d8b2a0663..f35f2b566a 100644 --- a/github/issues.go +++ b/github/issues.go @@ -304,7 +304,7 @@ func (s *IssuesService) Edit(ctx context.Context, owner string, repo string, num // This is a helper method to explicitly update an issue with a `null` milestone, thereby removing it. // // GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/issues/#update-an-issue -func (s *IssuesService) RemoveMilestone(ctx context.Context, owner string, repo string, issueNumber int) (*Issue, *Response, error) { +func (s *IssuesService) RemoveMilestone(ctx context.Context, owner, repo string, issueNumber int) (*Issue, *Response, error) { u := fmt.Sprintf("repos/%v/%v/issues/%v", owner, repo, issueNumber) req, err := s.client.NewRequest("PATCH", u, &struct { Milestone *Milestone `json:"milestone"`