From 0397779713c8008beb2911e9f3c14b40e713ad85 Mon Sep 17 00:00:00 2001 From: Leon Pham Date: Wed, 4 May 2022 13:39:45 -0400 Subject: [PATCH 1/4] Add support for the rerequest check run endpoint --- github/checks.go | 17 +++++++++++++++++ github/checks_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/github/checks.go b/github/checks.go index 8e388e8675..ec1bc8b194 100644 --- a/github/checks.go +++ b/github/checks.go @@ -307,6 +307,23 @@ func (s *ChecksService) ListCheckRunsCheckSuite(ctx context.Context, owner, repo return checkRunResults, resp, nil } +// ReRequestCheckRun triggers GitHub to rerequest an existing check run. +// +// GitHub API docs: https://docs.github.com/en/rest/checks/runs#rerequest-a-check-run +func (s *ChecksService) ReRequestCheckRun(ctx context.Context, owner, repo string, checkRunID int64) (*Response, error) { + u := fmt.Sprintf("repos/%v/%v/check-runs/%v/rerequest", owner, repo, checkRunID) + + req, err := s.client.NewRequest("POST", u, nil) + if err != nil { + return nil, err + } + + req.Header.Set("Accept", mediaTypeCheckRunsPreview) + + resp, err := s.client.Do(ctx, req, nil) + return resp, err +} + // ListCheckSuiteOptions represents parameters to list check suites. type ListCheckSuiteOptions struct { CheckName *string `url:"check_name,omitempty"` // Filters checks suites by the name of the check run. diff --git a/github/checks_test.go b/github/checks_test.go index d3c01cdd20..33400648a7 100644 --- a/github/checks_test.go +++ b/github/checks_test.go @@ -1718,3 +1718,28 @@ func TestCheckSuitePreferenceResults_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } + +func TestChecksService_ReRequestCheckRun(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/o/r/check-runs/1/rerequest", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + testHeader(t, r, "Accept", mediaTypeCheckRunsPreview) + w.WriteHeader(http.StatusCreated) + }) + ctx := context.Background() + resp, err := client.Checks.ReRequestCheckRun(ctx, "o", "r", 1) + if err != nil { + t.Errorf("Checks.ReRequestCheckSuite return error: %v", err) + } + if got, want := resp.StatusCode, http.StatusCreated; got != want { + t.Errorf("Checks.ReRequestCheckRun = %v, want %v", got, want) + } + + const methodName = "ReRequestCheckRun" + testBadOptions(t, methodName, func() (err error) { + _, err = client.Checks.ReRequestCheckRun(ctx, "\n", "\n", 1) + return err + }) +} From e018f99fa5810d791084ad2e380ff314461c672f Mon Sep 17 00:00:00 2001 From: Leon Pham Date: Wed, 4 May 2022 13:46:40 -0400 Subject: [PATCH 2/4] Fix typo in tests --- github/checks_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/checks_test.go b/github/checks_test.go index 33400648a7..2fdd2476e5 100644 --- a/github/checks_test.go +++ b/github/checks_test.go @@ -1731,7 +1731,7 @@ func TestChecksService_ReRequestCheckRun(t *testing.T) { ctx := context.Background() resp, err := client.Checks.ReRequestCheckRun(ctx, "o", "r", 1) if err != nil { - t.Errorf("Checks.ReRequestCheckSuite return error: %v", err) + t.Errorf("Checks.ReRequestCheckRun return error: %v", err) } if got, want := resp.StatusCode, http.StatusCreated; got != want { t.Errorf("Checks.ReRequestCheckRun = %v, want %v", got, want) From 7162e075ea97cec10c5c4f07f856a258f2712114 Mon Sep 17 00:00:00 2001 From: Leon Pham <81973057+leonpham0@users.noreply.github.com> Date: Wed, 4 May 2022 14:56:27 -0700 Subject: [PATCH 3/4] Avoid creating unnecessary variables Co-authored-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com> --- github/checks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/checks.go b/github/checks.go index ec1bc8b194..b8880c0d54 100644 --- a/github/checks.go +++ b/github/checks.go @@ -321,7 +321,7 @@ func (s *ChecksService) ReRequestCheckRun(ctx context.Context, owner, repo strin req.Header.Set("Accept", mediaTypeCheckRunsPreview) resp, err := s.client.Do(ctx, req, nil) - return resp, err + return s.client.Do(ctx, req, nil) } // ListCheckSuiteOptions represents parameters to list check suites. From 6c6aab979d40a51affbba1d319bc96c5da292568 Mon Sep 17 00:00:00 2001 From: Leon Pham Date: Wed, 4 May 2022 17:58:50 -0400 Subject: [PATCH 4/4] Remove duplicate Do call --- github/checks.go | 1 - 1 file changed, 1 deletion(-) diff --git a/github/checks.go b/github/checks.go index b8880c0d54..b4819fc945 100644 --- a/github/checks.go +++ b/github/checks.go @@ -320,7 +320,6 @@ func (s *ChecksService) ReRequestCheckRun(ctx context.Context, owner, repo strin req.Header.Set("Accept", mediaTypeCheckRunsPreview) - resp, err := s.client.Do(ctx, req, nil) return s.client.Do(ctx, req, nil) }