Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ReRequestCheckRun #2358

Merged
merged 4 commits into from May 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions github/checks.go
Expand Up @@ -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
leonpham0 marked this conversation as resolved.
Show resolved Hide resolved
}

// 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
})
}