Skip to content

Commit

Permalink
Add ReRequestCheckRun (#2358)
Browse files Browse the repository at this point in the history
Fixes: #2357
  • Loading branch information
leonpham0 committed May 16, 2022
1 parent a58d5f0 commit ce36651
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
16 changes: 16 additions & 0 deletions github/checks.go
Expand Up @@ -307,6 +307,22 @@ 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)

return s.client.Do(ctx, req, nil)
}

// 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.
Expand Down
25 changes: 25 additions & 0 deletions github/checks_test.go
Expand Up @@ -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.ReRequestCheckRun 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
})
}

0 comments on commit ce36651

Please sign in to comment.