@ -9,13 +9,14 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"
)
// RepositoriesService handles communication with the repository related
// methods of the GitHub API.
//
// GitHub API docs: https://developer.github.com/v3 /repos/
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/
type RepositoriesService service
// Repository represents a GitHub repository.
@ -44,16 +45,18 @@ type Repository struct {
ForksCount * int ` json:"forks_count,omitempty" `
NetworkCount * int ` json:"network_count,omitempty" `
OpenIssuesCount * int ` json:"open_issues_count,omitempty" `
OpenIssues * int ` json:"open_issues,omitempty" ` // Deprecated: Replaced by OpenIssuesCount. For backward compatibility OpenIssues is still populated.
StargazersCount * int ` json:"stargazers_count,omitempty" `
SubscribersCount * int ` json:"subscribers_count,omitempty" `
WatchersCount * int ` json:"watchers_count,omitempty" `
WatchersCount * int ` json:"watchers_count,omitempty" ` // Deprecated: Replaced by StargazersCount. For backward compatibility WatchersCount is still populated.
Watchers * int ` json:"watchers,omitempty" ` // Deprecated: Replaced by StargazersCount. For backward compatibility Watchers is still populated.
Size * int ` json:"size,omitempty" `
AutoInit * bool ` json:"auto_init,omitempty" `
Parent * Repository ` json:"parent,omitempty" `
Source * Repository ` json:"source,omitempty" `
TemplateRepository * Repository ` json:"template_repository,omitempty" `
Organization * Organization ` json:"organization,omitempty" `
Permissions * map [ string ] bool ` json:"permissions,omitempty" `
Permissions map [ string ] bool ` json:"permissions,omitempty" `
AllowRebaseMerge * bool ` json:"allow_rebase_merge,omitempty" `
AllowSquashMerge * bool ` json:"allow_squash_merge,omitempty" `
AllowMergeCommit * bool ` json:"allow_merge_commit,omitempty" `
@ -119,7 +122,7 @@ type Repository struct {
TeamsURL * string ` json:"teams_url,omitempty" `
// TextMatches is only populated from search results that request text matches
// See: search.go and https://developer.github.com/v3 /search/#text-match-metadata
// See: search.go and https://docs.github.com/en/free-pro-team@latest/rest/reference /search/#text-match-metadata
TextMatches [ ] * TextMatch ` json:"text_matches,omitempty" `
// Visibility is only used for Create and Edit endpoints. The visibility field
@ -182,8 +185,8 @@ type RepositoryListOptions struct {
// List the repositories for a user. Passing the empty string will list
// repositories for the authenticated user.
//
// GitHub API docs: https://developer.github.com/v3/repos/#list-repositories-for-a -user
// GitHub API docs: https://developer.github.com/v3/repos/#list-repositories-for-the-authenticated -user
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-repositories-for-the-authenticated -user
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#list-repositories-for-a -user
func ( s * RepositoriesService ) List ( ctx context . Context , user string , opts * RepositoryListOptions ) ( [ ] * Repository , * Response , error ) {
var u string
if user != "" {
@ -202,7 +205,7 @@ func (s *RepositoriesService) List(ctx context.Context, user string, opts *Repos
}
// TODO: remove custom Accept headers when APIs fully launch.
acceptHeaders := [ ] string { mediaTypeTopicsPreview }
acceptHeaders := [ ] string { mediaTypeTopicsPreview , mediaTypeRepositoryVisibilityPreview }
req . Header . Set ( "Accept" , strings . Join ( acceptHeaders , ", " ) )
var repos [ ] * Repository
@ -234,7 +237,7 @@ type RepositoryListByOrgOptions struct {
// ListByOrg lists the repositories for an organization.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#list-organization-repositories
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#list-organization-repositories
func ( s * RepositoriesService ) ListByOrg ( ctx context . Context , org string , opts * RepositoryListByOrgOptions ) ( [ ] * Repository , * Response , error ) {
u := fmt . Sprintf ( "orgs/%v/repos" , org )
u , err := addOptions ( u , opts )
@ -248,7 +251,7 @@ func (s *RepositoriesService) ListByOrg(ctx context.Context, org string, opts *R
}
// TODO: remove custom Accept headers when APIs fully launch.
acceptHeaders := [ ] string { mediaTypeTopicsPreview }
acceptHeaders := [ ] string { mediaTypeTopicsPreview , mediaTypeRepositoryVisibilityPreview }
req . Header . Set ( "Accept" , strings . Join ( acceptHeaders , ", " ) )
var repos [ ] * Repository
@ -269,7 +272,7 @@ type RepositoryListAllOptions struct {
// ListAll lists all GitHub repositories in the order that they were created.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#list-public-repositories
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#list-public-repositories
func ( s * RepositoriesService ) ListAll ( ctx context . Context , opts * RepositoryListAllOptions ) ( [ ] * Repository , * Response , error ) {
u , err := addOptions ( "repositories" , opts )
if err != nil {
@ -327,8 +330,13 @@ type createRepoRequest struct {
// Note that only a subset of the repo fields are used and repo must
// not be nil.
//
// GitHub API docs: https://developer.github.com/v3/repos/#create-a-repository-for-the-authenticated-user
// GitHub API docs: https://developer.github.com/v3/repos/#create-an-organization-repository
// Also note that this method will return the response without actually
// waiting for GitHub to finish creating the repository and letting the
// changes propagate throughout its servers. You may set up a loop with
// exponential back-off to verify repository's creation.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-a-repository-for-the-authenticated-user
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#create-an-organization-repository
func ( s * RepositoriesService ) Create ( ctx context . Context , org string , repo * Repository ) ( * Repository , * Response , error ) {
var u string
if org != "" {
@ -380,12 +388,13 @@ type TemplateRepoRequest struct {
Owner * string ` json:"owner,omitempty" `
Description * string ` json:"description,omitempty" `
IncludeAllBranches * bool ` json:"include_all_branches,omitempty" `
Private * bool ` json:"private,omitempty" `
}
// CreateFromTemplate generates a repository from a template.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#create-a-repository-using-a-template
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#create-a-repository-using-a-template
func ( s * RepositoriesService ) CreateFromTemplate ( ctx context . Context , templateOwner , templateRepo string , templateRepoReq * TemplateRepoRequest ) ( * Repository , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/generate" , templateOwner , templateRepo )
@ -406,7 +415,7 @@ func (s *RepositoriesService) CreateFromTemplate(ctx context.Context, templateOw
// Get fetches a repository.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#get-a-repository
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#get-a-repository
func ( s * RepositoriesService ) Get ( ctx context . Context , owner , repo string ) ( * Repository , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v" , owner , repo )
req , err := s . client . NewRequest ( "GET" , u , nil )
@ -415,7 +424,7 @@ func (s *RepositoriesService) Get(ctx context.Context, owner, repo string) (*Rep
}
// TODO: remove custom Accept header when the license support fully launches
// https://developer.github.com/v3 /licenses/#get-a-repositorys-license
// https://docs.github.com/en/free-pro-team@latest/rest/reference /licenses/#get-a-repositorys-license
acceptHeaders := [ ] string {
mediaTypeCodesOfConductPreview ,
mediaTypeTopicsPreview ,
@ -435,7 +444,7 @@ func (s *RepositoriesService) Get(ctx context.Context, owner, repo string) (*Rep
// GetCodeOfConduct gets the contents of a repository's code of conduct.
//
// GitHub API docs: https://developer.github.com/v3/codes_of_ conduct/#get-the-code-of-conduct-for-a-repository
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/codes-of- conduct/#get-the-code-of-conduct-for-a-repository
func ( s * RepositoriesService ) GetCodeOfConduct ( ctx context . Context , owner , repo string ) ( * CodeOfConduct , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/community/code_of_conduct" , owner , repo )
req , err := s . client . NewRequest ( "GET" , u , nil )
@ -476,7 +485,7 @@ func (s *RepositoriesService) GetByID(ctx context.Context, id int64) (*Repositor
// Edit updates a repository.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#update-a-repository
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#update-a-repository
func ( s * RepositoriesService ) Edit ( ctx context . Context , owner , repo string , repository * Repository ) ( * Repository , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v" , owner , repo )
req , err := s . client . NewRequest ( "PATCH" , u , repository )
@ -497,7 +506,7 @@ func (s *RepositoriesService) Edit(ctx context.Context, owner, repo string, repo
// Delete a repository.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#delete-a-repository
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#delete-a-repository
func ( s * RepositoriesService ) Delete ( ctx context . Context , owner , repo string ) ( * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v" , owner , repo )
req , err := s . client . NewRequest ( "DELETE" , u , nil )
@ -529,6 +538,8 @@ type Contributor struct {
Type * string ` json:"type,omitempty" `
SiteAdmin * bool ` json:"site_admin,omitempty" `
Contributions * int ` json:"contributions,omitempty" `
Name * string ` json:"name,omitempty" `
Email * string ` json:"email,omitempty" `
}
// ListContributorsOptions specifies the optional parameters to the
@ -542,7 +553,7 @@ type ListContributorsOptions struct {
// GetVulnerabilityAlerts checks if vulnerability alerts are enabled for a repository.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#check-if-vulnerability-alerts-are-enabled-for-a-repository
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#check-if-vulnerability-alerts-are-enabled-for-a-repository
func ( s * RepositoriesService ) GetVulnerabilityAlerts ( ctx context . Context , owner , repository string ) ( bool , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/vulnerability-alerts" , owner , repository )
@ -562,7 +573,7 @@ func (s *RepositoriesService) GetVulnerabilityAlerts(ctx context.Context, owner,
// EnableVulnerabilityAlerts enables vulnerability alerts and the dependency graph for a repository.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#enable-vulnerability-alerts
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#enable-vulnerability-alerts
func ( s * RepositoriesService ) EnableVulnerabilityAlerts ( ctx context . Context , owner , repository string ) ( * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/vulnerability-alerts" , owner , repository )
@ -579,7 +590,7 @@ func (s *RepositoriesService) EnableVulnerabilityAlerts(ctx context.Context, own
// DisableVulnerabilityAlerts disables vulnerability alerts and the dependency graph for a repository.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#disable-vulnerability-alerts
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#disable-vulnerability-alerts
func ( s * RepositoriesService ) DisableVulnerabilityAlerts ( ctx context . Context , owner , repository string ) ( * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/vulnerability-alerts" , owner , repository )
@ -596,7 +607,7 @@ func (s *RepositoriesService) DisableVulnerabilityAlerts(ctx context.Context, ow
// EnableAutomatedSecurityFixes enables the automated security fixes for a repository.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#enable-automated-security-fixes
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#enable-automated-security-fixes
func ( s * RepositoriesService ) EnableAutomatedSecurityFixes ( ctx context . Context , owner , repository string ) ( * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/automated-security-fixes" , owner , repository )
@ -613,7 +624,7 @@ func (s *RepositoriesService) EnableAutomatedSecurityFixes(ctx context.Context,
// DisableAutomatedSecurityFixes disables vulnerability alerts and the dependency graph for a repository.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#disable-automated-security-fixes
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#disable-automated-security-fixes
func ( s * RepositoriesService ) DisableAutomatedSecurityFixes ( ctx context . Context , owner , repository string ) ( * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/automated-security-fixes" , owner , repository )
@ -630,7 +641,7 @@ func (s *RepositoriesService) DisableAutomatedSecurityFixes(ctx context.Context,
// ListContributors lists contributors for a repository.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#list-repository-contributors
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#list-repository-contributors
func ( s * RepositoriesService ) ListContributors ( ctx context . Context , owner string , repository string , opts * ListContributorsOptions ) ( [ ] * Contributor , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/contributors" , owner , repository )
u , err := addOptions ( u , opts )
@ -646,7 +657,7 @@ func (s *RepositoriesService) ListContributors(ctx context.Context, owner string
var contributor [ ] * Contributor
resp , err := s . client . Do ( ctx , req , & contributor )
if err != nil {
return nil , nil , err
return nil , resp , err
}
return contributor , resp , nil
@ -661,7 +672,7 @@ func (s *RepositoriesService) ListContributors(ctx context.Context, owner string
// "Python": 7769
// }
//
// GitHub API docs: https://developer.github.com/v3 /repos/#list-repository-languages
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#list-repository-languages
func ( s * RepositoriesService ) ListLanguages ( ctx context . Context , owner string , repo string ) ( map [ string ] int , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/languages" , owner , repo )
req , err := s . client . NewRequest ( "GET" , u , nil )
@ -680,7 +691,7 @@ func (s *RepositoriesService) ListLanguages(ctx context.Context, owner string, r
// ListTeams lists the teams for the specified repository.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#list-repository-teams
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#list-repository-teams
func ( s * RepositoriesService ) ListTeams ( ctx context . Context , owner string , repo string , opts * ListOptions ) ( [ ] * Team , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/teams" , owner , repo )
u , err := addOptions ( u , opts )
@ -712,7 +723,7 @@ type RepositoryTag struct {
// ListTags lists tags for the specified repository.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#list-repository-tags
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#list-repository-tags
func ( s * RepositoriesService ) ListTags ( ctx context . Context , owner string , repo string , opts * ListOptions ) ( [ ] * RepositoryTag , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/tags" , owner , repo )
u , err := addOptions ( u , opts )
@ -750,6 +761,7 @@ type Protection struct {
RequireLinearHistory * RequireLinearHistory ` json:"required_linear_history" `
AllowForcePushes * AllowForcePushes ` json:"allow_force_pushes" `
AllowDeletions * AllowDeletions ` json:"allow_deletions" `
RequiredConversationResolution * RequiredConversationResolution ` json:"required_conversation_resolution" `
}
// ProtectionRequest represents a request to create/edit a branch's protection.
@ -826,7 +838,7 @@ type PullRequestReviewsEnforcementUpdate struct {
RequiredApprovingReviewCount int ` json:"required_approving_review_count" `
}
// RequireLinearHistory represents the configuration to enfore branches with no merge commit.
// RequireLinearHistory represents the configuration to enforc e branches with no merge commit.
type RequireLinearHistory struct {
Enabled bool ` json:"enabled" `
}
@ -841,6 +853,11 @@ type AllowForcePushes struct {
Enabled bool ` json:"enabled" `
}
// RequiredConversationResolution, if enabled, requires all comments on the pull request to be resolved before it can be merged to a protected branch.
type RequiredConversationResolution struct {
Enabled bool ` json:"enabled" `
}
// AdminEnforcement represents the configuration to enforce required status checks for repository administrators.
type AdminEnforcement struct {
URL * string ` json:"url,omitempty" `
@ -900,7 +917,7 @@ type SignaturesProtectedBranch struct {
// ListBranches lists branches for the specified repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#list-branches
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#list-branches
func ( s * RepositoriesService ) ListBranches ( ctx context . Context , owner string , repo string , opts * BranchListOptions ) ( [ ] * Branch , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches" , owner , repo )
u , err := addOptions ( u , opts )
@ -913,9 +930,6 @@ func (s *RepositoriesService) ListBranches(ctx context.Context, owner string, re
return nil , nil , err
}
// TODO: remove custom Accept header when this API fully launches
req . Header . Set ( "Accept" , mediaTypeRequiredApprovingReviewsPreview )
var branches [ ] * Branch
resp , err := s . client . Do ( ctx , req , & branches )
if err != nil {
@ -927,29 +941,55 @@ func (s *RepositoriesService) ListBranches(ctx context.Context, owner string, re
// GetBranch gets the specified branch for a repository.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#get-a-branch
func ( s * RepositoriesService ) GetBranch ( ctx context . Context , owner , repo , branch string ) ( * Branch , * Response , error ) {
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#get-a-branch
func ( s * RepositoriesService ) GetBranch ( ctx context . Context , owner , repo , branch string , followRedirects bool ) ( * Branch , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v" , owner , repo , branch )
req , err := s . client . NewRequest ( "GET" , u , nil )
resp , err := s . getBranchFromURL ( ctx , u , followRedirects )
if err != nil {
return nil , nil , err
}
defer resp . Body . Close ( )
// TODO: remove custom Accept header when this API fully launches
req . Header . Set ( "Accept" , mediaTypeRequiredApprovingReviewsPreview )
if resp . StatusCode != http . StatusOK {
return nil , newResponse ( resp ) , fmt . Errorf ( "unexpected status code: %s" , resp . Status )
}
b := new ( Branch )
resp , err := s . client . Do ( ctx , req , b )
err = json . NewDecoder ( resp . Body ) . Decode ( b )
return b , newResponse ( resp ) , err
}
func ( s * RepositoriesService ) getBranchFromURL ( ctx context . Context , u string , followRedirects bool ) ( * http . Response , error ) {
req , err := s . client . NewRequest ( "GET" , u , nil )
if err != nil {
return nil , resp , err
return nil , err
}
var resp * http . Response
// Use http.DefaultTransport if no custom Transport is configured
req = withContext ( ctx , req )
if s . client . client . Transport == nil {
resp , err = http . DefaultTransport . RoundTrip ( req )
} else {
resp , err = s . client . client . Transport . RoundTrip ( req )
}
if err != nil {
return nil , err
}
return b , resp , nil
// If redirect response is returned, follow it
if followRedirects && resp . StatusCode == http . StatusMovedPermanently {
resp . Body . Close ( )
u = resp . Header . Get ( "Location" )
resp , err = s . getBranchFromURL ( ctx , u , false )
}
return resp , err
}
// GetBranchProtection gets the protection of a given branch.
//
// GitHub API docs: https://developer.github.com/v3/repos/branches/#get-branch-protection
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#get-branch-protection
func ( s * RepositoriesService ) GetBranchProtection ( ctx context . Context , owner , repo , branch string ) ( * Protection , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection" , owner , repo , branch )
req , err := s . client . NewRequest ( "GET" , u , nil )
@ -971,7 +1011,7 @@ func (s *RepositoriesService) GetBranchProtection(ctx context.Context, owner, re
// GetRequiredStatusChecks gets the required status checks for a given protected branch.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#get-status-checks-protection
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#get-status-checks-protection
func ( s * RepositoriesService ) GetRequiredStatusChecks ( ctx context . Context , owner , repo , branch string ) ( * RequiredStatusChecks , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/required_status_checks" , owner , repo , branch )
req , err := s . client . NewRequest ( "GET" , u , nil )
@ -979,9 +1019,6 @@ func (s *RepositoriesService) GetRequiredStatusChecks(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 ( RequiredStatusChecks )
resp , err := s . client . Do ( ctx , req , p )
if err != nil {
@ -993,7 +1030,7 @@ func (s *RepositoriesService) GetRequiredStatusChecks(ctx context.Context, owner
// ListRequiredStatusChecksContexts lists the required status checks contexts for a given protected branch.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#get-all-status-check-contexts
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#get-all-status-check-contexts
func ( s * RepositoriesService ) ListRequiredStatusChecksContexts ( ctx context . Context , owner , repo , branch string ) ( contexts [ ] string , resp * Response , err error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/required_status_checks/contexts" , owner , repo , branch )
req , err := s . client . NewRequest ( "GET" , u , nil )
@ -1001,9 +1038,6 @@ func (s *RepositoriesService) ListRequiredStatusChecksContexts(ctx context.Conte
return nil , nil , err
}
// TODO: remove custom Accept header when this API fully launches
req . Header . Set ( "Accept" , mediaTypeRequiredApprovingReviewsPreview )
resp , err = s . client . Do ( ctx , req , & contexts )
if err != nil {
return nil , resp , err
@ -1014,7 +1048,7 @@ func (s *RepositoriesService) ListRequiredStatusChecksContexts(ctx context.Conte
// UpdateBranchProtection updates the protection of a given branch.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#update-branch-protection
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#update-branch-protection
func ( s * RepositoriesService ) UpdateBranchProtection ( ctx context . Context , owner , repo , branch string , preq * ProtectionRequest ) ( * Protection , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection" , owner , repo , branch )
req , err := s . client . NewRequest ( "PUT" , u , preq )
@ -1036,7 +1070,7 @@ func (s *RepositoriesService) UpdateBranchProtection(ctx context.Context, owner,
// RemoveBranchProtection removes the protection of a given branch.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#delete-branch-protection
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#delete-branch-protection
func ( s * RepositoriesService ) RemoveBranchProtection ( ctx context . Context , owner , repo , branch string ) ( * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection" , owner , repo , branch )
req , err := s . client . NewRequest ( "DELETE" , u , nil )
@ -1044,15 +1078,12 @@ func (s *RepositoriesService) RemoveBranchProtection(ctx context.Context, owner,
return nil , err
}
// TODO: remove custom Accept header when this API fully launches
req . Header . Set ( "Accept" , mediaTypeRequiredApprovingReviewsPreview )
return s . client . Do ( ctx , req , nil )
}
// GetSignaturesProtectedBranch gets required signatures of protected branch.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#get-commit-signature-protection
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#get-commit-signature-protection
func ( s * RepositoriesService ) GetSignaturesProtectedBranch ( ctx context . Context , owner , repo , branch string ) ( * SignaturesProtectedBranch , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/required_signatures" , owner , repo , branch )
req , err := s . client . NewRequest ( "GET" , u , nil )
@ -1075,7 +1106,7 @@ func (s *RepositoriesService) GetSignaturesProtectedBranch(ctx context.Context,
// RequireSignaturesOnProtectedBranch makes signed commits required on a protected branch.
// It requires admin access and branch protection to be enabled.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#create-commit-signature-protection
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#create-commit-signature-protection
func ( s * RepositoriesService ) RequireSignaturesOnProtectedBranch ( ctx context . Context , owner , repo , branch string ) ( * SignaturesProtectedBranch , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/required_signatures" , owner , repo , branch )
req , err := s . client . NewRequest ( "POST" , u , nil )
@ -1097,7 +1128,7 @@ func (s *RepositoriesService) RequireSignaturesOnProtectedBranch(ctx context.Con
// OptionalSignaturesOnProtectedBranch removes required signed commits on a given branch.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#delete-commit-signature-protection
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#delete-commit-signature-protection
func ( s * RepositoriesService ) OptionalSignaturesOnProtectedBranch ( ctx context . Context , owner , repo , branch string ) ( * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/required_signatures" , owner , repo , branch )
req , err := s . client . NewRequest ( "DELETE" , u , nil )
@ -1113,7 +1144,7 @@ func (s *RepositoriesService) OptionalSignaturesOnProtectedBranch(ctx context.Co
// UpdateRequiredStatusChecks updates the required status checks for a given protected branch.
//
// GitHub API docs: https://developer.github.com/v3/repos/branches/#update-status-check-p otection
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#update-status-check-pr otection
func ( s * RepositoriesService ) UpdateRequiredStatusChecks ( ctx context . Context , owner , repo , branch string , sreq * RequiredStatusChecksRequest ) ( * RequiredStatusChecks , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/required_status_checks" , owner , repo , branch )
req , err := s . client . NewRequest ( "PATCH" , u , sreq )
@ -1130,9 +1161,22 @@ func (s *RepositoriesService) UpdateRequiredStatusChecks(ctx context.Context, ow
return sc , resp , nil
}
// RemoveRequiredStatusChecks removes the required status checks for a given protected branch.
//
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#remove-status-check-protection
func ( s * RepositoriesService ) RemoveRequiredStatusChecks ( ctx context . Context , owner , repo , branch string ) ( * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/required_status_checks" , owner , repo , branch )
req , err := s . client . NewRequest ( "DELETE" , u , nil )
if err != nil {
return nil , err
}
return s . client . Do ( ctx , req , nil )
}
// License gets the contents of a repository's license if one is detected.
//
// GitHub API docs: https://developer.github.com/v3/licenses/#get-the-license-for-a-repository
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /licenses/#get-the-license-for-a-repository
func ( s * RepositoriesService ) License ( ctx context . Context , owner , repo string ) ( * RepositoryLicense , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/license" , owner , repo )
req , err := s . client . NewRequest ( "GET" , u , nil )
@ -1151,7 +1195,7 @@ func (s *RepositoriesService) License(ctx context.Context, owner, repo string) (
// GetPullRequestReviewEnforcement gets pull request review enforcement of a protected branch.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#get-pull-request-review-protection
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#get-pull-request-review-protection
func ( s * RepositoriesService ) GetPullRequestReviewEnforcement ( ctx context . Context , owner , repo , branch string ) ( * PullRequestReviewsEnforcement , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/required_pull_request_reviews" , owner , repo , branch )
req , err := s . client . NewRequest ( "GET" , u , nil )
@ -1174,7 +1218,7 @@ func (s *RepositoriesService) GetPullRequestReviewEnforcement(ctx context.Contex
// UpdatePullRequestReviewEnforcement patches pull request review enforcement of a protected branch.
// It requires admin access and branch protection to be enabled.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#update-pull-request-review-protection
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#update-pull-request-review-protection
func ( s * RepositoriesService ) UpdatePullRequestReviewEnforcement ( ctx context . Context , owner , repo , branch string , patch * PullRequestReviewsEnforcementUpdate ) ( * PullRequestReviewsEnforcement , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/required_pull_request_reviews" , owner , repo , branch )
req , err := s . client . NewRequest ( "PATCH" , u , patch )
@ -1197,7 +1241,7 @@ func (s *RepositoriesService) UpdatePullRequestReviewEnforcement(ctx context.Con
// DisableDismissalRestrictions disables dismissal restrictions of a protected branch.
// It requires admin access and branch protection to be enabled.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#update-pull-request-review-protection
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#update-pull-request-review-protection
func ( s * RepositoriesService ) DisableDismissalRestrictions ( ctx context . Context , owner , repo , branch string ) ( * PullRequestReviewsEnforcement , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/required_pull_request_reviews" , owner , repo , branch )
@ -1224,7 +1268,7 @@ func (s *RepositoriesService) DisableDismissalRestrictions(ctx context.Context,
// RemovePullRequestReviewEnforcement removes pull request enforcement of a protected branch.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#delete-pull-request-review-protection
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#delete-pull-request-review-protection
func ( s * RepositoriesService ) RemovePullRequestReviewEnforcement ( ctx context . Context , owner , repo , branch string ) ( * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/required_pull_request_reviews" , owner , repo , branch )
req , err := s . client . NewRequest ( "DELETE" , u , nil )
@ -1232,15 +1276,12 @@ func (s *RepositoriesService) RemovePullRequestReviewEnforcement(ctx context.Con
return nil , err
}
// TODO: remove custom Accept header when this API fully launches
req . Header . Set ( "Accept" , mediaTypeRequiredApprovingReviewsPreview )
return s . client . Do ( ctx , req , nil )
}
// GetAdminEnforcement gets admin enforcement information of a protected branch.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#get-admin-branch-protection
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#get-admin-branch-protection
func ( s * RepositoriesService ) GetAdminEnforcement ( ctx context . Context , owner , repo , branch string ) ( * AdminEnforcement , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/enforce_admins" , owner , repo , branch )
req , err := s . client . NewRequest ( "GET" , u , nil )
@ -1248,9 +1289,6 @@ func (s *RepositoriesService) GetAdminEnforcement(ctx context.Context, owner, re
return nil , nil , err
}
// TODO: remove custom Accept header when this API fully launches
req . Header . Set ( "Accept" , mediaTypeRequiredApprovingReviewsPreview )
r := new ( AdminEnforcement )
resp , err := s . client . Do ( ctx , req , r )
if err != nil {
@ -1263,7 +1301,7 @@ func (s *RepositoriesService) GetAdminEnforcement(ctx context.Context, owner, re
// AddAdminEnforcement adds admin enforcement to a protected branch.
// It requires admin access and branch protection to be enabled.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#set-admin-branch-protection
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#set-admin-branch-protection
func ( s * RepositoriesService ) AddAdminEnforcement ( ctx context . Context , owner , repo , branch string ) ( * AdminEnforcement , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/enforce_admins" , owner , repo , branch )
req , err := s . client . NewRequest ( "POST" , u , nil )
@ -1271,9 +1309,6 @@ func (s *RepositoriesService) AddAdminEnforcement(ctx context.Context, owner, re
return nil , nil , err
}
// TODO: remove custom Accept header when this API fully launches
req . Header . Set ( "Accept" , mediaTypeRequiredApprovingReviewsPreview )
r := new ( AdminEnforcement )
resp , err := s . client . Do ( ctx , req , r )
if err != nil {
@ -1285,7 +1320,7 @@ func (s *RepositoriesService) AddAdminEnforcement(ctx context.Context, owner, re
// RemoveAdminEnforcement removes admin enforcement from a protected branch.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#delete-admin-branch-protection
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#delete-admin-branch-protection
func ( s * RepositoriesService ) RemoveAdminEnforcement ( ctx context . Context , owner , repo , branch string ) ( * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/enforce_admins" , owner , repo , branch )
req , err := s . client . NewRequest ( "DELETE" , u , nil )
@ -1293,9 +1328,6 @@ func (s *RepositoriesService) RemoveAdminEnforcement(ctx context.Context, owner,
return nil , err
}
// TODO: remove custom Accept header when this API fully launches
req . Header . Set ( "Accept" , mediaTypeRequiredApprovingReviewsPreview )
return s . client . Do ( ctx , req , nil )
}
@ -1306,7 +1338,7 @@ type repositoryTopics struct {
// ListAllTopics lists topics for a repository.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#get-all-repository-topics
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#get-all-repository-topics
func ( s * RepositoriesService ) ListAllTopics ( ctx context . Context , owner , repo string ) ( [ ] string , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/topics" , owner , repo )
req , err := s . client . NewRequest ( "GET" , u , nil )
@ -1328,7 +1360,7 @@ func (s *RepositoriesService) ListAllTopics(ctx context.Context, owner, repo str
// ReplaceAllTopics replaces topics for a repository.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#replace-all-repository-topics
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#replace-all-repository-topics
func ( s * RepositoriesService ) ReplaceAllTopics ( ctx context . Context , owner , repo string , topics [ ] string ) ( [ ] string , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/topics" , owner , repo )
t := & repositoryTopics {
@ -1354,10 +1386,10 @@ func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo
return t . Names , resp , nil
}
// ListApps lists the Gith ub apps that have push access to a given protected branch.
// It requires the Gith ub apps to have `write` access to the `content` permission.
// ListApps lists the GitH ub apps that have push access to a given protected branch.
// It requires the GitH ub apps to have `write` access to the `content` permission.
//
// GitHub API docs: https://developer.github.com/v3/repos/branches/#lis t-apps-with-access-to-the-protected-branch
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repos/#ge t-apps-with-access-to-the-protected-branch
func ( s * RepositoriesService ) ListApps ( ctx context . Context , owner , repo , branch string ) ( [ ] * App , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/restrictions/apps" , owner , repo , branch )
req , err := s . client . NewRequest ( "GET" , u , nil )
@ -1376,11 +1408,11 @@ func (s *RepositoriesService) ListApps(ctx context.Context, owner, repo, branch
// ReplaceAppRestrictions replaces the apps that have push access to a given protected branch.
// It removes all apps that previously had push access and grants push access to the new list of apps.
// It requires the Gith ub apps to have `write` access to the `content` permission.
// It requires the GitH ub apps to have `write` access to the `content` permission.
//
// Note: The list of users, apps, and teams in total is limited to 100 items.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#set-app-access-restrictions
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#set-app-access-restrictions
func ( s * RepositoriesService ) ReplaceAppRestrictions ( ctx context . Context , owner , repo , branch string , slug [ ] string ) ( [ ] * App , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/restrictions/apps" , owner , repo , branch )
req , err := s . client . NewRequest ( "PUT" , u , slug )
@ -1391,18 +1423,18 @@ func (s *RepositoriesService) ReplaceAppRestrictions(ctx context.Context, owner,
var apps [ ] * App
resp , err := s . client . Do ( ctx , req , & apps )
if err != nil {
return nil , nil , err
return nil , resp , err
}
return apps , resp , nil
}
// AddAppRestrictions grants the specified apps push access to a given protected branch.
// It requires the Gith ub apps to have `write` access to the `content` permission.
// It requires the GitH ub apps to have `write` access to the `content` permission.
//
// Note: The list of users, apps, and teams in total is limited to 100 items.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#add-app-access-restrictions
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#add-app-access-restrictions
func ( s * RepositoriesService ) AddAppRestrictions ( ctx context . Context , owner , repo , branch string , slug [ ] string ) ( [ ] * App , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/restrictions/apps" , owner , repo , branch )
req , err := s . client . NewRequest ( "POST" , u , slug )
@ -1413,18 +1445,18 @@ func (s *RepositoriesService) AddAppRestrictions(ctx context.Context, owner, rep
var apps [ ] * App
resp , err := s . client . Do ( ctx , req , & apps )
if err != nil {
return nil , nil , err
return nil , resp , err
}
return apps , resp , nil
}
// RemoveAppRestrictions removes the ability of an app to push to this branch.
// It requires the Gith ub apps to have `write` access to the `content` permission.
// It requires the GitH ub apps to have `write` access to the `content` permission.
//
// Note: The list of users, apps, and teams in total is limited to 100 items.
//
// GitHub API docs: https://developer.github.com/v3/repos/branche s/#remove-app-access-restrictions
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference/repo s/#remove-app-access-restrictions
func ( s * RepositoriesService ) RemoveAppRestrictions ( ctx context . Context , owner , repo , branch string , slug [ ] string ) ( [ ] * App , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/branches/%v/protection/restrictions/apps" , owner , repo , branch )
req , err := s . client . NewRequest ( "DELETE" , u , slug )
@ -1435,7 +1467,7 @@ func (s *RepositoriesService) RemoveAppRestrictions(ctx context.Context, owner,
var apps [ ] * App
resp , err := s . client . Do ( ctx , req , & apps )
if err != nil {
return nil , nil , err
return nil , resp , err
}
return apps , resp , nil
@ -1455,7 +1487,7 @@ type TransferRequest struct {
// A follow up request, after a delay of a second or so, should result
// in a successful request.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#transfer-a-repository
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#transfer-a-repository
func ( s * RepositoriesService ) Transfer ( ctx context . Context , owner , repo string , transfer TransferRequest ) ( * Repository , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/transfer" , owner , repo )
@ -1484,7 +1516,7 @@ type DispatchRequestOptions struct {
// Dispatch triggers a repository_dispatch event in a GitHub Actions workflow.
//
// GitHub API docs: https://developer.github.com/v3 /repos/#create-a-repository-dispatch-event
// GitHub API docs: https://docs.github.com/en/free-pro-team@latest/rest/reference /repos/#create-a-repository-dispatch-event
func ( s * RepositoriesService ) Dispatch ( ctx context . Context , owner , repo string , opts DispatchRequestOptions ) ( * Repository , * Response , error ) {
u := fmt . Sprintf ( "repos/%v/%v/dispatches" , owner , repo )