diff --git a/github/apps.go b/github/apps.go index 8bd32d45761..e1bede64717 100644 --- a/github/apps.go +++ b/github/apps.go @@ -434,7 +434,6 @@ func (s *AppsService) CreateAttachment(ctx context.Context, contentReferenceID i return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeContentAttachmentsPreview) m := &Attachment{} diff --git a/github/codesofconduct.go b/github/codesofconduct.go index 159340e0a74..a514aac6b93 100644 --- a/github/codesofconduct.go +++ b/github/codesofconduct.go @@ -36,7 +36,6 @@ func (s *CodesOfConductService) List(ctx context.Context) ([]*CodeOfConduct, *Re return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeCodesOfConductPreview) var cs []*CodeOfConduct @@ -67,7 +66,6 @@ func (s *CodesOfConductService) Get(ctx context.Context, key string) (*CodeOfCon return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeCodesOfConductPreview) coc := new(CodeOfConduct) diff --git a/github/github.go b/github/github.go index f0bef46d799..e2086ee76ae 100644 --- a/github/github.go +++ b/github/github.go @@ -56,7 +56,7 @@ const ( mediaTypeIssueImportAPI = "application/vnd.github.golden-comet-preview+json" mediaTypeStarring = "application/vnd.github.star+json" - // Media Type values to access preview APIs + // Media Type values to access preview APIs. // These media types will be added to the API request as headers // and used to enable particular features on GitHub API that are still in preview. // After some time, specific media types will be promoted (to a "stable" state). @@ -71,7 +71,7 @@ const ( // versions. Additionally, non-functional (preview) headers don't create any side effects // on GitHub Cloud version. // - // See https://github.com/google/go-github/pull/2125 for full context. + // See https://github.com/google/go-github/pull/2125 and https://github.com/google/go-github/pull/2188 for full context. // https://help.github.com/enterprise/2.4/admin/guides/migrations/exporting-the-github-com-organization-s-repositories/ mediaTypeMigrationsPreview = "application/vnd.github.wyandotte-preview+json" @@ -91,6 +91,9 @@ const ( // https://developer.github.com/changes/2016-09-14-projects-api/ mediaTypeProjectsPreview = "application/vnd.github.inertia-preview+json" + // https://developer.github.com/changes/2017-01-05-commit-search-api/ + mediaTypeCommitSearchPreview = "application/vnd.github.cloak-preview+json" + // https://developer.github.com/changes/2017-02-28-user-blocking-apis-and-webhook/ mediaTypeBlockUsersPreview = "application/vnd.github.giant-sentry-fist-preview+json" diff --git a/github/interactions_orgs.go b/github/interactions_orgs.go index 47998c4eefb..55f2548179a 100644 --- a/github/interactions_orgs.go +++ b/github/interactions_orgs.go @@ -22,7 +22,6 @@ func (s *InteractionsService) GetRestrictionsForOrg(ctx context.Context, organiz return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeInteractionRestrictionsPreview) organizationInteractions := new(InteractionRestriction) @@ -54,7 +53,6 @@ func (s *InteractionsService) UpdateRestrictionsForOrg(ctx context.Context, orga return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeInteractionRestrictionsPreview) organizationInteractions := new(InteractionRestriction) @@ -79,7 +77,6 @@ func (s *InteractionsService) RemoveRestrictionsFromOrg(ctx context.Context, org return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeInteractionRestrictionsPreview) return s.client.Do(ctx, req, nil) diff --git a/github/interactions_repos.go b/github/interactions_repos.go index 58fd4f04f30..d99de494a9a 100644 --- a/github/interactions_repos.go +++ b/github/interactions_repos.go @@ -22,7 +22,6 @@ func (s *InteractionsService) GetRestrictionsForRepo(ctx context.Context, owner, return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeInteractionRestrictionsPreview) repositoryInteractions := new(InteractionRestriction) @@ -54,7 +53,6 @@ func (s *InteractionsService) UpdateRestrictionsForRepo(ctx context.Context, own return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeInteractionRestrictionsPreview) repositoryInteractions := new(InteractionRestriction) @@ -79,7 +77,6 @@ func (s *InteractionsService) RemoveRestrictionsFromRepo(ctx context.Context, ow return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeInteractionRestrictionsPreview) return s.client.Do(ctx, req, nil) diff --git a/github/issue_import.go b/github/issue_import.go index 843a8198941..ea42db1ba98 100644 --- a/github/issue_import.go +++ b/github/issue_import.go @@ -81,7 +81,6 @@ func (s *IssueImportService) Create(ctx context.Context, owner, repo string, iss return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeIssueImportAPI) i := new(IssueImportResponse) @@ -112,7 +111,6 @@ func (s *IssueImportService) CheckStatus(ctx context.Context, owner, repo string return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeIssueImportAPI) i := new(IssueImportResponse) @@ -136,7 +134,6 @@ func (s *IssueImportService) CheckStatusSince(ctx context.Context, owner, repo s return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeIssueImportAPI) var b bytes.Buffer diff --git a/github/issues.go b/github/issues.go index 6de04708dc8..72d0dbae6bd 100644 --- a/github/issues.go +++ b/github/issues.go @@ -195,7 +195,6 @@ func (s *IssuesService) listIssues(ctx context.Context, u string, opts *IssueLis return nil, nil, err } - // TODO: remove custom Accept header when this API fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) var issues []*Issue @@ -268,7 +267,6 @@ func (s *IssuesService) ListByRepo(ctx context.Context, owner, repo string, opts return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeReactionsPreview) var issues []*Issue @@ -292,7 +290,6 @@ func (s *IssuesService) Get(ctx context.Context, owner, repo string, number int) return nil, nil, err } - // TODO: remove custom Accept header when this API fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) issue := new(Issue) diff --git a/github/issues_comments.go b/github/issues_comments.go index 8918e0894bb..35069400de8 100644 --- a/github/issues_comments.go +++ b/github/issues_comments.go @@ -76,7 +76,6 @@ func (s *IssuesService) ListComments(ctx context.Context, owner, repo string, nu return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeReactionsPreview) var comments []*IssueComment @@ -101,7 +100,6 @@ func (s *IssuesService) GetComment(ctx context.Context, owner, repo string, comm return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeReactionsPreview) comment := new(IssueComment) diff --git a/github/issues_timeline.go b/github/issues_timeline.go index 903f5b89c34..cea900ee6bd 100644 --- a/github/issues_timeline.go +++ b/github/issues_timeline.go @@ -188,7 +188,6 @@ func (s *IssuesService) ListIssueTimeline(ctx context.Context, owner, repo strin return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. acceptHeaders := []string{mediaTypeTimelinePreview, mediaTypeProjectCardDetailsPreview} req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) diff --git a/github/migrations.go b/github/migrations.go index b33be5edd29..14d014b6149 100644 --- a/github/migrations.go +++ b/github/migrations.go @@ -109,7 +109,6 @@ func (s *MigrationService) StartMigration(ctx context.Context, org string, repos return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeMigrationsPreview) m := &Migration{} @@ -138,7 +137,6 @@ func (s *MigrationService) ListMigrations(ctx context.Context, org string, opts return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeMigrationsPreview) var m []*Migration @@ -164,7 +162,6 @@ func (s *MigrationService) MigrationStatus(ctx context.Context, org string, id i return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeMigrationsPreview) m := &Migration{} @@ -190,7 +187,6 @@ func (s *MigrationService) MigrationArchiveURL(ctx context.Context, org string, return "", err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeMigrationsPreview) s.client.clientMu.Lock() @@ -229,7 +225,6 @@ func (s *MigrationService) DeleteMigration(ctx context.Context, org string, id i return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeMigrationsPreview) return s.client.Do(ctx, req, nil) @@ -251,7 +246,6 @@ func (s *MigrationService) UnlockRepo(ctx context.Context, org string, id int64, return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeMigrationsPreview) return s.client.Do(ctx, req, nil) diff --git a/github/migrations_user.go b/github/migrations_user.go index 58e780ea7bb..49678fcc09f 100644 --- a/github/migrations_user.go +++ b/github/migrations_user.go @@ -84,7 +84,6 @@ func (s *MigrationService) StartUserMigration(ctx context.Context, repos []strin return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeMigrationsPreview) m := &UserMigration{} @@ -113,7 +112,6 @@ func (s *MigrationService) ListUserMigrations(ctx context.Context, opts *ListOpt return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeMigrationsPreview) var m []*UserMigration @@ -139,7 +137,6 @@ func (s *MigrationService) UserMigrationStatus(ctx context.Context, id int64) (* return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeMigrationsPreview) m := &UserMigration{} @@ -165,7 +162,6 @@ func (s *MigrationService) UserMigrationArchiveURL(ctx context.Context, id int64 return "", err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeMigrationsPreview) m := &UserMigration{} @@ -201,7 +197,6 @@ func (s *MigrationService) DeleteUserMigration(ctx context.Context, id int64) (* return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeMigrationsPreview) return s.client.Do(ctx, req, nil) @@ -223,7 +218,6 @@ func (s *MigrationService) UnlockUserRepo(ctx context.Context, id int64, repo st return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeMigrationsPreview) return s.client.Do(ctx, req, nil) diff --git a/github/orgs.go b/github/orgs.go index c7e4c412606..c1f7bf0d028 100644 --- a/github/orgs.go +++ b/github/orgs.go @@ -236,7 +236,6 @@ func (s *OrganizationsService) Get(ctx context.Context, org string) (*Organizati return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeMemberAllowedRepoCreationTypePreview) organization := new(Organization) @@ -281,7 +280,6 @@ func (s *OrganizationsService) Edit(ctx context.Context, name string, org *Organ return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeMemberAllowedRepoCreationTypePreview) o := new(Organization) diff --git a/github/orgs_users_blocking.go b/github/orgs_users_blocking.go index f69933ba430..60ee0f18ba6 100644 --- a/github/orgs_users_blocking.go +++ b/github/orgs_users_blocking.go @@ -27,7 +27,6 @@ func (s *OrganizationsService) ListBlockedUsers(ctx context.Context, org string, return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeBlockUsersPreview) var blockedUsers []*User @@ -52,7 +51,6 @@ func (s *OrganizationsService) IsBlocked(ctx context.Context, org, user string) return false, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeBlockUsersPreview) resp, err := s.client.Do(ctx, req, nil) @@ -73,7 +71,6 @@ func (s *OrganizationsService) BlockUser(ctx context.Context, org, user string) return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeBlockUsersPreview) return s.client.Do(ctx, req, nil) @@ -92,7 +89,6 @@ func (s *OrganizationsService) UnblockUser(ctx context.Context, org, user string return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeBlockUsersPreview) return s.client.Do(ctx, req, nil) diff --git a/github/pulls.go b/github/pulls.go index 917e4422124..aefd08a6dde 100644 --- a/github/pulls.go +++ b/github/pulls.go @@ -197,7 +197,6 @@ func (s *PullRequestsService) ListPullRequestsWithCommit(ctx context.Context, ow return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeListPullsOrBranchesForCommitPreview) var pulls []*PullRequest resp, err := s.client.Do(ctx, req, &pulls) @@ -332,7 +331,6 @@ func (s *PullRequestsService) UpdateBranch(ctx context.Context, owner, repo stri return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeUpdatePullRequestBranchPreview) p := new(PullRequestBranchUpdateResponse) diff --git a/github/pulls_comments.go b/github/pulls_comments.go index 0c495c5965b..03b3c1d2057 100644 --- a/github/pulls_comments.go +++ b/github/pulls_comments.go @@ -94,7 +94,6 @@ func (s *PullRequestsService) ListComments(ctx context.Context, owner, repo stri return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeMultiLineCommentsPreview} req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) @@ -119,7 +118,6 @@ func (s *PullRequestsService) GetComment(ctx context.Context, owner, repo string return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeMultiLineCommentsPreview} req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) @@ -143,7 +141,6 @@ func (s *PullRequestsService) CreateComment(ctx context.Context, owner, repo str if err != nil { return nil, nil, err } - // TODO: remove custom Accept headers when their respective API fully launches. acceptHeaders := []string{mediaTypeReactionsPreview, mediaTypeMultiLineCommentsPreview} req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) diff --git a/github/pulls_comments_test.go b/github/pulls_comments_test.go index f6e420663c8..e6e2d048930 100644 --- a/github/pulls_comments_test.go +++ b/github/pulls_comments_test.go @@ -271,7 +271,6 @@ func TestPullRequestsService_CreateComment(t *testing.T) { v := new(PullRequestComment) assertNilError(t, json.NewDecoder(r.Body).Decode(v)) - // TODO: remove custom Accept header assertion when the API fully launches. testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", ")) testMethod(t, r, "POST") if !cmp.Equal(v, input) { diff --git a/github/reactions.go b/github/reactions.go index 6f84c673c43..d659fa39c29 100644 --- a/github/reactions.go +++ b/github/reactions.go @@ -74,7 +74,6 @@ func (s *ReactionsService) ListCommentReactions(ctx context.Context, owner, repo return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) var m []*Reaction @@ -103,7 +102,6 @@ func (s *ReactionsService) CreateCommentReaction(ctx context.Context, owner, rep return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) m := &Reaction{} @@ -154,7 +152,6 @@ func (s *ReactionsService) ListIssueReactions(ctx context.Context, owner, repo s return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) var m []*Reaction @@ -183,7 +180,6 @@ func (s *ReactionsService) CreateIssueReaction(ctx context.Context, owner, repo return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) m := &Reaction{} @@ -234,7 +230,6 @@ func (s *ReactionsService) ListIssueCommentReactions(ctx context.Context, owner, return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) var m []*Reaction @@ -263,7 +258,6 @@ func (s *ReactionsService) CreateIssueCommentReaction(ctx context.Context, owner return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) m := &Reaction{} @@ -314,7 +308,6 @@ func (s *ReactionsService) ListPullRequestCommentReactions(ctx context.Context, return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) var m []*Reaction @@ -343,7 +336,6 @@ func (s *ReactionsService) CreatePullRequestCommentReaction(ctx context.Context, return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) m := &Reaction{} @@ -534,7 +526,6 @@ func (s *ReactionsService) deleteReaction(ctx context.Context, url string) (*Res return nil, err } - // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) return s.client.Do(ctx, req, nil) @@ -585,7 +576,6 @@ func (s *ReactionsService) ListReleaseReactions(ctx context.Context, owner, repo return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. req.Header.Set("Accept", mediaTypeReactionsPreview) var m []*Reaction diff --git a/github/repos.go b/github/repos.go index 92f802ae612..0119a01b5c4 100644 --- a/github/repos.go +++ b/github/repos.go @@ -434,7 +434,6 @@ func (s *RepositoriesService) ListByOrg(ctx context.Context, org string, opts *R return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. acceptHeaders := []string{mediaTypeTopicsPreview, mediaTypeRepositoryVisibilityPreview} req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) @@ -638,7 +637,6 @@ func (s *RepositoriesService) Get(ctx context.Context, owner, repo string) (*Rep return nil, nil, err } - // TODO: remove custom Accept header when the license support fully launches // https://docs.github.com/rest/licenses/#get-a-repositorys-license acceptHeaders := []string{ mediaTypeCodesOfConductPreview, @@ -671,7 +669,6 @@ func (s *RepositoriesService) GetCodeOfConduct(ctx context.Context, owner, repo return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeCodesOfConductPreview) r := new(Repository) @@ -789,7 +786,6 @@ func (s *RepositoriesService) GetVulnerabilityAlerts(ctx context.Context, owner, return false, nil, err } - // TODO: remove custom Accept header when this API fully launches req.Header.Set("Accept", mediaTypeRequiredVulnerabilityAlertsPreview) resp, err := s.client.Do(ctx, req, nil) @@ -810,7 +806,6 @@ func (s *RepositoriesService) EnableVulnerabilityAlerts(ctx context.Context, own return nil, err } - // TODO: remove custom Accept header when this API fully launches req.Header.Set("Accept", mediaTypeRequiredVulnerabilityAlertsPreview) return s.client.Do(ctx, req, nil) @@ -829,7 +824,6 @@ func (s *RepositoriesService) DisableVulnerabilityAlerts(ctx context.Context, ow return nil, err } - // TODO: remove custom Accept header when this API fully launches req.Header.Set("Accept", mediaTypeRequiredVulnerabilityAlertsPreview) return s.client.Do(ctx, req, nil) @@ -1507,7 +1501,6 @@ func (s *RepositoriesService) GetBranchProtection(ctx context.Context, owner, re return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) p := new(Protection) @@ -1587,7 +1580,6 @@ func (s *RepositoriesService) UpdateBranchProtection(ctx context.Context, owner, return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) p := new(Protection) @@ -1630,7 +1622,6 @@ func (s *RepositoriesService) GetSignaturesProtectedBranch(ctx context.Context, return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches req.Header.Set("Accept", mediaTypeSignaturePreview) p := new(SignaturesProtectedBranch) @@ -1657,7 +1648,6 @@ func (s *RepositoriesService) RequireSignaturesOnProtectedBranch(ctx context.Con return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches req.Header.Set("Accept", mediaTypeSignaturePreview) r := new(SignaturesProtectedBranch) @@ -1683,7 +1673,6 @@ func (s *RepositoriesService) OptionalSignaturesOnProtectedBranch(ctx context.Co return nil, err } - // TODO: remove custom Accept header when this API fully launches req.Header.Set("Accept", mediaTypeSignaturePreview) return s.client.Do(ctx, req, nil) @@ -1764,7 +1753,6 @@ func (s *RepositoriesService) GetPullRequestReviewEnforcement(ctx context.Contex return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) r := new(PullRequestReviewsEnforcement) @@ -1791,7 +1779,6 @@ func (s *RepositoriesService) UpdatePullRequestReviewEnforcement(ctx context.Con return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) r := new(PullRequestReviewsEnforcement) @@ -1823,7 +1810,6 @@ func (s *RepositoriesService) DisableDismissalRestrictions(ctx context.Context, return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview) r := new(PullRequestReviewsEnforcement) @@ -1933,7 +1919,6 @@ func (s *RepositoriesService) ListAllTopics(ctx context.Context, owner, repo str return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeTopicsPreview) topics := new(repositoryTopics) @@ -1963,7 +1948,6 @@ func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeTopicsPreview) t = new(repositoryTopics) diff --git a/github/repos_comments.go b/github/repos_comments.go index 766a614cc12..3d02a1999e8 100644 --- a/github/repos_comments.go +++ b/github/repos_comments.go @@ -50,7 +50,6 @@ func (s *RepositoriesService) ListComments(ctx context.Context, owner, repo stri return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeReactionsPreview) var comments []*RepositoryComment @@ -79,7 +78,6 @@ func (s *RepositoriesService) ListCommitComments(ctx context.Context, owner, rep return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeReactionsPreview) var comments []*RepositoryComment @@ -125,7 +123,6 @@ func (s *RepositoriesService) GetComment(ctx context.Context, owner, repo string return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeReactionsPreview) c := new(RepositoryComment) diff --git a/github/repos_commits.go b/github/repos_commits.go index 9d7c8d47822..36192cd3ed1 100644 --- a/github/repos_commits.go +++ b/github/repos_commits.go @@ -313,7 +313,6 @@ func (s *RepositoriesService) ListBranchesHeadCommit(ctx context.Context, owner, return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeListPullsOrBranchesForCommitPreview) var branchCommits []*BranchCommit resp, err := s.client.Do(ctx, req, &branchCommits) diff --git a/github/repos_deployments.go b/github/repos_deployments.go index ae9978307aa..637067491b0 100644 --- a/github/repos_deployments.go +++ b/github/repos_deployments.go @@ -122,7 +122,6 @@ func (s *RepositoriesService) CreateDeployment(ctx context.Context, owner, repo return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview} req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) @@ -198,7 +197,6 @@ func (s *RepositoriesService) ListDeploymentStatuses(ctx context.Context, owner, return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview} req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) @@ -224,7 +222,6 @@ func (s *RepositoriesService) GetDeploymentStatus(ctx context.Context, owner, re return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview} req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) @@ -250,7 +247,6 @@ func (s *RepositoriesService) CreateDeploymentStatus(ctx context.Context, owner, return nil, nil, err } - // TODO: remove custom Accept headers when APIs fully launch. acceptHeaders := []string{mediaTypeDeploymentStatusPreview, mediaTypeExpandDeploymentStatusPreview} req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) diff --git a/github/repos_forks.go b/github/repos_forks.go index 268233c37e0..cffc87e9b0b 100644 --- a/github/repos_forks.go +++ b/github/repos_forks.go @@ -39,7 +39,6 @@ func (s *RepositoriesService) ListForks(ctx context.Context, owner, repo string, return nil, nil, err } - // TODO: remove custom Accept header when topics API fully launches. req.Header.Set("Accept", mediaTypeTopicsPreview) var repos []*Repository diff --git a/github/repos_pages.go b/github/repos_pages.go index 5986fc01ba9..92110f59831 100644 --- a/github/repos_pages.go +++ b/github/repos_pages.go @@ -219,7 +219,6 @@ func (s *RepositoriesService) DisablePages(ctx context.Context, owner, repo stri return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeEnablePagesAPIPreview) return s.client.Do(ctx, req, nil) diff --git a/github/repos_prereceive_hooks.go b/github/repos_prereceive_hooks.go index 61373b4a9b1..0951916d1b6 100644 --- a/github/repos_prereceive_hooks.go +++ b/github/repos_prereceive_hooks.go @@ -39,7 +39,6 @@ func (s *RepositoriesService) ListPreReceiveHooks(ctx context.Context, owner, re return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypePreReceiveHooksPreview) var hooks []*PreReceiveHook @@ -63,7 +62,6 @@ func (s *RepositoriesService) GetPreReceiveHook(ctx context.Context, owner, repo return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypePreReceiveHooksPreview) h := new(PreReceiveHook) @@ -87,7 +85,6 @@ func (s *RepositoriesService) UpdatePreReceiveHook(ctx context.Context, owner, r return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypePreReceiveHooksPreview) h := new(PreReceiveHook) @@ -111,7 +108,6 @@ func (s *RepositoriesService) DeletePreReceiveHook(ctx context.Context, owner, r return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypePreReceiveHooksPreview) return s.client.Do(ctx, req, nil) diff --git a/github/repos_test.go b/github/repos_test.go index 0dc28671f81..dde24d1fd89 100644 --- a/github/repos_test.go +++ b/github/repos_test.go @@ -1159,7 +1159,6 @@ func TestRepositoriesService_GetBranchProtection(t *testing.T) { mux.HandleFunc(test.urlPath, func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - // TODO: remove custom Accept header when this API fully launches testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) fmt.Fprintf(w, `{ "required_status_checks":{ @@ -1314,7 +1313,6 @@ func TestRepositoriesService_GetBranchProtection_noDismissalRestrictions(t *test for _, test := range tests { mux.HandleFunc(test.urlPath, func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - // TODO: remove custom Accept header when this API fully launches testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) fmt.Fprintf(w, `{ "required_status_checks":{ @@ -1475,7 +1473,6 @@ func TestRepositoriesService_UpdateBranchProtection_Contexts(t *testing.T) { t.Errorf("Request body = %+v, want %+v", v, input) } - // TODO: remove custom Accept header when this API fully launches testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) fmt.Fprint(w, `{ "required_status_checks":{ @@ -1664,7 +1661,6 @@ func TestRepositoriesService_UpdateBranchProtection_EmptyContexts(t *testing.T) t.Errorf("Request body = %+v, want %+v", v, input) } - // TODO: remove custom Accept header when this API fully launches testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) fmt.Fprint(w, `{ "required_status_checks":{ @@ -1844,7 +1840,6 @@ func TestRepositoriesService_UpdateBranchProtection_Checks(t *testing.T) { t.Errorf("Request body = %+v, want %+v", v, input) } - // TODO: remove custom Accept header when this API fully launches testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) fmt.Fprint(w, `{ "required_status_checks":{ @@ -1998,7 +1993,6 @@ func TestRepositoriesService_UpdateBranchProtection_EmptyChecks(t *testing.T) { t.Errorf("Request body = %+v, want %+v", v, input) } - // TODO: remove custom Accept header when this API fully launches testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) fmt.Fprint(w, `{ "required_status_checks":{ @@ -2141,7 +2135,6 @@ func TestRepositoriesService_UpdateBranchProtection_StrictNoChecks(t *testing.T) t.Errorf("Request body = %+v, want %+v", v, input) } - // TODO: remove custom Accept header when this API fully launches testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) fmt.Fprint(w, `{ "required_status_checks":{ @@ -2816,7 +2809,6 @@ func TestRepositoriesService_GetPullRequestReviewEnforcement(t *testing.T) { mux.HandleFunc(test.urlPath, func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - // TODO: remove custom Accept header when this API fully launches testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) fmt.Fprint(w, `{ "dismissal_restrictions":{ @@ -2905,7 +2897,6 @@ func TestRepositoriesService_UpdatePullRequestReviewEnforcement(t *testing.T) { if !cmp.Equal(v, input) { t.Errorf("Request body = %+v, want %+v", v, input) } - // TODO: remove custom Accept header when this API fully launches testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) fmt.Fprint(w, `{ "dismissal_restrictions":{ @@ -2979,7 +2970,6 @@ func TestRepositoriesService_DisableDismissalRestrictions(t *testing.T) { mux.HandleFunc(test.urlPath, func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") - // TODO: remove custom Accept header when this API fully launches testHeader(t, r, "Accept", mediaTypeRequiredApprovingReviewsPreview) testBody(t, r, `{"dismissal_restrictions":{}}`+"\n") fmt.Fprint(w, `{"dismiss_stale_reviews":true,"require_code_owner_reviews":true,"required_approving_review_count":1}`) diff --git a/github/search.go b/github/search.go index 73b466396ab..9b9f937033d 100644 --- a/github/search.go +++ b/github/search.go @@ -9,6 +9,7 @@ import ( "context" "fmt" "strconv" + "strings" qs "github.com/google/go-querystring/query" ) @@ -316,12 +317,28 @@ func (s *SearchService) search(ctx context.Context, searchType string, parameter if err != nil { return nil, err } - // https://docs.github.com/en/rest/search/search#text-match-metadata + var acceptHeaders []string + switch searchType { + case "commits": + // Accept header for search commits preview endpoint + acceptHeaders = append(acceptHeaders, mediaTypeCommitSearchPreview) + case "topics": + // Accept header for search repositories based on topics preview endpoint + acceptHeaders = append(acceptHeaders, mediaTypeTopicsPreview) + case "repositories": + // Accept header for search repositories based on topics preview endpoint + acceptHeaders = append(acceptHeaders, mediaTypeTopicsPreview) + case "issues": + // Accept header for search issues based on reactions preview endpoint + acceptHeaders = append(acceptHeaders, mediaTypeReactionsPreview) + } + // https://docs.github.com/rest/search#search-repositories // Accept header defaults to "application/vnd.github.v3+json" // We change it here to fetch back text-match metadata if opts != nil && opts.TextMatch { - req.Header.Set("Accept", "application/vnd.github.v3.text-match+json") + acceptHeaders = append(acceptHeaders, "application/vnd.github.v3.text-match+json") } + req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) return s.client.Do(ctx, req, result) } diff --git a/github/search_test.go b/github/search_test.go index b24e8d04ef9..aec5b56c17e 100644 --- a/github/search_test.go +++ b/github/search_test.go @@ -8,6 +8,7 @@ package github import ( "fmt" "net/http" + "strings" "testing" "github.com/google/go-cmp/cmp" @@ -77,7 +78,12 @@ func TestSearchService_RepositoriesTextMatch(t *testing.T) { ] } ` - if r.Header.Get("Accept") == "application/vnd.github.v3.text-match+json" { + list := strings.Split(r.Header.Get("Accept"), ",") + aMap := make(map[string]struct{}) + for _, s := range list { + aMap[strings.TrimSpace(s)] = struct{}{} + } + if _, ok := aMap["application/vnd.github.v3.text-match+json"]; ok { textMatchResponse = ` { "total_count": 1, diff --git a/github/teams.go b/github/teams.go index 682c6508185..9e851378242 100644 --- a/github/teams.go +++ b/github/teams.go @@ -405,7 +405,6 @@ func (s *TeamsService) ListTeamReposByID(ctx context.Context, orgID, teamID int6 return nil, nil, err } - // TODO: remove custom Accept header when topics API fully launches. req.Header.Set("Accept", mediaTypeTopicsPreview) var repos []*Repository @@ -434,7 +433,6 @@ func (s *TeamsService) ListTeamReposBySlug(ctx context.Context, org, slug string return nil, nil, err } - // TODO: remove custom Accept header when topics API fully launches. req.Header.Set("Accept", mediaTypeTopicsPreview) var repos []*Repository @@ -626,7 +624,6 @@ func (s *TeamsService) ListTeamProjectsByID(ctx context.Context, orgID, teamID i return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeProjectsPreview) var projects []*ProjectV2 @@ -651,7 +648,6 @@ func (s *TeamsService) ListTeamProjectsBySlug(ctx context.Context, org, slug str return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeProjectsPreview) var projects []*ProjectV2 @@ -678,7 +674,6 @@ func (s *TeamsService) ReviewTeamProjectsByID(ctx context.Context, orgID, teamID return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeProjectsPreview) projects := &ProjectV2{} @@ -703,7 +698,6 @@ func (s *TeamsService) ReviewTeamProjectsBySlug(ctx context.Context, org, slug s return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeProjectsPreview) projects := &ProjectV2{} @@ -743,7 +737,6 @@ func (s *TeamsService) AddTeamProjectByID(ctx context.Context, orgID, teamID, pr return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeProjectsPreview) return s.client.Do(ctx, req, nil) @@ -763,7 +756,6 @@ func (s *TeamsService) AddTeamProjectBySlug(ctx context.Context, org, slug strin return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeProjectsPreview) return s.client.Do(ctx, req, nil) @@ -788,7 +780,6 @@ func (s *TeamsService) RemoveTeamProjectByID(ctx context.Context, orgID, teamID, return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeProjectsPreview) return s.client.Do(ctx, req, nil) @@ -811,7 +802,6 @@ func (s *TeamsService) RemoveTeamProjectBySlug(ctx context.Context, org, slug st return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeProjectsPreview) return s.client.Do(ctx, req, nil) diff --git a/github/users_blocking.go b/github/users_blocking.go index 3f2af38f6c9..39d89d34c68 100644 --- a/github/users_blocking.go +++ b/github/users_blocking.go @@ -27,7 +27,6 @@ func (s *UsersService) ListBlockedUsers(ctx context.Context, opts *ListOptions) return nil, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeBlockUsersPreview) var blockedUsers []*User @@ -52,7 +51,6 @@ func (s *UsersService) IsBlocked(ctx context.Context, user string) (bool, *Respo return false, nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeBlockUsersPreview) resp, err := s.client.Do(ctx, req, nil) @@ -73,7 +71,6 @@ func (s *UsersService) BlockUser(ctx context.Context, user string) (*Response, e return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeBlockUsersPreview) return s.client.Do(ctx, req, nil) @@ -92,7 +89,6 @@ func (s *UsersService) UnblockUser(ctx context.Context, user string) (*Response, return nil, err } - // TODO: remove custom Accept header when this API fully launches. req.Header.Set("Accept", mediaTypeBlockUsersPreview) return s.client.Do(ctx, req, nil)