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
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,9 @@ linters:
# Body type names exempt from the "Options" suffix rule.
# TODO: fix and remove these exceptions.
body-allowed-wrong-names:
- CheckSuitePreferenceOptions
- ConfigApplyOptions
- CreateCheckRunOptions
- CreateCheckSuiteOptions
- MaintenanceOptions
- RepositoryContentFileOptions
- UpdateCheckRunOptions
sliceofpointers:
type: module
description: Reports usage of []*string and slices of structs without pointers.
Expand Down
42 changes: 21 additions & 21 deletions github/checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ func (s *ChecksService) GetCheckSuite(ctx context.Context, owner, repo string, c
return checkSuite, resp, nil
}

// CreateCheckRunOptions sets up parameters needed to create a CheckRun.
type CreateCheckRunOptions struct {
// CreateCheckRunRequest sets up parameters needed to create a CheckRun.
type CreateCheckRunRequest struct {
Name string `json:"name"` // The name of the check (e.g., "code-coverage"). (Required.)
HeadSHA string `json:"head_sha"` // The SHA of the commit. (Required.)
DetailsURL *string `json:"details_url,omitempty"` // The URL of the integrator's site that has the full details of the check. (Optional.)
Expand All @@ -156,7 +156,7 @@ type CreateCheckRunOptions struct {
StartedAt *Timestamp `json:"started_at,omitempty"` // The time that the check run began. (Optional.)
CompletedAt *Timestamp `json:"completed_at,omitempty"` // The time the check completed. (Optional. Required if you provide conclusion.)
Output *CheckRunOutput `json:"output,omitempty"` // Provide descriptive details about the run. (Optional)
Actions []*CheckRunAction `json:"actions,omitempty"` // Possible further actions the integrator can perform, which a user may trigger. (Optional.)
Actions []*CheckRunAction `json:"actions,omitzero"` // Possible further actions the integrator can perform, which a user may trigger. (Optional.)
}

// CheckRunAction exposes further actions the integrator can perform, which a user may trigger.
Expand All @@ -171,7 +171,7 @@ type CheckRunAction struct {
// GitHub API docs: https://docs.github.com/rest/checks/runs?apiVersion=2022-11-28#create-a-check-run
//
//meta:operation POST /repos/{owner}/{repo}/check-runs
func (s *ChecksService) CreateCheckRun(ctx context.Context, owner, repo string, body CreateCheckRunOptions) (*CheckRun, *Response, error) {
func (s *ChecksService) CreateCheckRun(ctx context.Context, owner, repo string, body CreateCheckRunRequest) (*CheckRun, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/check-runs", owner, repo)
req, err := s.client.NewRequest(ctx, "POST", u, body)
if err != nil {
Expand All @@ -189,24 +189,25 @@ func (s *ChecksService) CreateCheckRun(ctx context.Context, owner, repo string,
return checkRun, resp, nil
}

// UpdateCheckRunOptions sets up parameters needed to update a CheckRun.
type UpdateCheckRunOptions struct {
Name string `json:"name"` // The name of the check (e.g., "code-coverage"). (Required.)
// UpdateCheckRunRequest sets up parameters needed to update a CheckRun.
type UpdateCheckRunRequest struct {
Name *string `json:"name,omitempty"` // The name of the check (e.g., "code-coverage"). (Optional.)
DetailsURL *string `json:"details_url,omitempty"` // The URL of the integrator's site that has the full details of the check. (Optional.)
ExternalID *string `json:"external_id,omitempty"` // A reference for the run on the integrator's system. (Optional.)
StartedAt *Timestamp `json:"started_at,omitempty"` // The time that the check run began. (Optional.)
Status *string `json:"status,omitempty"` // The current status. Can be one of "queued", "in_progress", or "completed". Default: "queued". (Optional.)
Conclusion *string `json:"conclusion,omitempty"` // Can be one of "success", "failure", "neutral", "cancelled", "skipped", "timed_out", or "action_required". (Optional. Required if you provide a status of "completed".)
CompletedAt *Timestamp `json:"completed_at,omitempty"` // The time the check completed. (Optional. Required if you provide conclusion.)
Output *CheckRunOutput `json:"output,omitempty"` // Provide descriptive details about the run. (Optional)
Actions []*CheckRunAction `json:"actions,omitempty"` // Possible further actions the integrator can perform, which a user may trigger. (Optional.)
Actions []*CheckRunAction `json:"actions,omitzero"` // Possible further actions the integrator can perform, which a user may trigger. (Optional.)
}

// UpdateCheckRun updates a check run for a specific commit in a repository.
//
// GitHub API docs: https://docs.github.com/rest/checks/runs?apiVersion=2022-11-28#update-a-check-run
//
//meta:operation PATCH /repos/{owner}/{repo}/check-runs/{check_run_id}
func (s *ChecksService) UpdateCheckRun(ctx context.Context, owner, repo string, checkRunID int64, body UpdateCheckRunOptions) (*CheckRun, *Response, error) {
func (s *ChecksService) UpdateCheckRun(ctx context.Context, owner, repo string, checkRunID int64, body UpdateCheckRunRequest) (*CheckRun, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/check-runs/%v", owner, repo, checkRunID)
req, err := s.client.NewRequest(ctx, "PATCH", u, body)
if err != nil {
Expand Down Expand Up @@ -390,13 +391,13 @@ func (s *ChecksService) ListCheckSuitesForRef(ctx context.Context, owner, repo,

// AutoTriggerCheck enables or disables automatic creation of CheckSuite events upon pushes to the repository.
type AutoTriggerCheck struct {
AppID *int64 `json:"app_id,omitempty"` // The id of the GitHub App. (Required.)
Setting *bool `json:"setting,omitempty"` // Set to "true" to enable automatic creation of CheckSuite events upon pushes to the repository, or "false" to disable them. Default: "true" (Required.)
AppID int64 `json:"app_id"` // The id of the GitHub App. (Required.)
Setting bool `json:"setting"` // Set to "true" to enable automatic creation of CheckSuite events upon pushes to the repository, or "false" to disable them. Default: "true" (Required.)
}

// CheckSuitePreferenceOptions set options for check suite preferences for a repository.
type CheckSuitePreferenceOptions struct {
AutoTriggerChecks []*AutoTriggerCheck `json:"auto_trigger_checks,omitempty"` // A slice of auto trigger checks that can be set for a check suite in a repository.
// UpdateCheckSuitePreferencesRequest sets options for check suite preferences for a repository.
type UpdateCheckSuitePreferencesRequest struct {
AutoTriggerChecks []*AutoTriggerCheck `json:"auto_trigger_checks,omitzero"` // A slice of auto trigger checks that can be set for a check suite in a repository.
}

// CheckSuitePreferenceResults represents the results of the preference set operation.
Expand All @@ -410,12 +411,12 @@ type PreferenceList struct {
AutoTriggerChecks []*AutoTriggerCheck `json:"auto_trigger_checks,omitempty"` // A slice of auto trigger checks that can be set for a check suite in a repository.
}

// SetCheckSuitePreferences changes the default automatic flow when creating check suites.
// UpdateCheckSuitePreferences changes the default automatic flow when creating check suites.
//
// GitHub API docs: https://docs.github.com/rest/checks/suites?apiVersion=2022-11-28#update-repository-preferences-for-check-suites
//
//meta:operation PATCH /repos/{owner}/{repo}/check-suites/preferences
func (s *ChecksService) SetCheckSuitePreferences(ctx context.Context, owner, repo string, body CheckSuitePreferenceOptions) (*CheckSuitePreferenceResults, *Response, error) {
func (s *ChecksService) UpdateCheckSuitePreferences(ctx context.Context, owner, repo string, body UpdateCheckSuitePreferencesRequest) (*CheckSuitePreferenceResults, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/check-suites/preferences", owner, repo)
req, err := s.client.NewRequest(ctx, "PATCH", u, body)
if err != nil {
Expand All @@ -433,18 +434,17 @@ func (s *ChecksService) SetCheckSuitePreferences(ctx context.Context, owner, rep
return checkSuitePrefResults, resp, nil
}

// CreateCheckSuiteOptions sets up parameters to manually create a check suite.
type CreateCheckSuiteOptions struct {
HeadSHA string `json:"head_sha"` // The sha of the head commit. (Required.)
HeadBranch *string `json:"head_branch,omitempty"` // The name of the head branch where the code changes are implemented.
// CreateCheckSuiteRequest sets up parameters to manually create a check suite.
type CreateCheckSuiteRequest struct {
HeadSHA string `json:"head_sha"` // The sha of the head commit. (Required.)
}

// CreateCheckSuite manually creates a check suite for a repository.
//
// GitHub API docs: https://docs.github.com/rest/checks/suites?apiVersion=2022-11-28#create-a-check-suite
//
//meta:operation POST /repos/{owner}/{repo}/check-suites
func (s *ChecksService) CreateCheckSuite(ctx context.Context, owner, repo string, body CreateCheckSuiteOptions) (*CheckSuite, *Response, error) {
func (s *ChecksService) CreateCheckSuite(ctx context.Context, owner, repo string, body CreateCheckSuiteRequest) (*CheckSuite, *Response, error) {
u := fmt.Sprintf("repos/%v/%v/check-suites", owner, repo)
req, err := s.client.NewRequest(ctx, "POST", u, body)
if err != nil {
Expand Down
52 changes: 26 additions & 26 deletions github/checks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestChecksService_CreateCheckRun(t *testing.T) {
"output":{"title": "Mighty test report", "summary":"", "text":""}}`)
})
startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z")
checkRunOpt := CreateCheckRunOptions{
body := CreateCheckRunRequest{
Name: "testCreateCheckRun",
HeadSHA: "deadbeef",
Status: new("in_progress"),
Expand All @@ -144,7 +144,7 @@ func TestChecksService_CreateCheckRun(t *testing.T) {
}

ctx := t.Context()
checkRun, _, err := client.Checks.CreateCheckRun(ctx, "o", "r", checkRunOpt)
checkRun, _, err := client.Checks.CreateCheckRun(ctx, "o", "r", body)
if err != nil {
t.Errorf("Checks.CreateCheckRun return error: %v", err)
}
Expand All @@ -167,12 +167,12 @@ func TestChecksService_CreateCheckRun(t *testing.T) {

const methodName = "CreateCheckRun"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Checks.CreateCheckRun(ctx, "\n", "\n", CreateCheckRunOptions{})
_, _, err = client.Checks.CreateCheckRun(ctx, "\n", "\n", CreateCheckRunRequest{})
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Checks.CreateCheckRun(ctx, "o", "r", checkRunOpt)
got, resp, err := client.Checks.CreateCheckRun(ctx, "o", "r", body)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand Down Expand Up @@ -257,8 +257,9 @@ func TestChecksService_UpdateCheckRun(t *testing.T) {
"output":{"title": "Mighty test report", "summary":"There are 0 failures, 2 warnings and 1 notice", "text":"You may have misspelled some words."}}`)
})
startedAt, _ := time.Parse(time.RFC3339, "2018-05-04T01:14:52Z")
updateCheckRunOpt := UpdateCheckRunOptions{
Name: "testUpdateCheckRun",
body := UpdateCheckRunRequest{
Name: new("testUpdateCheckRun"),
StartedAt: &Timestamp{startedAt},
Status: new("completed"),
CompletedAt: &Timestamp{startedAt},
Output: &CheckRunOutput{
Expand All @@ -269,7 +270,7 @@ func TestChecksService_UpdateCheckRun(t *testing.T) {
}

ctx := t.Context()
checkRun, _, err := client.Checks.UpdateCheckRun(ctx, "o", "r", 1, updateCheckRunOpt)
checkRun, _, err := client.Checks.UpdateCheckRun(ctx, "o", "r", 1, body)
if err != nil {
t.Errorf("Checks.UpdateCheckRun return error: %v", err)
}
Expand All @@ -293,12 +294,12 @@ func TestChecksService_UpdateCheckRun(t *testing.T) {

const methodName = "UpdateCheckRun"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Checks.UpdateCheckRun(ctx, "\n", "\n", -1, UpdateCheckRunOptions{})
_, _, err = client.Checks.UpdateCheckRun(ctx, "\n", "\n", -1, UpdateCheckRunRequest{})
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Checks.UpdateCheckRun(ctx, "o", "r", 1, updateCheckRunOpt)
got, resp, err := client.Checks.UpdateCheckRun(ctx, "o", "r", 1, body)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand Down Expand Up @@ -511,27 +512,27 @@ func TestChecksService_ListCheckSuiteForRef(t *testing.T) {
})
}

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

a := []*AutoTriggerCheck{{
AppID: new(int64(2)),
Setting: new(false),
AppID: 2,
Setting: false,
}}
opt := CheckSuitePreferenceOptions{AutoTriggerChecks: a}
body := UpdateCheckSuitePreferencesRequest{AutoTriggerChecks: a}

mux.HandleFunc("/repos/o/r/check-suites/preferences", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PATCH")
testHeader(t, r, "Accept", mediaTypeCheckRunsPreview)
testJSONBody(t, r, opt)
testJSONBody(t, r, body)
fmt.Fprint(w, `{"preferences":{"auto_trigger_checks":[{"app_id": 2,"setting": false}]}}`)
})

ctx := t.Context()
prefResults, _, err := client.Checks.SetCheckSuitePreferences(ctx, "o", "r", opt)
prefResults, _, err := client.Checks.UpdateCheckSuitePreferences(ctx, "o", "r", body)
if err != nil {
t.Errorf("Checks.SetCheckSuitePreferences return error: %v", err)
t.Errorf("Checks.UpdateCheckSuitePreferences return error: %v", err)
}

p := &PreferenceList{
Expand All @@ -542,17 +543,17 @@ func TestChecksService_SetCheckSuitePreferences(t *testing.T) {
}

if !cmp.Equal(prefResults, want) {
t.Errorf("Checks.SetCheckSuitePreferences return %+v, want %+v", prefResults, want)
t.Errorf("Checks.UpdateCheckSuitePreferences return %+v, want %+v", prefResults, want)
}

const methodName = "SetCheckSuitePreferences"
const methodName = "UpdateCheckSuitePreferences"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Checks.SetCheckSuitePreferences(ctx, "\n", "\n", CheckSuitePreferenceOptions{})
_, _, err = client.Checks.UpdateCheckSuitePreferences(ctx, "\n", "\n", UpdateCheckSuitePreferencesRequest{})
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Checks.SetCheckSuitePreferences(ctx, "o", "r", opt)
got, resp, err := client.Checks.UpdateCheckSuitePreferences(ctx, "o", "r", body)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand All @@ -577,13 +578,12 @@ func TestChecksService_CreateCheckSuite(t *testing.T) {
"after": "deadbeefa"}`)
})

checkSuiteOpt := CreateCheckSuiteOptions{
HeadSHA: "deadbeef",
HeadBranch: new("master"),
body := CreateCheckSuiteRequest{
HeadSHA: "deadbeef",
}

ctx := t.Context()
checkSuite, _, err := client.Checks.CreateCheckSuite(ctx, "o", "r", checkSuiteOpt)
checkSuite, _, err := client.Checks.CreateCheckSuite(ctx, "o", "r", body)
if err != nil {
t.Errorf("Checks.CreateCheckSuite return error: %v", err)
}
Expand All @@ -603,12 +603,12 @@ func TestChecksService_CreateCheckSuite(t *testing.T) {

const methodName = "CreateCheckSuite"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Checks.CreateCheckSuite(ctx, "\n", "\n", CreateCheckSuiteOptions{})
_, _, err = client.Checks.CreateCheckSuite(ctx, "\n", "\n", CreateCheckSuiteRequest{})
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Checks.CreateCheckSuite(ctx, "o", "r", checkSuiteOpt)
got, resp, err := client.Checks.CreateCheckSuite(ctx, "o", "r", body)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
Expand Down
Loading
Loading