github.com/google/go-github/v57@v57.0.0/github/repos.go (about)

     1  // Copyright 2013 The go-github AUTHORS. All rights reserved.
     2  //
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package github
     7  
     8  import (
     9  	"context"
    10  	"encoding/json"
    11  	"errors"
    12  	"fmt"
    13  	"net/http"
    14  	"net/url"
    15  	"strings"
    16  )
    17  
    18  const githubBranchNotProtected string = "Branch not protected"
    19  
    20  var ErrBranchNotProtected = errors.New("branch is not protected")
    21  
    22  // RepositoriesService handles communication with the repository related
    23  // methods of the GitHub API.
    24  //
    25  // GitHub API docs: https://docs.github.com/rest/repos/
    26  type RepositoriesService service
    27  
    28  // Repository represents a GitHub repository.
    29  type Repository struct {
    30  	ID                        *int64          `json:"id,omitempty"`
    31  	NodeID                    *string         `json:"node_id,omitempty"`
    32  	Owner                     *User           `json:"owner,omitempty"`
    33  	Name                      *string         `json:"name,omitempty"`
    34  	FullName                  *string         `json:"full_name,omitempty"`
    35  	Description               *string         `json:"description,omitempty"`
    36  	Homepage                  *string         `json:"homepage,omitempty"`
    37  	CodeOfConduct             *CodeOfConduct  `json:"code_of_conduct,omitempty"`
    38  	DefaultBranch             *string         `json:"default_branch,omitempty"`
    39  	MasterBranch              *string         `json:"master_branch,omitempty"`
    40  	CreatedAt                 *Timestamp      `json:"created_at,omitempty"`
    41  	PushedAt                  *Timestamp      `json:"pushed_at,omitempty"`
    42  	UpdatedAt                 *Timestamp      `json:"updated_at,omitempty"`
    43  	HTMLURL                   *string         `json:"html_url,omitempty"`
    44  	CloneURL                  *string         `json:"clone_url,omitempty"`
    45  	GitURL                    *string         `json:"git_url,omitempty"`
    46  	MirrorURL                 *string         `json:"mirror_url,omitempty"`
    47  	SSHURL                    *string         `json:"ssh_url,omitempty"`
    48  	SVNURL                    *string         `json:"svn_url,omitempty"`
    49  	Language                  *string         `json:"language,omitempty"`
    50  	Fork                      *bool           `json:"fork,omitempty"`
    51  	ForksCount                *int            `json:"forks_count,omitempty"`
    52  	NetworkCount              *int            `json:"network_count,omitempty"`
    53  	OpenIssuesCount           *int            `json:"open_issues_count,omitempty"`
    54  	OpenIssues                *int            `json:"open_issues,omitempty"` // Deprecated: Replaced by OpenIssuesCount. For backward compatibility OpenIssues is still populated.
    55  	StargazersCount           *int            `json:"stargazers_count,omitempty"`
    56  	SubscribersCount          *int            `json:"subscribers_count,omitempty"`
    57  	WatchersCount             *int            `json:"watchers_count,omitempty"` // Deprecated: Replaced by StargazersCount. For backward compatibility WatchersCount is still populated.
    58  	Watchers                  *int            `json:"watchers,omitempty"`       // Deprecated: Replaced by StargazersCount. For backward compatibility Watchers is still populated.
    59  	Size                      *int            `json:"size,omitempty"`
    60  	AutoInit                  *bool           `json:"auto_init,omitempty"`
    61  	Parent                    *Repository     `json:"parent,omitempty"`
    62  	Source                    *Repository     `json:"source,omitempty"`
    63  	TemplateRepository        *Repository     `json:"template_repository,omitempty"`
    64  	Organization              *Organization   `json:"organization,omitempty"`
    65  	Permissions               map[string]bool `json:"permissions,omitempty"`
    66  	AllowRebaseMerge          *bool           `json:"allow_rebase_merge,omitempty"`
    67  	AllowUpdateBranch         *bool           `json:"allow_update_branch,omitempty"`
    68  	AllowSquashMerge          *bool           `json:"allow_squash_merge,omitempty"`
    69  	AllowMergeCommit          *bool           `json:"allow_merge_commit,omitempty"`
    70  	AllowAutoMerge            *bool           `json:"allow_auto_merge,omitempty"`
    71  	AllowForking              *bool           `json:"allow_forking,omitempty"`
    72  	WebCommitSignoffRequired  *bool           `json:"web_commit_signoff_required,omitempty"`
    73  	DeleteBranchOnMerge       *bool           `json:"delete_branch_on_merge,omitempty"`
    74  	UseSquashPRTitleAsDefault *bool           `json:"use_squash_pr_title_as_default,omitempty"`
    75  	SquashMergeCommitTitle    *string         `json:"squash_merge_commit_title,omitempty"`   // Can be one of: "PR_TITLE", "COMMIT_OR_PR_TITLE"
    76  	SquashMergeCommitMessage  *string         `json:"squash_merge_commit_message,omitempty"` // Can be one of: "PR_BODY", "COMMIT_MESSAGES", "BLANK"
    77  	MergeCommitTitle          *string         `json:"merge_commit_title,omitempty"`          // Can be one of: "PR_TITLE", "MERGE_MESSAGE"
    78  	MergeCommitMessage        *string         `json:"merge_commit_message,omitempty"`        // Can be one of: "PR_BODY", "PR_TITLE", "BLANK"
    79  	Topics                    []string        `json:"topics,omitempty"`
    80  	Archived                  *bool           `json:"archived,omitempty"`
    81  	Disabled                  *bool           `json:"disabled,omitempty"`
    82  
    83  	// Only provided when using RepositoriesService.Get while in preview
    84  	License *License `json:"license,omitempty"`
    85  
    86  	// Additional mutable fields when creating and editing a repository
    87  	Private           *bool   `json:"private,omitempty"`
    88  	HasIssues         *bool   `json:"has_issues,omitempty"`
    89  	HasWiki           *bool   `json:"has_wiki,omitempty"`
    90  	HasPages          *bool   `json:"has_pages,omitempty"`
    91  	HasProjects       *bool   `json:"has_projects,omitempty"`
    92  	HasDownloads      *bool   `json:"has_downloads,omitempty"`
    93  	HasDiscussions    *bool   `json:"has_discussions,omitempty"`
    94  	IsTemplate        *bool   `json:"is_template,omitempty"`
    95  	LicenseTemplate   *string `json:"license_template,omitempty"`
    96  	GitignoreTemplate *string `json:"gitignore_template,omitempty"`
    97  
    98  	// Options for configuring Advanced Security and Secret Scanning
    99  	SecurityAndAnalysis *SecurityAndAnalysis `json:"security_and_analysis,omitempty"`
   100  
   101  	// Creating an organization repository. Required for non-owners.
   102  	TeamID *int64 `json:"team_id,omitempty"`
   103  
   104  	// API URLs
   105  	URL              *string `json:"url,omitempty"`
   106  	ArchiveURL       *string `json:"archive_url,omitempty"`
   107  	AssigneesURL     *string `json:"assignees_url,omitempty"`
   108  	BlobsURL         *string `json:"blobs_url,omitempty"`
   109  	BranchesURL      *string `json:"branches_url,omitempty"`
   110  	CollaboratorsURL *string `json:"collaborators_url,omitempty"`
   111  	CommentsURL      *string `json:"comments_url,omitempty"`
   112  	CommitsURL       *string `json:"commits_url,omitempty"`
   113  	CompareURL       *string `json:"compare_url,omitempty"`
   114  	ContentsURL      *string `json:"contents_url,omitempty"`
   115  	ContributorsURL  *string `json:"contributors_url,omitempty"`
   116  	DeploymentsURL   *string `json:"deployments_url,omitempty"`
   117  	DownloadsURL     *string `json:"downloads_url,omitempty"`
   118  	EventsURL        *string `json:"events_url,omitempty"`
   119  	ForksURL         *string `json:"forks_url,omitempty"`
   120  	GitCommitsURL    *string `json:"git_commits_url,omitempty"`
   121  	GitRefsURL       *string `json:"git_refs_url,omitempty"`
   122  	GitTagsURL       *string `json:"git_tags_url,omitempty"`
   123  	HooksURL         *string `json:"hooks_url,omitempty"`
   124  	IssueCommentURL  *string `json:"issue_comment_url,omitempty"`
   125  	IssueEventsURL   *string `json:"issue_events_url,omitempty"`
   126  	IssuesURL        *string `json:"issues_url,omitempty"`
   127  	KeysURL          *string `json:"keys_url,omitempty"`
   128  	LabelsURL        *string `json:"labels_url,omitempty"`
   129  	LanguagesURL     *string `json:"languages_url,omitempty"`
   130  	MergesURL        *string `json:"merges_url,omitempty"`
   131  	MilestonesURL    *string `json:"milestones_url,omitempty"`
   132  	NotificationsURL *string `json:"notifications_url,omitempty"`
   133  	PullsURL         *string `json:"pulls_url,omitempty"`
   134  	ReleasesURL      *string `json:"releases_url,omitempty"`
   135  	StargazersURL    *string `json:"stargazers_url,omitempty"`
   136  	StatusesURL      *string `json:"statuses_url,omitempty"`
   137  	SubscribersURL   *string `json:"subscribers_url,omitempty"`
   138  	SubscriptionURL  *string `json:"subscription_url,omitempty"`
   139  	TagsURL          *string `json:"tags_url,omitempty"`
   140  	TreesURL         *string `json:"trees_url,omitempty"`
   141  	TeamsURL         *string `json:"teams_url,omitempty"`
   142  
   143  	// TextMatches is only populated from search results that request text matches
   144  	// See: search.go and https://docs.github.com/rest/search/#text-match-metadata
   145  	TextMatches []*TextMatch `json:"text_matches,omitempty"`
   146  
   147  	// Visibility is only used for Create and Edit endpoints. The visibility field
   148  	// overrides the field parameter when both are used.
   149  	// Can be one of public, private or internal.
   150  	Visibility *string `json:"visibility,omitempty"`
   151  
   152  	// RoleName is only returned by the API 'check team permissions for a repository'.
   153  	// See: teams.go (IsTeamRepoByID) https://docs.github.com/rest/teams/teams#check-team-permissions-for-a-repository
   154  	RoleName *string `json:"role_name,omitempty"`
   155  }
   156  
   157  func (r Repository) String() string {
   158  	return Stringify(r)
   159  }
   160  
   161  // BranchListOptions specifies the optional parameters to the
   162  // RepositoriesService.ListBranches method.
   163  type BranchListOptions struct {
   164  	// Setting to true returns only protected branches.
   165  	// When set to false, only unprotected branches are returned.
   166  	// Omitting this parameter returns all branches.
   167  	// Default: nil
   168  	Protected *bool `url:"protected,omitempty"`
   169  
   170  	ListOptions
   171  }
   172  
   173  // RepositoryListOptions specifies the optional parameters to the
   174  // RepositoriesService.List method.
   175  type RepositoryListOptions struct {
   176  	// See RepositoryListByAuthenticatedUserOptions.Visibility
   177  	Visibility string `url:"visibility,omitempty"`
   178  
   179  	// See RepositoryListByAuthenticatedUserOptions.Affiliation
   180  	Affiliation string `url:"affiliation,omitempty"`
   181  
   182  	// See RepositoryListByUserOptions.Type or RepositoryListByAuthenticatedUserOptions.Type
   183  	Type string `url:"type,omitempty"`
   184  
   185  	// See RepositoryListByUserOptions.Sort or RepositoryListByAuthenticatedUserOptions.Sort
   186  	Sort string `url:"sort,omitempty"`
   187  
   188  	// See RepositoryListByUserOptions.Direction or RepositoryListByAuthenticatedUserOptions.Direction
   189  	Direction string `url:"direction,omitempty"`
   190  
   191  	ListOptions
   192  }
   193  
   194  // SecurityAndAnalysis specifies the optional advanced security features
   195  // that are enabled on a given repository.
   196  type SecurityAndAnalysis struct {
   197  	AdvancedSecurity             *AdvancedSecurity             `json:"advanced_security,omitempty"`
   198  	SecretScanning               *SecretScanning               `json:"secret_scanning,omitempty"`
   199  	SecretScanningPushProtection *SecretScanningPushProtection `json:"secret_scanning_push_protection,omitempty"`
   200  	DependabotSecurityUpdates    *DependabotSecurityUpdates    `json:"dependabot_security_updates,omitempty"`
   201  }
   202  
   203  func (s SecurityAndAnalysis) String() string {
   204  	return Stringify(s)
   205  }
   206  
   207  // AdvancedSecurity specifies the state of advanced security on a repository.
   208  //
   209  // GitHub API docs: https://docs.github.com/github/getting-started-with-github/learning-about-github/about-github-advanced-security
   210  type AdvancedSecurity struct {
   211  	Status *string `json:"status,omitempty"`
   212  }
   213  
   214  func (a AdvancedSecurity) String() string {
   215  	return Stringify(a)
   216  }
   217  
   218  // SecretScanning specifies the state of secret scanning on a repository.
   219  //
   220  // GitHub API docs: https://docs.github.com/code-security/secret-security/about-secret-scanning
   221  type SecretScanning struct {
   222  	Status *string `json:"status,omitempty"`
   223  }
   224  
   225  func (s SecretScanning) String() string {
   226  	return Stringify(s)
   227  }
   228  
   229  // SecretScanningPushProtection specifies the state of secret scanning push protection on a repository.
   230  //
   231  // GitHub API docs: https://docs.github.com/code-security/secret-scanning/about-secret-scanning#about-secret-scanning-for-partner-patterns
   232  type SecretScanningPushProtection struct {
   233  	Status *string `json:"status,omitempty"`
   234  }
   235  
   236  func (s SecretScanningPushProtection) String() string {
   237  	return Stringify(s)
   238  }
   239  
   240  // DependabotSecurityUpdates specifies the state of Dependabot security updates on a repository.
   241  //
   242  // GitHub API docs: https://docs.github.com/code-security/dependabot/dependabot-security-updates/about-dependabot-security-updates
   243  type DependabotSecurityUpdates struct {
   244  	Status *string `json:"status,omitempty"`
   245  }
   246  
   247  func (d DependabotSecurityUpdates) String() string {
   248  	return Stringify(d)
   249  }
   250  
   251  // List calls either RepositoriesService.ListByUser or RepositoriesService.ListByAuthenticatedUser
   252  // depending on whether user is empty.
   253  //
   254  // Deprecated: Use RepositoriesService.ListByUser or RepositoriesService.ListByAuthenticatedUser instead.
   255  //
   256  // GitHub API docs: https://docs.github.com/rest/repos/repos#list-repositories-for-a-user
   257  // GitHub API docs: https://docs.github.com/rest/repos/repos#list-repositories-for-the-authenticated-user
   258  //
   259  //meta:operation GET /user/repos
   260  //meta:operation GET /users/{username}/repos
   261  func (s *RepositoriesService) List(ctx context.Context, user string, opts *RepositoryListOptions) ([]*Repository, *Response, error) {
   262  	if opts == nil {
   263  		opts = &RepositoryListOptions{}
   264  	}
   265  	if user != "" {
   266  		return s.ListByUser(ctx, user, &RepositoryListByUserOptions{
   267  			Type:        opts.Type,
   268  			Sort:        opts.Sort,
   269  			Direction:   opts.Direction,
   270  			ListOptions: opts.ListOptions,
   271  		})
   272  	}
   273  	return s.ListByAuthenticatedUser(ctx, &RepositoryListByAuthenticatedUserOptions{
   274  		Visibility:  opts.Visibility,
   275  		Affiliation: opts.Affiliation,
   276  		Type:        opts.Type,
   277  		Sort:        opts.Sort,
   278  		Direction:   opts.Direction,
   279  		ListOptions: opts.ListOptions,
   280  	})
   281  }
   282  
   283  // RepositoryListByUserOptions specifies the optional parameters to the
   284  // RepositoriesService.ListByUser method.
   285  type RepositoryListByUserOptions struct {
   286  	// Limit results to repositories of the specified type.
   287  	// Default: owner
   288  	// Can be one of: all, owner, member
   289  	Type string `url:"type,omitempty"`
   290  
   291  	// The property to sort the results by.
   292  	// Default: full_name
   293  	// Can be one of: created, updated, pushed, full_name
   294  	Sort string `url:"sort,omitempty"`
   295  
   296  	// The order to sort by.
   297  	// Default: asc when using full_name, otherwise desc.
   298  	// Can be one of: asc, desc
   299  	Direction string `url:"direction,omitempty"`
   300  
   301  	ListOptions
   302  }
   303  
   304  // ListByUser lists public repositories for the specified user.
   305  //
   306  // GitHub API docs: https://docs.github.com/rest/repos/repos#list-repositories-for-a-user
   307  //
   308  //meta:operation GET /users/{username}/repos
   309  func (s *RepositoriesService) ListByUser(ctx context.Context, user string, opts *RepositoryListByUserOptions) ([]*Repository, *Response, error) {
   310  	u := fmt.Sprintf("users/%v/repos", user)
   311  	u, err := addOptions(u, opts)
   312  	if err != nil {
   313  		return nil, nil, err
   314  	}
   315  
   316  	req, err := s.client.NewRequest("GET", u, nil)
   317  	if err != nil {
   318  		return nil, nil, err
   319  	}
   320  
   321  	var repos []*Repository
   322  	resp, err := s.client.Do(ctx, req, &repos)
   323  	if err != nil {
   324  		return nil, resp, err
   325  	}
   326  
   327  	return repos, resp, nil
   328  }
   329  
   330  // RepositoryListByAuthenticatedUserOptions specifies the optional parameters to the
   331  // RepositoriesService.ListByAuthenticatedUser method.
   332  type RepositoryListByAuthenticatedUserOptions struct {
   333  	// Limit results to repositories with the specified visibility.
   334  	// Default: all
   335  	// Can be one of: all, public, private
   336  	Visibility string `url:"visibility,omitempty"`
   337  
   338  	// List repos of given affiliation[s].
   339  	// Comma-separated list of values. Can include:
   340  	// * owner: Repositories that are owned by the authenticated user.
   341  	// * collaborator: Repositories that the user has been added to as a
   342  	//   collaborator.
   343  	// * organization_member: Repositories that the user has access to through
   344  	//   being a member of an organization. This includes every repository on
   345  	//   every team that the user is on.
   346  	// Default: owner,collaborator,organization_member
   347  	Affiliation string `url:"affiliation,omitempty"`
   348  
   349  	// Limit results to repositories of the specified type. Will cause a 422 error if
   350  	// used in the same request as visibility or affiliation.
   351  	// Default: all
   352  	// Can be one of: all, owner, public, private, member
   353  	Type string `url:"type,omitempty"`
   354  
   355  	// The property to sort the results by.
   356  	// Default: full_name
   357  	// Can be one of: created, updated, pushed, full_name
   358  	Sort string `url:"sort,omitempty"`
   359  
   360  	// Direction in which to sort repositories. Can be one of asc or desc.
   361  	// Default: when using full_name: asc; otherwise desc
   362  	Direction string `url:"direction,omitempty"`
   363  
   364  	ListOptions
   365  }
   366  
   367  // ListByAuthenticatedUser lists repositories for the authenticated user.
   368  //
   369  // GitHub API docs: https://docs.github.com/rest/repos/repos#list-repositories-for-the-authenticated-user
   370  //
   371  //meta:operation GET /user/repos
   372  func (s *RepositoriesService) ListByAuthenticatedUser(ctx context.Context, opts *RepositoryListByAuthenticatedUserOptions) ([]*Repository, *Response, error) {
   373  	u := "user/repos"
   374  	u, err := addOptions(u, opts)
   375  	if err != nil {
   376  		return nil, nil, err
   377  	}
   378  
   379  	req, err := s.client.NewRequest("GET", u, nil)
   380  	if err != nil {
   381  		return nil, nil, err
   382  	}
   383  
   384  	var repos []*Repository
   385  	resp, err := s.client.Do(ctx, req, &repos)
   386  	if err != nil {
   387  		return nil, resp, err
   388  	}
   389  
   390  	return repos, resp, nil
   391  }
   392  
   393  // RepositoryListByOrgOptions specifies the optional parameters to the
   394  // RepositoriesService.ListByOrg method.
   395  type RepositoryListByOrgOptions struct {
   396  	// Type of repositories to list. Possible values are: all, public, private,
   397  	// forks, sources, member. Default is "all".
   398  	Type string `url:"type,omitempty"`
   399  
   400  	// How to sort the repository list. Can be one of created, updated, pushed,
   401  	// full_name. Default is "created".
   402  	Sort string `url:"sort,omitempty"`
   403  
   404  	// Direction in which to sort repositories. Can be one of asc or desc.
   405  	// Default when using full_name: asc; otherwise desc.
   406  	Direction string `url:"direction,omitempty"`
   407  
   408  	ListOptions
   409  }
   410  
   411  // ListByOrg lists the repositories for an organization.
   412  //
   413  // GitHub API docs: https://docs.github.com/rest/repos/repos#list-organization-repositories
   414  //
   415  //meta:operation GET /orgs/{org}/repos
   416  func (s *RepositoriesService) ListByOrg(ctx context.Context, org string, opts *RepositoryListByOrgOptions) ([]*Repository, *Response, error) {
   417  	u := fmt.Sprintf("orgs/%v/repos", org)
   418  	u, err := addOptions(u, opts)
   419  	if err != nil {
   420  		return nil, nil, err
   421  	}
   422  
   423  	req, err := s.client.NewRequest("GET", u, nil)
   424  	if err != nil {
   425  		return nil, nil, err
   426  	}
   427  
   428  	// TODO: remove custom Accept headers when APIs fully launch.
   429  	acceptHeaders := []string{mediaTypeTopicsPreview, mediaTypeRepositoryVisibilityPreview}
   430  	req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
   431  
   432  	var repos []*Repository
   433  	resp, err := s.client.Do(ctx, req, &repos)
   434  	if err != nil {
   435  		return nil, resp, err
   436  	}
   437  
   438  	return repos, resp, nil
   439  }
   440  
   441  // RepositoryListAllOptions specifies the optional parameters to the
   442  // RepositoriesService.ListAll method.
   443  type RepositoryListAllOptions struct {
   444  	// ID of the last repository seen
   445  	Since int64 `url:"since,omitempty"`
   446  }
   447  
   448  // ListAll lists all GitHub repositories in the order that they were created.
   449  //
   450  // GitHub API docs: https://docs.github.com/rest/repos/repos#list-public-repositories
   451  //
   452  //meta:operation GET /repositories
   453  func (s *RepositoriesService) ListAll(ctx context.Context, opts *RepositoryListAllOptions) ([]*Repository, *Response, error) {
   454  	u, err := addOptions("repositories", opts)
   455  	if err != nil {
   456  		return nil, nil, err
   457  	}
   458  
   459  	req, err := s.client.NewRequest("GET", u, nil)
   460  	if err != nil {
   461  		return nil, nil, err
   462  	}
   463  
   464  	var repos []*Repository
   465  	resp, err := s.client.Do(ctx, req, &repos)
   466  	if err != nil {
   467  		return nil, resp, err
   468  	}
   469  
   470  	return repos, resp, nil
   471  }
   472  
   473  // createRepoRequest is a subset of Repository and is used internally
   474  // by Create to pass only the known fields for the endpoint.
   475  //
   476  // See https://github.com/google/go-github/issues/1014 for more
   477  // information.
   478  type createRepoRequest struct {
   479  	// Name is required when creating a repo.
   480  	Name        *string `json:"name,omitempty"`
   481  	Description *string `json:"description,omitempty"`
   482  	Homepage    *string `json:"homepage,omitempty"`
   483  
   484  	Private        *bool   `json:"private,omitempty"`
   485  	Visibility     *string `json:"visibility,omitempty"`
   486  	HasIssues      *bool   `json:"has_issues,omitempty"`
   487  	HasProjects    *bool   `json:"has_projects,omitempty"`
   488  	HasWiki        *bool   `json:"has_wiki,omitempty"`
   489  	HasDiscussions *bool   `json:"has_discussions,omitempty"`
   490  	IsTemplate     *bool   `json:"is_template,omitempty"`
   491  
   492  	// Creating an organization repository. Required for non-owners.
   493  	TeamID *int64 `json:"team_id,omitempty"`
   494  
   495  	AutoInit                  *bool   `json:"auto_init,omitempty"`
   496  	GitignoreTemplate         *string `json:"gitignore_template,omitempty"`
   497  	LicenseTemplate           *string `json:"license_template,omitempty"`
   498  	AllowSquashMerge          *bool   `json:"allow_squash_merge,omitempty"`
   499  	AllowMergeCommit          *bool   `json:"allow_merge_commit,omitempty"`
   500  	AllowRebaseMerge          *bool   `json:"allow_rebase_merge,omitempty"`
   501  	AllowUpdateBranch         *bool   `json:"allow_update_branch,omitempty"`
   502  	AllowAutoMerge            *bool   `json:"allow_auto_merge,omitempty"`
   503  	AllowForking              *bool   `json:"allow_forking,omitempty"`
   504  	DeleteBranchOnMerge       *bool   `json:"delete_branch_on_merge,omitempty"`
   505  	UseSquashPRTitleAsDefault *bool   `json:"use_squash_pr_title_as_default,omitempty"`
   506  	SquashMergeCommitTitle    *string `json:"squash_merge_commit_title,omitempty"`
   507  	SquashMergeCommitMessage  *string `json:"squash_merge_commit_message,omitempty"`
   508  	MergeCommitTitle          *string `json:"merge_commit_title,omitempty"`
   509  	MergeCommitMessage        *string `json:"merge_commit_message,omitempty"`
   510  }
   511  
   512  // Create a new repository. If an organization is specified, the new
   513  // repository will be created under that org. If the empty string is
   514  // specified, it will be created for the authenticated user.
   515  //
   516  // Note that only a subset of the repo fields are used and repo must
   517  // not be nil.
   518  //
   519  // Also note that this method will return the response without actually
   520  // waiting for GitHub to finish creating the repository and letting the
   521  // changes propagate throughout its servers. You may set up a loop with
   522  // exponential back-off to verify repository's creation.
   523  //
   524  // GitHub API docs: https://docs.github.com/rest/repos/repos#create-a-repository-for-the-authenticated-user
   525  // GitHub API docs: https://docs.github.com/rest/repos/repos#create-an-organization-repository
   526  //
   527  //meta:operation POST /orgs/{org}/repos
   528  //meta:operation POST /user/repos
   529  func (s *RepositoriesService) Create(ctx context.Context, org string, repo *Repository) (*Repository, *Response, error) {
   530  	var u string
   531  	if org != "" {
   532  		u = fmt.Sprintf("orgs/%v/repos", org)
   533  	} else {
   534  		u = "user/repos"
   535  	}
   536  
   537  	repoReq := &createRepoRequest{
   538  		Name:                      repo.Name,
   539  		Description:               repo.Description,
   540  		Homepage:                  repo.Homepage,
   541  		Private:                   repo.Private,
   542  		Visibility:                repo.Visibility,
   543  		HasIssues:                 repo.HasIssues,
   544  		HasProjects:               repo.HasProjects,
   545  		HasWiki:                   repo.HasWiki,
   546  		HasDiscussions:            repo.HasDiscussions,
   547  		IsTemplate:                repo.IsTemplate,
   548  		TeamID:                    repo.TeamID,
   549  		AutoInit:                  repo.AutoInit,
   550  		GitignoreTemplate:         repo.GitignoreTemplate,
   551  		LicenseTemplate:           repo.LicenseTemplate,
   552  		AllowSquashMerge:          repo.AllowSquashMerge,
   553  		AllowMergeCommit:          repo.AllowMergeCommit,
   554  		AllowRebaseMerge:          repo.AllowRebaseMerge,
   555  		AllowUpdateBranch:         repo.AllowUpdateBranch,
   556  		AllowAutoMerge:            repo.AllowAutoMerge,
   557  		AllowForking:              repo.AllowForking,
   558  		DeleteBranchOnMerge:       repo.DeleteBranchOnMerge,
   559  		UseSquashPRTitleAsDefault: repo.UseSquashPRTitleAsDefault,
   560  		SquashMergeCommitTitle:    repo.SquashMergeCommitTitle,
   561  		SquashMergeCommitMessage:  repo.SquashMergeCommitMessage,
   562  		MergeCommitTitle:          repo.MergeCommitTitle,
   563  		MergeCommitMessage:        repo.MergeCommitMessage,
   564  	}
   565  
   566  	req, err := s.client.NewRequest("POST", u, repoReq)
   567  	if err != nil {
   568  		return nil, nil, err
   569  	}
   570  
   571  	acceptHeaders := []string{mediaTypeRepositoryTemplatePreview, mediaTypeRepositoryVisibilityPreview}
   572  	req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
   573  	r := new(Repository)
   574  	resp, err := s.client.Do(ctx, req, r)
   575  	if err != nil {
   576  		return nil, resp, err
   577  	}
   578  
   579  	return r, resp, nil
   580  }
   581  
   582  // TemplateRepoRequest represents a request to create a repository from a template.
   583  type TemplateRepoRequest struct {
   584  	// Name is required when creating a repo.
   585  	Name        *string `json:"name,omitempty"`
   586  	Owner       *string `json:"owner,omitempty"`
   587  	Description *string `json:"description,omitempty"`
   588  
   589  	IncludeAllBranches *bool `json:"include_all_branches,omitempty"`
   590  	Private            *bool `json:"private,omitempty"`
   591  }
   592  
   593  // CreateFromTemplate generates a repository from a template.
   594  //
   595  // GitHub API docs: https://docs.github.com/rest/repos/repos#create-a-repository-using-a-template
   596  //
   597  //meta:operation POST /repos/{template_owner}/{template_repo}/generate
   598  func (s *RepositoriesService) CreateFromTemplate(ctx context.Context, templateOwner, templateRepo string, templateRepoReq *TemplateRepoRequest) (*Repository, *Response, error) {
   599  	u := fmt.Sprintf("repos/%v/%v/generate", templateOwner, templateRepo)
   600  
   601  	req, err := s.client.NewRequest("POST", u, templateRepoReq)
   602  	if err != nil {
   603  		return nil, nil, err
   604  	}
   605  
   606  	req.Header.Set("Accept", mediaTypeRepositoryTemplatePreview)
   607  	r := new(Repository)
   608  	resp, err := s.client.Do(ctx, req, r)
   609  	if err != nil {
   610  		return nil, resp, err
   611  	}
   612  
   613  	return r, resp, nil
   614  }
   615  
   616  // Get fetches a repository.
   617  //
   618  // GitHub API docs: https://docs.github.com/rest/repos/repos#get-a-repository
   619  //
   620  //meta:operation GET /repos/{owner}/{repo}
   621  func (s *RepositoriesService) Get(ctx context.Context, owner, repo string) (*Repository, *Response, error) {
   622  	u := fmt.Sprintf("repos/%v/%v", owner, repo)
   623  	req, err := s.client.NewRequest("GET", u, nil)
   624  	if err != nil {
   625  		return nil, nil, err
   626  	}
   627  
   628  	// TODO: remove custom Accept header when the license support fully launches
   629  	// https://docs.github.com/rest/licenses/#get-a-repositorys-license
   630  	acceptHeaders := []string{
   631  		mediaTypeCodesOfConductPreview,
   632  		mediaTypeTopicsPreview,
   633  		mediaTypeRepositoryTemplatePreview,
   634  		mediaTypeRepositoryVisibilityPreview,
   635  	}
   636  	req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
   637  
   638  	repository := new(Repository)
   639  	resp, err := s.client.Do(ctx, req, repository)
   640  	if err != nil {
   641  		return nil, resp, err
   642  	}
   643  
   644  	return repository, resp, nil
   645  }
   646  
   647  // GetCodeOfConduct gets the contents of a repository's code of conduct.
   648  // Note that https://docs.github.com/rest/codes-of-conduct#about-the-codes-of-conduct-api
   649  // says to use the GET /repos/{owner}/{repo} endpoint.
   650  //
   651  // GitHub API docs: https://docs.github.com/rest/repos/repos#get-a-repository
   652  //
   653  //meta:operation GET /repos/{owner}/{repo}
   654  func (s *RepositoriesService) GetCodeOfConduct(ctx context.Context, owner, repo string) (*CodeOfConduct, *Response, error) {
   655  	u := fmt.Sprintf("repos/%v/%v", owner, repo)
   656  	req, err := s.client.NewRequest("GET", u, nil)
   657  	if err != nil {
   658  		return nil, nil, err
   659  	}
   660  
   661  	// TODO: remove custom Accept header when this API fully launches.
   662  	req.Header.Set("Accept", mediaTypeCodesOfConductPreview)
   663  
   664  	r := new(Repository)
   665  	resp, err := s.client.Do(ctx, req, r)
   666  	if err != nil {
   667  		return nil, resp, err
   668  	}
   669  
   670  	return r.GetCodeOfConduct(), resp, nil
   671  }
   672  
   673  // GetByID fetches a repository.
   674  //
   675  // Note: GetByID uses the undocumented GitHub API endpoint "GET /repositories/{repository_id}".
   676  //
   677  //meta:operation GET /repositories/{repository_id}
   678  func (s *RepositoriesService) GetByID(ctx context.Context, id int64) (*Repository, *Response, error) {
   679  	u := fmt.Sprintf("repositories/%d", id)
   680  	req, err := s.client.NewRequest("GET", u, nil)
   681  	if err != nil {
   682  		return nil, nil, err
   683  	}
   684  
   685  	repository := new(Repository)
   686  	resp, err := s.client.Do(ctx, req, repository)
   687  	if err != nil {
   688  		return nil, resp, err
   689  	}
   690  
   691  	return repository, resp, nil
   692  }
   693  
   694  // Edit updates a repository.
   695  //
   696  // GitHub API docs: https://docs.github.com/rest/repos/repos#update-a-repository
   697  //
   698  //meta:operation PATCH /repos/{owner}/{repo}
   699  func (s *RepositoriesService) Edit(ctx context.Context, owner, repo string, repository *Repository) (*Repository, *Response, error) {
   700  	u := fmt.Sprintf("repos/%v/%v", owner, repo)
   701  	req, err := s.client.NewRequest("PATCH", u, repository)
   702  	if err != nil {
   703  		return nil, nil, err
   704  	}
   705  
   706  	acceptHeaders := []string{mediaTypeRepositoryTemplatePreview, mediaTypeRepositoryVisibilityPreview}
   707  	req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
   708  	r := new(Repository)
   709  	resp, err := s.client.Do(ctx, req, r)
   710  	if err != nil {
   711  		return nil, resp, err
   712  	}
   713  
   714  	return r, resp, nil
   715  }
   716  
   717  // Delete a repository.
   718  //
   719  // GitHub API docs: https://docs.github.com/rest/repos/repos#delete-a-repository
   720  //
   721  //meta:operation DELETE /repos/{owner}/{repo}
   722  func (s *RepositoriesService) Delete(ctx context.Context, owner, repo string) (*Response, error) {
   723  	u := fmt.Sprintf("repos/%v/%v", owner, repo)
   724  	req, err := s.client.NewRequest("DELETE", u, nil)
   725  	if err != nil {
   726  		return nil, err
   727  	}
   728  
   729  	return s.client.Do(ctx, req, nil)
   730  }
   731  
   732  // Contributor represents a repository contributor
   733  type Contributor struct {
   734  	Login             *string `json:"login,omitempty"`
   735  	ID                *int64  `json:"id,omitempty"`
   736  	NodeID            *string `json:"node_id,omitempty"`
   737  	AvatarURL         *string `json:"avatar_url,omitempty"`
   738  	GravatarID        *string `json:"gravatar_id,omitempty"`
   739  	URL               *string `json:"url,omitempty"`
   740  	HTMLURL           *string `json:"html_url,omitempty"`
   741  	FollowersURL      *string `json:"followers_url,omitempty"`
   742  	FollowingURL      *string `json:"following_url,omitempty"`
   743  	GistsURL          *string `json:"gists_url,omitempty"`
   744  	StarredURL        *string `json:"starred_url,omitempty"`
   745  	SubscriptionsURL  *string `json:"subscriptions_url,omitempty"`
   746  	OrganizationsURL  *string `json:"organizations_url,omitempty"`
   747  	ReposURL          *string `json:"repos_url,omitempty"`
   748  	EventsURL         *string `json:"events_url,omitempty"`
   749  	ReceivedEventsURL *string `json:"received_events_url,omitempty"`
   750  	Type              *string `json:"type,omitempty"`
   751  	SiteAdmin         *bool   `json:"site_admin,omitempty"`
   752  	Contributions     *int    `json:"contributions,omitempty"`
   753  	Name              *string `json:"name,omitempty"`
   754  	Email             *string `json:"email,omitempty"`
   755  }
   756  
   757  // ListContributorsOptions specifies the optional parameters to the
   758  // RepositoriesService.ListContributors method.
   759  type ListContributorsOptions struct {
   760  	// Include anonymous contributors in results or not
   761  	Anon string `url:"anon,omitempty"`
   762  
   763  	ListOptions
   764  }
   765  
   766  // GetVulnerabilityAlerts checks if vulnerability alerts are enabled for a repository.
   767  //
   768  // GitHub API docs: https://docs.github.com/rest/repos/repos#check-if-vulnerability-alerts-are-enabled-for-a-repository
   769  //
   770  //meta:operation GET /repos/{owner}/{repo}/vulnerability-alerts
   771  func (s *RepositoriesService) GetVulnerabilityAlerts(ctx context.Context, owner, repository string) (bool, *Response, error) {
   772  	u := fmt.Sprintf("repos/%v/%v/vulnerability-alerts", owner, repository)
   773  
   774  	req, err := s.client.NewRequest("GET", u, nil)
   775  	if err != nil {
   776  		return false, nil, err
   777  	}
   778  
   779  	// TODO: remove custom Accept header when this API fully launches
   780  	req.Header.Set("Accept", mediaTypeRequiredVulnerabilityAlertsPreview)
   781  
   782  	resp, err := s.client.Do(ctx, req, nil)
   783  	vulnerabilityAlertsEnabled, err := parseBoolResponse(err)
   784  	return vulnerabilityAlertsEnabled, resp, err
   785  }
   786  
   787  // EnableVulnerabilityAlerts enables vulnerability alerts and the dependency graph for a repository.
   788  //
   789  // GitHub API docs: https://docs.github.com/rest/repos/repos#enable-vulnerability-alerts
   790  //
   791  //meta:operation PUT /repos/{owner}/{repo}/vulnerability-alerts
   792  func (s *RepositoriesService) EnableVulnerabilityAlerts(ctx context.Context, owner, repository string) (*Response, error) {
   793  	u := fmt.Sprintf("repos/%v/%v/vulnerability-alerts", owner, repository)
   794  
   795  	req, err := s.client.NewRequest("PUT", u, nil)
   796  	if err != nil {
   797  		return nil, err
   798  	}
   799  
   800  	// TODO: remove custom Accept header when this API fully launches
   801  	req.Header.Set("Accept", mediaTypeRequiredVulnerabilityAlertsPreview)
   802  
   803  	return s.client.Do(ctx, req, nil)
   804  }
   805  
   806  // DisableVulnerabilityAlerts disables vulnerability alerts and the dependency graph for a repository.
   807  //
   808  // GitHub API docs: https://docs.github.com/rest/repos/repos#disable-vulnerability-alerts
   809  //
   810  //meta:operation DELETE /repos/{owner}/{repo}/vulnerability-alerts
   811  func (s *RepositoriesService) DisableVulnerabilityAlerts(ctx context.Context, owner, repository string) (*Response, error) {
   812  	u := fmt.Sprintf("repos/%v/%v/vulnerability-alerts", owner, repository)
   813  
   814  	req, err := s.client.NewRequest("DELETE", u, nil)
   815  	if err != nil {
   816  		return nil, err
   817  	}
   818  
   819  	// TODO: remove custom Accept header when this API fully launches
   820  	req.Header.Set("Accept", mediaTypeRequiredVulnerabilityAlertsPreview)
   821  
   822  	return s.client.Do(ctx, req, nil)
   823  }
   824  
   825  // GetAutomatedSecurityFixes checks if the automated security fixes for a repository are enabled.
   826  //
   827  // GitHub API docs: https://docs.github.com/rest/repos/repos#check-if-automated-security-fixes-are-enabled-for-a-repository
   828  //
   829  //meta:operation GET /repos/{owner}/{repo}/automated-security-fixes
   830  func (s *RepositoriesService) GetAutomatedSecurityFixes(ctx context.Context, owner, repository string) (*AutomatedSecurityFixes, *Response, error) {
   831  	u := fmt.Sprintf("repos/%v/%v/automated-security-fixes", owner, repository)
   832  
   833  	req, err := s.client.NewRequest("GET", u, nil)
   834  	if err != nil {
   835  		return nil, nil, err
   836  	}
   837  
   838  	p := new(AutomatedSecurityFixes)
   839  	resp, err := s.client.Do(ctx, req, p)
   840  	if err != nil {
   841  		return nil, resp, err
   842  	}
   843  	return p, resp, nil
   844  }
   845  
   846  // EnableAutomatedSecurityFixes enables the automated security fixes for a repository.
   847  //
   848  // GitHub API docs: https://docs.github.com/rest/repos/repos#enable-automated-security-fixes
   849  //
   850  //meta:operation PUT /repos/{owner}/{repo}/automated-security-fixes
   851  func (s *RepositoriesService) EnableAutomatedSecurityFixes(ctx context.Context, owner, repository string) (*Response, error) {
   852  	u := fmt.Sprintf("repos/%v/%v/automated-security-fixes", owner, repository)
   853  
   854  	req, err := s.client.NewRequest("PUT", u, nil)
   855  	if err != nil {
   856  		return nil, err
   857  	}
   858  
   859  	return s.client.Do(ctx, req, nil)
   860  }
   861  
   862  // DisableAutomatedSecurityFixes disables vulnerability alerts and the dependency graph for a repository.
   863  //
   864  // GitHub API docs: https://docs.github.com/rest/repos/repos#disable-automated-security-fixes
   865  //
   866  //meta:operation DELETE /repos/{owner}/{repo}/automated-security-fixes
   867  func (s *RepositoriesService) DisableAutomatedSecurityFixes(ctx context.Context, owner, repository string) (*Response, error) {
   868  	u := fmt.Sprintf("repos/%v/%v/automated-security-fixes", owner, repository)
   869  
   870  	req, err := s.client.NewRequest("DELETE", u, nil)
   871  	if err != nil {
   872  		return nil, err
   873  	}
   874  
   875  	return s.client.Do(ctx, req, nil)
   876  }
   877  
   878  // ListContributors lists contributors for a repository.
   879  //
   880  // GitHub API docs: https://docs.github.com/rest/repos/repos#list-repository-contributors
   881  //
   882  //meta:operation GET /repos/{owner}/{repo}/contributors
   883  func (s *RepositoriesService) ListContributors(ctx context.Context, owner string, repository string, opts *ListContributorsOptions) ([]*Contributor, *Response, error) {
   884  	u := fmt.Sprintf("repos/%v/%v/contributors", owner, repository)
   885  	u, err := addOptions(u, opts)
   886  	if err != nil {
   887  		return nil, nil, err
   888  	}
   889  
   890  	req, err := s.client.NewRequest("GET", u, nil)
   891  	if err != nil {
   892  		return nil, nil, err
   893  	}
   894  
   895  	var contributor []*Contributor
   896  	resp, err := s.client.Do(ctx, req, &contributor)
   897  	if err != nil {
   898  		return nil, resp, err
   899  	}
   900  
   901  	return contributor, resp, nil
   902  }
   903  
   904  // ListLanguages lists languages for the specified repository. The returned map
   905  // specifies the languages and the number of bytes of code written in that
   906  // language. For example:
   907  //
   908  //	{
   909  //	  "C": 78769,
   910  //	  "Python": 7769
   911  //	}
   912  //
   913  // GitHub API docs: https://docs.github.com/rest/repos/repos#list-repository-languages
   914  //
   915  //meta:operation GET /repos/{owner}/{repo}/languages
   916  func (s *RepositoriesService) ListLanguages(ctx context.Context, owner string, repo string) (map[string]int, *Response, error) {
   917  	u := fmt.Sprintf("repos/%v/%v/languages", owner, repo)
   918  	req, err := s.client.NewRequest("GET", u, nil)
   919  	if err != nil {
   920  		return nil, nil, err
   921  	}
   922  
   923  	languages := make(map[string]int)
   924  	resp, err := s.client.Do(ctx, req, &languages)
   925  	if err != nil {
   926  		return nil, resp, err
   927  	}
   928  
   929  	return languages, resp, nil
   930  }
   931  
   932  // ListTeams lists the teams for the specified repository.
   933  //
   934  // GitHub API docs: https://docs.github.com/rest/repos/repos#list-repository-teams
   935  //
   936  //meta:operation GET /repos/{owner}/{repo}/teams
   937  func (s *RepositoriesService) ListTeams(ctx context.Context, owner string, repo string, opts *ListOptions) ([]*Team, *Response, error) {
   938  	u := fmt.Sprintf("repos/%v/%v/teams", owner, repo)
   939  	u, err := addOptions(u, opts)
   940  	if err != nil {
   941  		return nil, nil, err
   942  	}
   943  
   944  	req, err := s.client.NewRequest("GET", u, nil)
   945  	if err != nil {
   946  		return nil, nil, err
   947  	}
   948  
   949  	var teams []*Team
   950  	resp, err := s.client.Do(ctx, req, &teams)
   951  	if err != nil {
   952  		return nil, resp, err
   953  	}
   954  
   955  	return teams, resp, nil
   956  }
   957  
   958  // RepositoryTag represents a repository tag.
   959  type RepositoryTag struct {
   960  	Name       *string `json:"name,omitempty"`
   961  	Commit     *Commit `json:"commit,omitempty"`
   962  	ZipballURL *string `json:"zipball_url,omitempty"`
   963  	TarballURL *string `json:"tarball_url,omitempty"`
   964  }
   965  
   966  // ListTags lists tags for the specified repository.
   967  //
   968  // GitHub API docs: https://docs.github.com/rest/repos/repos#list-repository-tags
   969  //
   970  //meta:operation GET /repos/{owner}/{repo}/tags
   971  func (s *RepositoriesService) ListTags(ctx context.Context, owner string, repo string, opts *ListOptions) ([]*RepositoryTag, *Response, error) {
   972  	u := fmt.Sprintf("repos/%v/%v/tags", owner, repo)
   973  	u, err := addOptions(u, opts)
   974  	if err != nil {
   975  		return nil, nil, err
   976  	}
   977  
   978  	req, err := s.client.NewRequest("GET", u, nil)
   979  	if err != nil {
   980  		return nil, nil, err
   981  	}
   982  
   983  	var tags []*RepositoryTag
   984  	resp, err := s.client.Do(ctx, req, &tags)
   985  	if err != nil {
   986  		return nil, resp, err
   987  	}
   988  
   989  	return tags, resp, nil
   990  }
   991  
   992  // Branch represents a repository branch
   993  type Branch struct {
   994  	Name      *string           `json:"name,omitempty"`
   995  	Commit    *RepositoryCommit `json:"commit,omitempty"`
   996  	Protected *bool             `json:"protected,omitempty"`
   997  }
   998  
   999  // Protection represents a repository branch's protection.
  1000  type Protection struct {
  1001  	RequiredStatusChecks           *RequiredStatusChecks           `json:"required_status_checks"`
  1002  	RequiredPullRequestReviews     *PullRequestReviewsEnforcement  `json:"required_pull_request_reviews"`
  1003  	EnforceAdmins                  *AdminEnforcement               `json:"enforce_admins"`
  1004  	Restrictions                   *BranchRestrictions             `json:"restrictions"`
  1005  	RequireLinearHistory           *RequireLinearHistory           `json:"required_linear_history"`
  1006  	AllowForcePushes               *AllowForcePushes               `json:"allow_force_pushes"`
  1007  	AllowDeletions                 *AllowDeletions                 `json:"allow_deletions"`
  1008  	RequiredConversationResolution *RequiredConversationResolution `json:"required_conversation_resolution"`
  1009  	BlockCreations                 *BlockCreations                 `json:"block_creations,omitempty"`
  1010  	LockBranch                     *LockBranch                     `json:"lock_branch,omitempty"`
  1011  	AllowForkSyncing               *AllowForkSyncing               `json:"allow_fork_syncing,omitempty"`
  1012  	RequiredSignatures             *SignaturesProtectedBranch      `json:"required_signatures,omitempty"`
  1013  	URL                            *string                         `json:"url,omitempty"`
  1014  }
  1015  
  1016  // BlockCreations represents whether users can push changes that create branches. If this is true, this
  1017  // setting blocks pushes that create new branches, unless the push is initiated by a user, team, or app
  1018  // which has the ability to push.
  1019  type BlockCreations struct {
  1020  	Enabled *bool `json:"enabled,omitempty"`
  1021  }
  1022  
  1023  // LockBranch represents if the branch is marked as read-only. If this is true, users will not be able to push to the branch.
  1024  type LockBranch struct {
  1025  	Enabled *bool `json:"enabled,omitempty"`
  1026  }
  1027  
  1028  // AllowForkSyncing represents whether users can pull changes from upstream when the branch is locked.
  1029  type AllowForkSyncing struct {
  1030  	Enabled *bool `json:"enabled,omitempty"`
  1031  }
  1032  
  1033  // BranchProtectionRule represents the rule applied to a repositories branch.
  1034  type BranchProtectionRule struct {
  1035  	ID                                       *int64     `json:"id,omitempty"`
  1036  	RepositoryID                             *int64     `json:"repository_id,omitempty"`
  1037  	Name                                     *string    `json:"name,omitempty"`
  1038  	CreatedAt                                *Timestamp `json:"created_at,omitempty"`
  1039  	UpdatedAt                                *Timestamp `json:"updated_at,omitempty"`
  1040  	PullRequestReviewsEnforcementLevel       *string    `json:"pull_request_reviews_enforcement_level,omitempty"`
  1041  	RequiredApprovingReviewCount             *int       `json:"required_approving_review_count,omitempty"`
  1042  	DismissStaleReviewsOnPush                *bool      `json:"dismiss_stale_reviews_on_push,omitempty"`
  1043  	AuthorizedDismissalActorsOnly            *bool      `json:"authorized_dismissal_actors_only,omitempty"`
  1044  	IgnoreApprovalsFromContributors          *bool      `json:"ignore_approvals_from_contributors,omitempty"`
  1045  	RequireCodeOwnerReview                   *bool      `json:"require_code_owner_review,omitempty"`
  1046  	RequiredStatusChecks                     []string   `json:"required_status_checks,omitempty"`
  1047  	RequiredStatusChecksEnforcementLevel     *string    `json:"required_status_checks_enforcement_level,omitempty"`
  1048  	StrictRequiredStatusChecksPolicy         *bool      `json:"strict_required_status_checks_policy,omitempty"`
  1049  	SignatureRequirementEnforcementLevel     *string    `json:"signature_requirement_enforcement_level,omitempty"`
  1050  	LinearHistoryRequirementEnforcementLevel *string    `json:"linear_history_requirement_enforcement_level,omitempty"`
  1051  	AdminEnforced                            *bool      `json:"admin_enforced,omitempty"`
  1052  	AllowForcePushesEnforcementLevel         *string    `json:"allow_force_pushes_enforcement_level,omitempty"`
  1053  	AllowDeletionsEnforcementLevel           *string    `json:"allow_deletions_enforcement_level,omitempty"`
  1054  	MergeQueueEnforcementLevel               *string    `json:"merge_queue_enforcement_level,omitempty"`
  1055  	RequiredDeploymentsEnforcementLevel      *string    `json:"required_deployments_enforcement_level,omitempty"`
  1056  	RequiredConversationResolutionLevel      *string    `json:"required_conversation_resolution_level,omitempty"`
  1057  	AuthorizedActorsOnly                     *bool      `json:"authorized_actors_only,omitempty"`
  1058  	AuthorizedActorNames                     []string   `json:"authorized_actor_names,omitempty"`
  1059  }
  1060  
  1061  // ProtectionChanges represents the changes to the rule if the BranchProtection was edited.
  1062  type ProtectionChanges struct {
  1063  	AdminEnforced                            *AdminEnforcedChanges                            `json:"admin_enforced,omitempty"`
  1064  	AllowDeletionsEnforcementLevel           *AllowDeletionsEnforcementLevelChanges           `json:"allow_deletions_enforcement_level,omitempty"`
  1065  	AuthorizedActorNames                     *AuthorizedActorNames                            `json:"authorized_actor_names,omitempty"`
  1066  	AuthorizedActorsOnly                     *AuthorizedActorsOnly                            `json:"authorized_actors_only,omitempty"`
  1067  	AuthorizedDismissalActorsOnly            *AuthorizedDismissalActorsOnlyChanges            `json:"authorized_dismissal_actors_only,omitempty"`
  1068  	CreateProtected                          *CreateProtectedChanges                          `json:"create_protected,omitempty"`
  1069  	DismissStaleReviewsOnPush                *DismissStaleReviewsOnPushChanges                `json:"dismiss_stale_reviews_on_push,omitempty"`
  1070  	LinearHistoryRequirementEnforcementLevel *LinearHistoryRequirementEnforcementLevelChanges `json:"linear_history_requirement_enforcement_level,omitempty"`
  1071  	PullRequestReviewsEnforcementLevel       *PullRequestReviewsEnforcementLevelChanges       `json:"pull_request_reviews_enforcement_level,omitempty"`
  1072  	RequireCodeOwnerReview                   *RequireCodeOwnerReviewChanges                   `json:"require_code_owner_review,omitempty"`
  1073  	RequiredConversationResolutionLevel      *RequiredConversationResolutionLevelChanges      `json:"required_conversation_resolution_level,omitempty"`
  1074  	RequiredDeploymentsEnforcementLevel      *RequiredDeploymentsEnforcementLevelChanges      `json:"required_deployments_enforcement_level,omitempty"`
  1075  	RequiredStatusChecks                     *RequiredStatusChecksChanges                     `json:"required_status_checks,omitempty"`
  1076  	RequiredStatusChecksEnforcementLevel     *RequiredStatusChecksEnforcementLevelChanges     `json:"required_status_checks_enforcement_level,omitempty"`
  1077  	SignatureRequirementEnforcementLevel     *SignatureRequirementEnforcementLevelChanges     `json:"signature_requirement_enforcement_level,omitempty"`
  1078  }
  1079  
  1080  // AdminEnforcedChanges represents the changes made to the AdminEnforced policy.
  1081  type AdminEnforcedChanges struct {
  1082  	From *bool `json:"from,omitempty"`
  1083  }
  1084  
  1085  // AllowDeletionsEnforcementLevelChanges represents the changes made to the AllowDeletionsEnforcementLevel policy.
  1086  type AllowDeletionsEnforcementLevelChanges struct {
  1087  	From *string `json:"from,omitempty"`
  1088  }
  1089  
  1090  // AuthorizedActorNames represents who are authorized to edit the branch protection rules.
  1091  type AuthorizedActorNames struct {
  1092  	From []string `json:"from,omitempty"`
  1093  }
  1094  
  1095  // AuthorizedActorsOnly represents if the branch rule can be edited by authorized actors only.
  1096  type AuthorizedActorsOnly struct {
  1097  	From *bool `json:"from,omitempty"`
  1098  }
  1099  
  1100  // AuthorizedDismissalActorsOnlyChanges represents the changes made to the AuthorizedDismissalActorsOnly policy.
  1101  type AuthorizedDismissalActorsOnlyChanges struct {
  1102  	From *bool `json:"from,omitempty"`
  1103  }
  1104  
  1105  // CreateProtectedChanges represents the changes made to the CreateProtected policy.
  1106  type CreateProtectedChanges struct {
  1107  	From *bool `json:"from,omitempty"`
  1108  }
  1109  
  1110  // DismissStaleReviewsOnPushChanges represents the changes made to the DismissStaleReviewsOnPushChanges policy.
  1111  type DismissStaleReviewsOnPushChanges struct {
  1112  	From *bool `json:"from,omitempty"`
  1113  }
  1114  
  1115  // LinearHistoryRequirementEnforcementLevelChanges represents the changes made to the LinearHistoryRequirementEnforcementLevel policy.
  1116  type LinearHistoryRequirementEnforcementLevelChanges struct {
  1117  	From *string `json:"from,omitempty"`
  1118  }
  1119  
  1120  // PullRequestReviewsEnforcementLevelChanges represents the changes made to the PullRequestReviewsEnforcementLevel policy.
  1121  type PullRequestReviewsEnforcementLevelChanges struct {
  1122  	From *string `json:"from,omitempty"`
  1123  }
  1124  
  1125  // RequireCodeOwnerReviewChanges represents the changes made to the RequireCodeOwnerReview policy.
  1126  type RequireCodeOwnerReviewChanges struct {
  1127  	From *bool `json:"from,omitempty"`
  1128  }
  1129  
  1130  // RequiredConversationResolutionLevelChanges represents the changes made to the RequiredConversationResolutionLevel policy.
  1131  type RequiredConversationResolutionLevelChanges struct {
  1132  	From *string `json:"from,omitempty"`
  1133  }
  1134  
  1135  // RequiredDeploymentsEnforcementLevelChanges represents the changes made to the RequiredDeploymentsEnforcementLevel policy.
  1136  type RequiredDeploymentsEnforcementLevelChanges struct {
  1137  	From *string `json:"from,omitempty"`
  1138  }
  1139  
  1140  // RequiredStatusChecksChanges represents the changes made to the RequiredStatusChecks policy.
  1141  type RequiredStatusChecksChanges struct {
  1142  	From []string `json:"from,omitempty"`
  1143  }
  1144  
  1145  // RequiredStatusChecksEnforcementLevelChanges represents the changes made to the RequiredStatusChecksEnforcementLevel policy.
  1146  type RequiredStatusChecksEnforcementLevelChanges struct {
  1147  	From *string `json:"from,omitempty"`
  1148  }
  1149  
  1150  // SignatureRequirementEnforcementLevelChanges represents the changes made to the SignatureRequirementEnforcementLevel policy.
  1151  type SignatureRequirementEnforcementLevelChanges struct {
  1152  	From *string `json:"from,omitempty"`
  1153  }
  1154  
  1155  // ProtectionRequest represents a request to create/edit a branch's protection.
  1156  type ProtectionRequest struct {
  1157  	RequiredStatusChecks       *RequiredStatusChecks                 `json:"required_status_checks"`
  1158  	RequiredPullRequestReviews *PullRequestReviewsEnforcementRequest `json:"required_pull_request_reviews"`
  1159  	EnforceAdmins              bool                                  `json:"enforce_admins"`
  1160  	Restrictions               *BranchRestrictionsRequest            `json:"restrictions"`
  1161  	// Enforces a linear commit Git history, which prevents anyone from pushing merge commits to a branch.
  1162  	RequireLinearHistory *bool `json:"required_linear_history,omitempty"`
  1163  	// Permits force pushes to the protected branch by anyone with write access to the repository.
  1164  	AllowForcePushes *bool `json:"allow_force_pushes,omitempty"`
  1165  	// Allows deletion of the protected branch by anyone with write access to the repository.
  1166  	AllowDeletions *bool `json:"allow_deletions,omitempty"`
  1167  	// RequiredConversationResolution, if set to true, requires all comments
  1168  	// on the pull request to be resolved before it can be merged to a protected branch.
  1169  	RequiredConversationResolution *bool `json:"required_conversation_resolution,omitempty"`
  1170  	// BlockCreations, if set to true, will cause the restrictions setting to also block pushes
  1171  	// which create new branches, unless initiated by a user, team, app with the ability to push.
  1172  	BlockCreations *bool `json:"block_creations,omitempty"`
  1173  	// LockBranch, if set to true, will prevent users from pushing to the branch.
  1174  	LockBranch *bool `json:"lock_branch,omitempty"`
  1175  	// AllowForkSyncing, if set to true, will allow users to pull changes from upstream
  1176  	// when the branch is locked.
  1177  	AllowForkSyncing *bool `json:"allow_fork_syncing,omitempty"`
  1178  }
  1179  
  1180  // RequiredStatusChecks represents the protection status of a individual branch.
  1181  type RequiredStatusChecks struct {
  1182  	// Require branches to be up to date before merging. (Required.)
  1183  	Strict bool `json:"strict"`
  1184  	// The list of status checks to require in order to merge into this
  1185  	// branch. (Deprecated. Note: only one of Contexts/Checks can be populated,
  1186  	// but at least one must be populated).
  1187  	Contexts []string `json:"contexts,omitempty"`
  1188  	// The list of status checks to require in order to merge into this
  1189  	// branch.
  1190  	Checks      []*RequiredStatusCheck `json:"checks,omitempty"`
  1191  	ContextsURL *string                `json:"contexts_url,omitempty"`
  1192  	URL         *string                `json:"url,omitempty"`
  1193  }
  1194  
  1195  // RequiredStatusChecksRequest represents a request to edit a protected branch's status checks.
  1196  type RequiredStatusChecksRequest struct {
  1197  	Strict *bool `json:"strict,omitempty"`
  1198  	// Note: if both Contexts and Checks are populated,
  1199  	// the GitHub API will only use Checks.
  1200  	Contexts []string               `json:"contexts,omitempty"`
  1201  	Checks   []*RequiredStatusCheck `json:"checks,omitempty"`
  1202  }
  1203  
  1204  // RequiredStatusCheck represents a status check of a protected branch.
  1205  type RequiredStatusCheck struct {
  1206  	// The name of the required check.
  1207  	Context string `json:"context"`
  1208  	// The ID of the GitHub App that must provide this check.
  1209  	// Omit this field to automatically select the GitHub App
  1210  	// that has recently provided this check,
  1211  	// or any app if it was not set by a GitHub App.
  1212  	// Pass -1 to explicitly allow any app to set the status.
  1213  	AppID *int64 `json:"app_id,omitempty"`
  1214  }
  1215  
  1216  // PullRequestReviewsEnforcement represents the pull request reviews enforcement of a protected branch.
  1217  type PullRequestReviewsEnforcement struct {
  1218  	// Allow specific users, teams, or apps to bypass pull request requirements.
  1219  	BypassPullRequestAllowances *BypassPullRequestAllowances `json:"bypass_pull_request_allowances,omitempty"`
  1220  	// Specifies which users, teams and apps can dismiss pull request reviews.
  1221  	DismissalRestrictions *DismissalRestrictions `json:"dismissal_restrictions,omitempty"`
  1222  	// Specifies if approved reviews are dismissed automatically, when a new commit is pushed.
  1223  	DismissStaleReviews bool `json:"dismiss_stale_reviews"`
  1224  	// RequireCodeOwnerReviews specifies if an approved review is required in pull requests including files with a designated code owner.
  1225  	RequireCodeOwnerReviews bool `json:"require_code_owner_reviews"`
  1226  	// RequiredApprovingReviewCount specifies the number of approvals required before the pull request can be merged.
  1227  	// Valid values are 1-6.
  1228  	RequiredApprovingReviewCount int `json:"required_approving_review_count"`
  1229  	// RequireLastPushApproval specifies whether the last pusher to a pull request branch can approve it.
  1230  	RequireLastPushApproval bool `json:"require_last_push_approval"`
  1231  }
  1232  
  1233  // PullRequestReviewsEnforcementRequest represents request to set the pull request review
  1234  // enforcement of a protected branch. It is separate from PullRequestReviewsEnforcement above
  1235  // because the request structure is different from the response structure.
  1236  type PullRequestReviewsEnforcementRequest struct {
  1237  	// Allow specific users, teams, or apps to bypass pull request requirements.
  1238  	BypassPullRequestAllowancesRequest *BypassPullRequestAllowancesRequest `json:"bypass_pull_request_allowances,omitempty"`
  1239  	// Specifies which users, teams and apps should be allowed to dismiss pull request reviews.
  1240  	// User, team and app dismissal restrictions are only available for
  1241  	// organization-owned repositories. Must be nil for personal repositories.
  1242  	DismissalRestrictionsRequest *DismissalRestrictionsRequest `json:"dismissal_restrictions,omitempty"`
  1243  	// Specifies if approved reviews can be dismissed automatically, when a new commit is pushed. (Required)
  1244  	DismissStaleReviews bool `json:"dismiss_stale_reviews"`
  1245  	// RequireCodeOwnerReviews specifies if an approved review is required in pull requests including files with a designated code owner.
  1246  	RequireCodeOwnerReviews bool `json:"require_code_owner_reviews"`
  1247  	// RequiredApprovingReviewCount specifies the number of approvals required before the pull request can be merged.
  1248  	// Valid values are 1-6.
  1249  	RequiredApprovingReviewCount int `json:"required_approving_review_count"`
  1250  	// RequireLastPushApproval specifies whether the last pusher to a pull request branch can approve it.
  1251  	RequireLastPushApproval *bool `json:"require_last_push_approval,omitempty"`
  1252  }
  1253  
  1254  // PullRequestReviewsEnforcementUpdate represents request to patch the pull request review
  1255  // enforcement of a protected branch. It is separate from PullRequestReviewsEnforcementRequest above
  1256  // because the patch request does not require all fields to be initialized.
  1257  type PullRequestReviewsEnforcementUpdate struct {
  1258  	// Allow specific users, teams, or apps to bypass pull request requirements.
  1259  	BypassPullRequestAllowancesRequest *BypassPullRequestAllowancesRequest `json:"bypass_pull_request_allowances,omitempty"`
  1260  	// Specifies which users, teams and apps can dismiss pull request reviews. Can be omitted.
  1261  	DismissalRestrictionsRequest *DismissalRestrictionsRequest `json:"dismissal_restrictions,omitempty"`
  1262  	// Specifies if approved reviews can be dismissed automatically, when a new commit is pushed. Can be omitted.
  1263  	DismissStaleReviews *bool `json:"dismiss_stale_reviews,omitempty"`
  1264  	// RequireCodeOwnerReviews specifies if merging pull requests is blocked until code owners have reviewed.
  1265  	RequireCodeOwnerReviews *bool `json:"require_code_owner_reviews,omitempty"`
  1266  	// RequiredApprovingReviewCount specifies the number of approvals required before the pull request can be merged.
  1267  	// Valid values are 1 - 6 or 0 to not require reviewers.
  1268  	RequiredApprovingReviewCount int `json:"required_approving_review_count"`
  1269  	// RequireLastPushApproval specifies whether the last pusher to a pull request branch can approve it.
  1270  	RequireLastPushApproval *bool `json:"require_last_push_approval,omitempty"`
  1271  }
  1272  
  1273  // RequireLinearHistory represents the configuration to enforce branches with no merge commit.
  1274  type RequireLinearHistory struct {
  1275  	Enabled bool `json:"enabled"`
  1276  }
  1277  
  1278  // AllowDeletions represents the configuration to accept deletion of protected branches.
  1279  type AllowDeletions struct {
  1280  	Enabled bool `json:"enabled"`
  1281  }
  1282  
  1283  // AllowForcePushes represents the configuration to accept forced pushes on protected branches.
  1284  type AllowForcePushes struct {
  1285  	Enabled bool `json:"enabled"`
  1286  }
  1287  
  1288  // RequiredConversationResolution requires all comments on the pull request to be resolved before it can be
  1289  // merged to a protected branch when enabled.
  1290  type RequiredConversationResolution struct {
  1291  	Enabled bool `json:"enabled"`
  1292  }
  1293  
  1294  // AdminEnforcement represents the configuration to enforce required status checks for repository administrators.
  1295  type AdminEnforcement struct {
  1296  	URL     *string `json:"url,omitempty"`
  1297  	Enabled bool    `json:"enabled"`
  1298  }
  1299  
  1300  // BranchRestrictions represents the restriction that only certain users or
  1301  // teams may push to a branch.
  1302  type BranchRestrictions struct {
  1303  	// The list of user logins with push access.
  1304  	Users []*User `json:"users"`
  1305  	// The list of team slugs with push access.
  1306  	Teams []*Team `json:"teams"`
  1307  	// The list of app slugs with push access.
  1308  	Apps []*App `json:"apps"`
  1309  }
  1310  
  1311  // BranchRestrictionsRequest represents the request to create/edit the
  1312  // restriction that only certain users or teams may push to a branch. It is
  1313  // separate from BranchRestrictions above because the request structure is
  1314  // different from the response structure.
  1315  type BranchRestrictionsRequest struct {
  1316  	// The list of user logins with push access. (Required; use []string{} instead of nil for empty list.)
  1317  	Users []string `json:"users"`
  1318  	// The list of team slugs with push access. (Required; use []string{} instead of nil for empty list.)
  1319  	Teams []string `json:"teams"`
  1320  	// The list of app slugs with push access.
  1321  	Apps []string `json:"apps"`
  1322  }
  1323  
  1324  // BypassPullRequestAllowances represents the people, teams, or apps who are allowed to bypass required pull requests.
  1325  type BypassPullRequestAllowances struct {
  1326  	// The list of users allowed to bypass pull request requirements.
  1327  	Users []*User `json:"users"`
  1328  	// The list of teams allowed to bypass pull request requirements.
  1329  	Teams []*Team `json:"teams"`
  1330  	// The list of apps allowed to bypass pull request requirements.
  1331  	Apps []*App `json:"apps"`
  1332  }
  1333  
  1334  // BypassPullRequestAllowancesRequest represents the people, teams, or apps who are
  1335  // allowed to bypass required pull requests.
  1336  // It is separate from BypassPullRequestAllowances above because the request structure is
  1337  // different from the response structure.
  1338  type BypassPullRequestAllowancesRequest struct {
  1339  	// The list of user logins allowed to bypass pull request requirements.
  1340  	Users []string `json:"users"`
  1341  	// The list of team slugs allowed to bypass pull request requirements.
  1342  	Teams []string `json:"teams"`
  1343  	// The list of app slugs allowed to bypass pull request requirements.
  1344  	Apps []string `json:"apps"`
  1345  }
  1346  
  1347  // DismissalRestrictions specifies which users and teams can dismiss pull request reviews.
  1348  type DismissalRestrictions struct {
  1349  	// The list of users who can dimiss pull request reviews.
  1350  	Users []*User `json:"users"`
  1351  	// The list of teams which can dismiss pull request reviews.
  1352  	Teams []*Team `json:"teams"`
  1353  	// The list of apps which can dismiss pull request reviews.
  1354  	Apps []*App `json:"apps"`
  1355  }
  1356  
  1357  // DismissalRestrictionsRequest represents the request to create/edit the
  1358  // restriction to allows only specific users, teams or apps to dimiss pull request reviews. It is
  1359  // separate from DismissalRestrictions above because the request structure is
  1360  // different from the response structure.
  1361  // Note: Both Users and Teams must be nil, or both must be non-nil.
  1362  type DismissalRestrictionsRequest struct {
  1363  	// The list of user logins who can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.)
  1364  	Users *[]string `json:"users,omitempty"`
  1365  	// The list of team slugs which can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.)
  1366  	Teams *[]string `json:"teams,omitempty"`
  1367  	// The list of app slugs which can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.)
  1368  	Apps *[]string `json:"apps,omitempty"`
  1369  }
  1370  
  1371  // SignaturesProtectedBranch represents the protection status of an individual branch.
  1372  type SignaturesProtectedBranch struct {
  1373  	URL *string `json:"url,omitempty"`
  1374  	// Commits pushed to matching branches must have verified signatures.
  1375  	Enabled *bool `json:"enabled,omitempty"`
  1376  }
  1377  
  1378  // AutomatedSecurityFixes represents their status.
  1379  type AutomatedSecurityFixes struct {
  1380  	Enabled *bool `json:"enabled"`
  1381  	Paused  *bool `json:"paused"`
  1382  }
  1383  
  1384  // ListBranches lists branches for the specified repository.
  1385  //
  1386  // GitHub API docs: https://docs.github.com/rest/branches/branches#list-branches
  1387  //
  1388  //meta:operation GET /repos/{owner}/{repo}/branches
  1389  func (s *RepositoriesService) ListBranches(ctx context.Context, owner string, repo string, opts *BranchListOptions) ([]*Branch, *Response, error) {
  1390  	u := fmt.Sprintf("repos/%v/%v/branches", owner, repo)
  1391  	u, err := addOptions(u, opts)
  1392  	if err != nil {
  1393  		return nil, nil, err
  1394  	}
  1395  
  1396  	req, err := s.client.NewRequest("GET", u, nil)
  1397  	if err != nil {
  1398  		return nil, nil, err
  1399  	}
  1400  
  1401  	var branches []*Branch
  1402  	resp, err := s.client.Do(ctx, req, &branches)
  1403  	if err != nil {
  1404  		return nil, resp, err
  1405  	}
  1406  
  1407  	return branches, resp, nil
  1408  }
  1409  
  1410  // GetBranch gets the specified branch for a repository.
  1411  //
  1412  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1413  //
  1414  // GitHub API docs: https://docs.github.com/rest/branches/branches#get-a-branch
  1415  //
  1416  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}
  1417  func (s *RepositoriesService) GetBranch(ctx context.Context, owner, repo, branch string, maxRedirects int) (*Branch, *Response, error) {
  1418  	u := fmt.Sprintf("repos/%v/%v/branches/%v", owner, repo, url.PathEscape(branch))
  1419  
  1420  	resp, err := s.client.roundTripWithOptionalFollowRedirect(ctx, u, maxRedirects)
  1421  	if err != nil {
  1422  		return nil, nil, err
  1423  	}
  1424  	defer resp.Body.Close()
  1425  
  1426  	if resp.StatusCode != http.StatusOK {
  1427  		return nil, newResponse(resp), fmt.Errorf("unexpected status code: %s", resp.Status)
  1428  	}
  1429  
  1430  	b := new(Branch)
  1431  	err = json.NewDecoder(resp.Body).Decode(b)
  1432  	return b, newResponse(resp), err
  1433  }
  1434  
  1435  // renameBranchRequest represents a request to rename a branch.
  1436  type renameBranchRequest struct {
  1437  	NewName string `json:"new_name"`
  1438  }
  1439  
  1440  // RenameBranch renames a branch in a repository.
  1441  //
  1442  // To rename a non-default branch: Users must have push access. GitHub Apps must have the `contents:write` repository permission.
  1443  // To rename the default branch: Users must have admin or owner permissions. GitHub Apps must have the `administration:write` repository permission.
  1444  //
  1445  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1446  //
  1447  // GitHub API docs: https://docs.github.com/rest/branches/branches#rename-a-branch
  1448  //
  1449  //meta:operation POST /repos/{owner}/{repo}/branches/{branch}/rename
  1450  func (s *RepositoriesService) RenameBranch(ctx context.Context, owner, repo, branch, newName string) (*Branch, *Response, error) {
  1451  	u := fmt.Sprintf("repos/%v/%v/branches/%v/rename", owner, repo, url.PathEscape(branch))
  1452  	r := &renameBranchRequest{NewName: newName}
  1453  	req, err := s.client.NewRequest("POST", u, r)
  1454  	if err != nil {
  1455  		return nil, nil, err
  1456  	}
  1457  
  1458  	b := new(Branch)
  1459  	resp, err := s.client.Do(ctx, req, b)
  1460  	if err != nil {
  1461  		return nil, resp, err
  1462  	}
  1463  
  1464  	return b, resp, nil
  1465  }
  1466  
  1467  // GetBranchProtection gets the protection of a given branch.
  1468  //
  1469  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1470  //
  1471  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-branch-protection
  1472  //
  1473  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection
  1474  func (s *RepositoriesService) GetBranchProtection(ctx context.Context, owner, repo, branch string) (*Protection, *Response, error) {
  1475  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, url.PathEscape(branch))
  1476  	req, err := s.client.NewRequest("GET", u, nil)
  1477  	if err != nil {
  1478  		return nil, nil, err
  1479  	}
  1480  
  1481  	// TODO: remove custom Accept header when this API fully launches
  1482  	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
  1483  
  1484  	p := new(Protection)
  1485  	resp, err := s.client.Do(ctx, req, p)
  1486  	if err != nil {
  1487  		if isBranchNotProtected(err) {
  1488  			err = ErrBranchNotProtected
  1489  		}
  1490  		return nil, resp, err
  1491  	}
  1492  
  1493  	return p, resp, nil
  1494  }
  1495  
  1496  // GetRequiredStatusChecks gets the required status checks for a given protected branch.
  1497  //
  1498  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1499  //
  1500  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-status-checks-protection
  1501  //
  1502  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks
  1503  func (s *RepositoriesService) GetRequiredStatusChecks(ctx context.Context, owner, repo, branch string) (*RequiredStatusChecks, *Response, error) {
  1504  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks", owner, repo, url.PathEscape(branch))
  1505  	req, err := s.client.NewRequest("GET", u, nil)
  1506  	if err != nil {
  1507  		return nil, nil, err
  1508  	}
  1509  
  1510  	p := new(RequiredStatusChecks)
  1511  	resp, err := s.client.Do(ctx, req, p)
  1512  	if err != nil {
  1513  		if isBranchNotProtected(err) {
  1514  			err = ErrBranchNotProtected
  1515  		}
  1516  		return nil, resp, err
  1517  	}
  1518  
  1519  	return p, resp, nil
  1520  }
  1521  
  1522  // ListRequiredStatusChecksContexts lists the required status checks contexts for a given protected branch.
  1523  //
  1524  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1525  //
  1526  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-all-status-check-contexts
  1527  //
  1528  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks/contexts
  1529  func (s *RepositoriesService) ListRequiredStatusChecksContexts(ctx context.Context, owner, repo, branch string) (contexts []string, resp *Response, err error) {
  1530  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks/contexts", owner, repo, url.PathEscape(branch))
  1531  	req, err := s.client.NewRequest("GET", u, nil)
  1532  	if err != nil {
  1533  		return nil, nil, err
  1534  	}
  1535  
  1536  	resp, err = s.client.Do(ctx, req, &contexts)
  1537  	if err != nil {
  1538  		if isBranchNotProtected(err) {
  1539  			err = ErrBranchNotProtected
  1540  		}
  1541  		return nil, resp, err
  1542  	}
  1543  
  1544  	return contexts, resp, nil
  1545  }
  1546  
  1547  // UpdateBranchProtection updates the protection of a given branch.
  1548  //
  1549  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1550  //
  1551  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#update-branch-protection
  1552  //
  1553  //meta:operation PUT /repos/{owner}/{repo}/branches/{branch}/protection
  1554  func (s *RepositoriesService) UpdateBranchProtection(ctx context.Context, owner, repo, branch string, preq *ProtectionRequest) (*Protection, *Response, error) {
  1555  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, url.PathEscape(branch))
  1556  	req, err := s.client.NewRequest("PUT", u, preq)
  1557  	if err != nil {
  1558  		return nil, nil, err
  1559  	}
  1560  
  1561  	// TODO: remove custom Accept header when this API fully launches
  1562  	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
  1563  
  1564  	p := new(Protection)
  1565  	resp, err := s.client.Do(ctx, req, p)
  1566  	if err != nil {
  1567  		return nil, resp, err
  1568  	}
  1569  
  1570  	return p, resp, nil
  1571  }
  1572  
  1573  // RemoveBranchProtection removes the protection of a given branch.
  1574  //
  1575  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1576  //
  1577  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#delete-branch-protection
  1578  //
  1579  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection
  1580  func (s *RepositoriesService) RemoveBranchProtection(ctx context.Context, owner, repo, branch string) (*Response, error) {
  1581  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, url.PathEscape(branch))
  1582  	req, err := s.client.NewRequest("DELETE", u, nil)
  1583  	if err != nil {
  1584  		return nil, err
  1585  	}
  1586  
  1587  	return s.client.Do(ctx, req, nil)
  1588  }
  1589  
  1590  // GetSignaturesProtectedBranch gets required signatures of protected branch.
  1591  //
  1592  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1593  //
  1594  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-commit-signature-protection
  1595  //
  1596  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures
  1597  func (s *RepositoriesService) GetSignaturesProtectedBranch(ctx context.Context, owner, repo, branch string) (*SignaturesProtectedBranch, *Response, error) {
  1598  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_signatures", owner, repo, url.PathEscape(branch))
  1599  	req, err := s.client.NewRequest("GET", u, nil)
  1600  	if err != nil {
  1601  		return nil, nil, err
  1602  	}
  1603  
  1604  	// TODO: remove custom Accept header when this API fully launches
  1605  	req.Header.Set("Accept", mediaTypeSignaturePreview)
  1606  
  1607  	p := new(SignaturesProtectedBranch)
  1608  	resp, err := s.client.Do(ctx, req, p)
  1609  	if err != nil {
  1610  		return nil, resp, err
  1611  	}
  1612  
  1613  	return p, resp, nil
  1614  }
  1615  
  1616  // RequireSignaturesOnProtectedBranch makes signed commits required on a protected branch.
  1617  // It requires admin access and branch protection to be enabled.
  1618  //
  1619  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1620  //
  1621  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#create-commit-signature-protection
  1622  //
  1623  //meta:operation POST /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures
  1624  func (s *RepositoriesService) RequireSignaturesOnProtectedBranch(ctx context.Context, owner, repo, branch string) (*SignaturesProtectedBranch, *Response, error) {
  1625  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_signatures", owner, repo, url.PathEscape(branch))
  1626  	req, err := s.client.NewRequest("POST", u, nil)
  1627  	if err != nil {
  1628  		return nil, nil, err
  1629  	}
  1630  
  1631  	// TODO: remove custom Accept header when this API fully launches
  1632  	req.Header.Set("Accept", mediaTypeSignaturePreview)
  1633  
  1634  	r := new(SignaturesProtectedBranch)
  1635  	resp, err := s.client.Do(ctx, req, r)
  1636  	if err != nil {
  1637  		return nil, resp, err
  1638  	}
  1639  
  1640  	return r, resp, nil
  1641  }
  1642  
  1643  // OptionalSignaturesOnProtectedBranch removes required signed commits on a given branch.
  1644  //
  1645  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1646  //
  1647  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#delete-commit-signature-protection
  1648  //
  1649  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures
  1650  func (s *RepositoriesService) OptionalSignaturesOnProtectedBranch(ctx context.Context, owner, repo, branch string) (*Response, error) {
  1651  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_signatures", owner, repo, url.PathEscape(branch))
  1652  	req, err := s.client.NewRequest("DELETE", u, nil)
  1653  	if err != nil {
  1654  		return nil, err
  1655  	}
  1656  
  1657  	// TODO: remove custom Accept header when this API fully launches
  1658  	req.Header.Set("Accept", mediaTypeSignaturePreview)
  1659  
  1660  	return s.client.Do(ctx, req, nil)
  1661  }
  1662  
  1663  // UpdateRequiredStatusChecks updates the required status checks for a given protected branch.
  1664  //
  1665  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1666  //
  1667  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#update-status-check-protection
  1668  //
  1669  //meta:operation PATCH /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks
  1670  func (s *RepositoriesService) UpdateRequiredStatusChecks(ctx context.Context, owner, repo, branch string, sreq *RequiredStatusChecksRequest) (*RequiredStatusChecks, *Response, error) {
  1671  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks", owner, repo, url.PathEscape(branch))
  1672  	req, err := s.client.NewRequest("PATCH", u, sreq)
  1673  	if err != nil {
  1674  		return nil, nil, err
  1675  	}
  1676  
  1677  	sc := new(RequiredStatusChecks)
  1678  	resp, err := s.client.Do(ctx, req, sc)
  1679  	if err != nil {
  1680  		return nil, resp, err
  1681  	}
  1682  
  1683  	return sc, resp, nil
  1684  }
  1685  
  1686  // RemoveRequiredStatusChecks removes the required status checks for a given protected branch.
  1687  //
  1688  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1689  //
  1690  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#remove-status-check-protection
  1691  //
  1692  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks
  1693  func (s *RepositoriesService) RemoveRequiredStatusChecks(ctx context.Context, owner, repo, branch string) (*Response, error) {
  1694  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks", owner, repo, url.PathEscape(branch))
  1695  	req, err := s.client.NewRequest("DELETE", u, nil)
  1696  	if err != nil {
  1697  		return nil, err
  1698  	}
  1699  
  1700  	return s.client.Do(ctx, req, nil)
  1701  }
  1702  
  1703  // License gets the contents of a repository's license if one is detected.
  1704  //
  1705  // GitHub API docs: https://docs.github.com/rest/licenses/licenses#get-the-license-for-a-repository
  1706  //
  1707  //meta:operation GET /repos/{owner}/{repo}/license
  1708  func (s *RepositoriesService) License(ctx context.Context, owner, repo string) (*RepositoryLicense, *Response, error) {
  1709  	u := fmt.Sprintf("repos/%v/%v/license", owner, repo)
  1710  	req, err := s.client.NewRequest("GET", u, nil)
  1711  	if err != nil {
  1712  		return nil, nil, err
  1713  	}
  1714  
  1715  	r := &RepositoryLicense{}
  1716  	resp, err := s.client.Do(ctx, req, r)
  1717  	if err != nil {
  1718  		return nil, resp, err
  1719  	}
  1720  
  1721  	return r, resp, nil
  1722  }
  1723  
  1724  // GetPullRequestReviewEnforcement gets pull request review enforcement of a protected branch.
  1725  //
  1726  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1727  //
  1728  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-pull-request-review-protection
  1729  //
  1730  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews
  1731  func (s *RepositoriesService) GetPullRequestReviewEnforcement(ctx context.Context, owner, repo, branch string) (*PullRequestReviewsEnforcement, *Response, error) {
  1732  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, url.PathEscape(branch))
  1733  	req, err := s.client.NewRequest("GET", u, nil)
  1734  	if err != nil {
  1735  		return nil, nil, err
  1736  	}
  1737  
  1738  	// TODO: remove custom Accept header when this API fully launches
  1739  	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
  1740  
  1741  	r := new(PullRequestReviewsEnforcement)
  1742  	resp, err := s.client.Do(ctx, req, r)
  1743  	if err != nil {
  1744  		return nil, resp, err
  1745  	}
  1746  
  1747  	return r, resp, nil
  1748  }
  1749  
  1750  // UpdatePullRequestReviewEnforcement patches pull request review enforcement of a protected branch.
  1751  // It requires admin access and branch protection to be enabled.
  1752  //
  1753  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1754  //
  1755  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#update-pull-request-review-protection
  1756  //
  1757  //meta:operation PATCH /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews
  1758  func (s *RepositoriesService) UpdatePullRequestReviewEnforcement(ctx context.Context, owner, repo, branch string, patch *PullRequestReviewsEnforcementUpdate) (*PullRequestReviewsEnforcement, *Response, error) {
  1759  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, url.PathEscape(branch))
  1760  	req, err := s.client.NewRequest("PATCH", u, patch)
  1761  	if err != nil {
  1762  		return nil, nil, err
  1763  	}
  1764  
  1765  	// TODO: remove custom Accept header when this API fully launches
  1766  	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
  1767  
  1768  	r := new(PullRequestReviewsEnforcement)
  1769  	resp, err := s.client.Do(ctx, req, r)
  1770  	if err != nil {
  1771  		return nil, resp, err
  1772  	}
  1773  
  1774  	return r, resp, nil
  1775  }
  1776  
  1777  // DisableDismissalRestrictions disables dismissal restrictions of a protected branch.
  1778  // It requires admin access and branch protection to be enabled.
  1779  //
  1780  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1781  //
  1782  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#update-pull-request-review-protection
  1783  //
  1784  //meta:operation PATCH /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews
  1785  func (s *RepositoriesService) DisableDismissalRestrictions(ctx context.Context, owner, repo, branch string) (*PullRequestReviewsEnforcement, *Response, error) {
  1786  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, url.PathEscape(branch))
  1787  
  1788  	data := new(struct {
  1789  		DismissalRestrictionsRequest `json:"dismissal_restrictions"`
  1790  	})
  1791  
  1792  	req, err := s.client.NewRequest("PATCH", u, data)
  1793  	if err != nil {
  1794  		return nil, nil, err
  1795  	}
  1796  
  1797  	// TODO: remove custom Accept header when this API fully launches
  1798  	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
  1799  
  1800  	r := new(PullRequestReviewsEnforcement)
  1801  	resp, err := s.client.Do(ctx, req, r)
  1802  	if err != nil {
  1803  		return nil, resp, err
  1804  	}
  1805  
  1806  	return r, resp, nil
  1807  }
  1808  
  1809  // RemovePullRequestReviewEnforcement removes pull request enforcement of a protected branch.
  1810  //
  1811  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1812  //
  1813  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#delete-pull-request-review-protection
  1814  //
  1815  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews
  1816  func (s *RepositoriesService) RemovePullRequestReviewEnforcement(ctx context.Context, owner, repo, branch string) (*Response, error) {
  1817  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, url.PathEscape(branch))
  1818  	req, err := s.client.NewRequest("DELETE", u, nil)
  1819  	if err != nil {
  1820  		return nil, err
  1821  	}
  1822  
  1823  	return s.client.Do(ctx, req, nil)
  1824  }
  1825  
  1826  // GetAdminEnforcement gets admin enforcement information of a protected branch.
  1827  //
  1828  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1829  //
  1830  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-admin-branch-protection
  1831  //
  1832  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins
  1833  func (s *RepositoriesService) GetAdminEnforcement(ctx context.Context, owner, repo, branch string) (*AdminEnforcement, *Response, error) {
  1834  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/enforce_admins", owner, repo, url.PathEscape(branch))
  1835  	req, err := s.client.NewRequest("GET", u, nil)
  1836  	if err != nil {
  1837  		return nil, nil, err
  1838  	}
  1839  
  1840  	r := new(AdminEnforcement)
  1841  	resp, err := s.client.Do(ctx, req, r)
  1842  	if err != nil {
  1843  		return nil, resp, err
  1844  	}
  1845  
  1846  	return r, resp, nil
  1847  }
  1848  
  1849  // AddAdminEnforcement adds admin enforcement to a protected branch.
  1850  // It requires admin access and branch protection to be enabled.
  1851  //
  1852  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1853  //
  1854  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#set-admin-branch-protection
  1855  //
  1856  //meta:operation POST /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins
  1857  func (s *RepositoriesService) AddAdminEnforcement(ctx context.Context, owner, repo, branch string) (*AdminEnforcement, *Response, error) {
  1858  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/enforce_admins", owner, repo, url.PathEscape(branch))
  1859  	req, err := s.client.NewRequest("POST", u, nil)
  1860  	if err != nil {
  1861  		return nil, nil, err
  1862  	}
  1863  
  1864  	r := new(AdminEnforcement)
  1865  	resp, err := s.client.Do(ctx, req, r)
  1866  	if err != nil {
  1867  		return nil, resp, err
  1868  	}
  1869  
  1870  	return r, resp, nil
  1871  }
  1872  
  1873  // RemoveAdminEnforcement removes admin enforcement from a protected branch.
  1874  //
  1875  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1876  //
  1877  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#delete-admin-branch-protection
  1878  //
  1879  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins
  1880  func (s *RepositoriesService) RemoveAdminEnforcement(ctx context.Context, owner, repo, branch string) (*Response, error) {
  1881  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/enforce_admins", owner, repo, url.PathEscape(branch))
  1882  	req, err := s.client.NewRequest("DELETE", u, nil)
  1883  	if err != nil {
  1884  		return nil, err
  1885  	}
  1886  
  1887  	return s.client.Do(ctx, req, nil)
  1888  }
  1889  
  1890  // repositoryTopics represents a collection of repository topics.
  1891  type repositoryTopics struct {
  1892  	Names []string `json:"names"`
  1893  }
  1894  
  1895  // ListAllTopics lists topics for a repository.
  1896  //
  1897  // GitHub API docs: https://docs.github.com/rest/repos/repos#get-all-repository-topics
  1898  //
  1899  //meta:operation GET /repos/{owner}/{repo}/topics
  1900  func (s *RepositoriesService) ListAllTopics(ctx context.Context, owner, repo string) ([]string, *Response, error) {
  1901  	u := fmt.Sprintf("repos/%v/%v/topics", owner, repo)
  1902  	req, err := s.client.NewRequest("GET", u, nil)
  1903  	if err != nil {
  1904  		return nil, nil, err
  1905  	}
  1906  
  1907  	// TODO: remove custom Accept header when this API fully launches.
  1908  	req.Header.Set("Accept", mediaTypeTopicsPreview)
  1909  
  1910  	topics := new(repositoryTopics)
  1911  	resp, err := s.client.Do(ctx, req, topics)
  1912  	if err != nil {
  1913  		return nil, resp, err
  1914  	}
  1915  
  1916  	return topics.Names, resp, nil
  1917  }
  1918  
  1919  // ReplaceAllTopics replaces all repository topics.
  1920  //
  1921  // GitHub API docs: https://docs.github.com/rest/repos/repos#replace-all-repository-topics
  1922  //
  1923  //meta:operation PUT /repos/{owner}/{repo}/topics
  1924  func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo string, topics []string) ([]string, *Response, error) {
  1925  	u := fmt.Sprintf("repos/%v/%v/topics", owner, repo)
  1926  	t := &repositoryTopics{
  1927  		Names: topics,
  1928  	}
  1929  	if t.Names == nil {
  1930  		t.Names = []string{}
  1931  	}
  1932  	req, err := s.client.NewRequest("PUT", u, t)
  1933  	if err != nil {
  1934  		return nil, nil, err
  1935  	}
  1936  
  1937  	// TODO: remove custom Accept header when this API fully launches.
  1938  	req.Header.Set("Accept", mediaTypeTopicsPreview)
  1939  
  1940  	t = new(repositoryTopics)
  1941  	resp, err := s.client.Do(ctx, req, t)
  1942  	if err != nil {
  1943  		return nil, resp, err
  1944  	}
  1945  
  1946  	return t.Names, resp, nil
  1947  }
  1948  
  1949  // ListApps lists the GitHub apps that have push access to a given protected branch.
  1950  // It requires the GitHub apps to have `write` access to the `content` permission.
  1951  //
  1952  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1953  //
  1954  // Deprecated: Please use ListAppRestrictions instead.
  1955  //
  1956  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-apps-with-access-to-the-protected-branch
  1957  //
  1958  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps
  1959  func (s *RepositoriesService) ListApps(ctx context.Context, owner, repo, branch string) ([]*App, *Response, error) {
  1960  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, url.PathEscape(branch))
  1961  	req, err := s.client.NewRequest("GET", u, nil)
  1962  	if err != nil {
  1963  		return nil, nil, err
  1964  	}
  1965  
  1966  	var apps []*App
  1967  	resp, err := s.client.Do(ctx, req, &apps)
  1968  	if err != nil {
  1969  		return nil, resp, err
  1970  	}
  1971  
  1972  	return apps, resp, nil
  1973  }
  1974  
  1975  // ListAppRestrictions lists the GitHub apps that have push access to a given protected branch.
  1976  // It requires the GitHub apps to have `write` access to the `content` permission.
  1977  //
  1978  // Note: This is a wrapper around ListApps so a naming convention with ListUserRestrictions and ListTeamRestrictions is preserved.
  1979  //
  1980  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-apps-with-access-to-the-protected-branch
  1981  //
  1982  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps
  1983  func (s *RepositoriesService) ListAppRestrictions(ctx context.Context, owner, repo, branch string) ([]*App, *Response, error) {
  1984  	return s.ListApps(ctx, owner, repo, branch)
  1985  }
  1986  
  1987  // ReplaceAppRestrictions replaces the apps that have push access to a given protected branch.
  1988  // It removes all apps that previously had push access and grants push access to the new list of apps.
  1989  // It requires the GitHub apps to have `write` access to the `content` permission.
  1990  //
  1991  // Note: The list of users, apps, and teams in total is limited to 100 items.
  1992  //
  1993  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1994  //
  1995  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#set-app-access-restrictions
  1996  //
  1997  //meta:operation PUT /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps
  1998  func (s *RepositoriesService) ReplaceAppRestrictions(ctx context.Context, owner, repo, branch string, apps []string) ([]*App, *Response, error) {
  1999  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, url.PathEscape(branch))
  2000  	req, err := s.client.NewRequest("PUT", u, apps)
  2001  	if err != nil {
  2002  		return nil, nil, err
  2003  	}
  2004  
  2005  	var newApps []*App
  2006  	resp, err := s.client.Do(ctx, req, &newApps)
  2007  	if err != nil {
  2008  		return nil, resp, err
  2009  	}
  2010  
  2011  	return newApps, resp, nil
  2012  }
  2013  
  2014  // AddAppRestrictions grants the specified apps push access to a given protected branch.
  2015  // It requires the GitHub apps to have `write` access to the `content` permission.
  2016  //
  2017  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2018  //
  2019  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2020  //
  2021  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#add-app-access-restrictions
  2022  //
  2023  //meta:operation POST /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps
  2024  func (s *RepositoriesService) AddAppRestrictions(ctx context.Context, owner, repo, branch string, apps []string) ([]*App, *Response, error) {
  2025  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, url.PathEscape(branch))
  2026  	req, err := s.client.NewRequest("POST", u, apps)
  2027  	if err != nil {
  2028  		return nil, nil, err
  2029  	}
  2030  
  2031  	var newApps []*App
  2032  	resp, err := s.client.Do(ctx, req, &newApps)
  2033  	if err != nil {
  2034  		return nil, resp, err
  2035  	}
  2036  
  2037  	return newApps, resp, nil
  2038  }
  2039  
  2040  // RemoveAppRestrictions removes the restrictions of an app from pushing to this branch.
  2041  // It requires the GitHub apps to have `write` access to the `content` permission.
  2042  //
  2043  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2044  //
  2045  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2046  //
  2047  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#remove-app-access-restrictions
  2048  //
  2049  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps
  2050  func (s *RepositoriesService) RemoveAppRestrictions(ctx context.Context, owner, repo, branch string, apps []string) ([]*App, *Response, error) {
  2051  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, url.PathEscape(branch))
  2052  	req, err := s.client.NewRequest("DELETE", u, apps)
  2053  	if err != nil {
  2054  		return nil, nil, err
  2055  	}
  2056  
  2057  	var newApps []*App
  2058  	resp, err := s.client.Do(ctx, req, &newApps)
  2059  	if err != nil {
  2060  		return nil, resp, err
  2061  	}
  2062  
  2063  	return newApps, resp, nil
  2064  }
  2065  
  2066  // ListTeamRestrictions lists the GitHub teams that have push access to a given protected branch.
  2067  // It requires the GitHub teams to have `write` access to the `content` permission.
  2068  //
  2069  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2070  //
  2071  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-teams-with-access-to-the-protected-branch
  2072  //
  2073  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams
  2074  func (s *RepositoriesService) ListTeamRestrictions(ctx context.Context, owner, repo, branch string) ([]*Team, *Response, error) {
  2075  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/teams", owner, repo, url.PathEscape(branch))
  2076  	req, err := s.client.NewRequest("GET", u, nil)
  2077  	if err != nil {
  2078  		return nil, nil, err
  2079  	}
  2080  
  2081  	var teams []*Team
  2082  	resp, err := s.client.Do(ctx, req, &teams)
  2083  	if err != nil {
  2084  		return nil, resp, err
  2085  	}
  2086  
  2087  	return teams, resp, nil
  2088  }
  2089  
  2090  // ReplaceTeamRestrictions replaces the team that have push access to a given protected branch.
  2091  // This removes all teams that previously had push access and grants push access to the new list of teams.
  2092  // It requires the GitHub teams to have `write` access to the `content` permission.
  2093  //
  2094  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2095  //
  2096  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2097  //
  2098  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#set-team-access-restrictions
  2099  //
  2100  //meta:operation PUT /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams
  2101  func (s *RepositoriesService) ReplaceTeamRestrictions(ctx context.Context, owner, repo, branch string, teams []string) ([]*Team, *Response, error) {
  2102  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/teams", owner, repo, url.PathEscape(branch))
  2103  	req, err := s.client.NewRequest("PUT", u, teams)
  2104  	if err != nil {
  2105  		return nil, nil, err
  2106  	}
  2107  
  2108  	var newTeams []*Team
  2109  	resp, err := s.client.Do(ctx, req, &newTeams)
  2110  	if err != nil {
  2111  		return nil, resp, err
  2112  	}
  2113  
  2114  	return newTeams, resp, nil
  2115  }
  2116  
  2117  // AddTeamRestrictions grants the specified teams push access to a given protected branch.
  2118  // It requires the GitHub teams to have `write` access to the `content` permission.
  2119  //
  2120  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2121  //
  2122  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2123  //
  2124  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#add-team-access-restrictions
  2125  //
  2126  //meta:operation POST /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams
  2127  func (s *RepositoriesService) AddTeamRestrictions(ctx context.Context, owner, repo, branch string, teams []string) ([]*Team, *Response, error) {
  2128  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/teams", owner, repo, url.PathEscape(branch))
  2129  	req, err := s.client.NewRequest("POST", u, teams)
  2130  	if err != nil {
  2131  		return nil, nil, err
  2132  	}
  2133  
  2134  	var newTeams []*Team
  2135  	resp, err := s.client.Do(ctx, req, &newTeams)
  2136  	if err != nil {
  2137  		return nil, resp, err
  2138  	}
  2139  
  2140  	return newTeams, resp, nil
  2141  }
  2142  
  2143  // RemoveTeamRestrictions removes the restrictions of a team from pushing to this branch.
  2144  // It requires the GitHub teams to have `write` access to the `content` permission.
  2145  //
  2146  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2147  //
  2148  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2149  //
  2150  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#remove-team-access-restrictions
  2151  //
  2152  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams
  2153  func (s *RepositoriesService) RemoveTeamRestrictions(ctx context.Context, owner, repo, branch string, teams []string) ([]*Team, *Response, error) {
  2154  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/teams", owner, repo, url.PathEscape(branch))
  2155  	req, err := s.client.NewRequest("DELETE", u, teams)
  2156  	if err != nil {
  2157  		return nil, nil, err
  2158  	}
  2159  
  2160  	var newTeams []*Team
  2161  	resp, err := s.client.Do(ctx, req, &newTeams)
  2162  	if err != nil {
  2163  		return nil, resp, err
  2164  	}
  2165  
  2166  	return newTeams, resp, nil
  2167  }
  2168  
  2169  // ListUserRestrictions lists the GitHub users that have push access to a given protected branch.
  2170  // It requires the GitHub users to have `write` access to the `content` permission.
  2171  //
  2172  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2173  //
  2174  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-users-with-access-to-the-protected-branch
  2175  //
  2176  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users
  2177  func (s *RepositoriesService) ListUserRestrictions(ctx context.Context, owner, repo, branch string) ([]*User, *Response, error) {
  2178  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/users", owner, repo, url.PathEscape(branch))
  2179  	req, err := s.client.NewRequest("GET", u, nil)
  2180  	if err != nil {
  2181  		return nil, nil, err
  2182  	}
  2183  
  2184  	var users []*User
  2185  	resp, err := s.client.Do(ctx, req, &users)
  2186  	if err != nil {
  2187  		return nil, resp, err
  2188  	}
  2189  
  2190  	return users, resp, nil
  2191  }
  2192  
  2193  // ReplaceUserRestrictions replaces the user that have push access to a given protected branch.
  2194  // It removes all users that previously had push access and grants push access to the new list of users.
  2195  // It requires the GitHub users to have `write` access to the `content` permission.
  2196  //
  2197  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2198  //
  2199  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2200  //
  2201  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#set-user-access-restrictions
  2202  //
  2203  //meta:operation PUT /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users
  2204  func (s *RepositoriesService) ReplaceUserRestrictions(ctx context.Context, owner, repo, branch string, users []string) ([]*User, *Response, error) {
  2205  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/users", owner, repo, url.PathEscape(branch))
  2206  	req, err := s.client.NewRequest("PUT", u, users)
  2207  	if err != nil {
  2208  		return nil, nil, err
  2209  	}
  2210  
  2211  	var newUsers []*User
  2212  	resp, err := s.client.Do(ctx, req, &newUsers)
  2213  	if err != nil {
  2214  		return nil, resp, err
  2215  	}
  2216  
  2217  	return newUsers, resp, nil
  2218  }
  2219  
  2220  // AddUserRestrictions grants the specified users push access to a given protected branch.
  2221  // It requires the GitHub users to have `write` access to the `content` permission.
  2222  //
  2223  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2224  //
  2225  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2226  //
  2227  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#add-user-access-restrictions
  2228  //
  2229  //meta:operation POST /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users
  2230  func (s *RepositoriesService) AddUserRestrictions(ctx context.Context, owner, repo, branch string, users []string) ([]*User, *Response, error) {
  2231  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/users", owner, repo, url.PathEscape(branch))
  2232  	req, err := s.client.NewRequest("POST", u, users)
  2233  	if err != nil {
  2234  		return nil, nil, err
  2235  	}
  2236  
  2237  	var newUsers []*User
  2238  	resp, err := s.client.Do(ctx, req, &newUsers)
  2239  	if err != nil {
  2240  		return nil, resp, err
  2241  	}
  2242  
  2243  	return newUsers, resp, nil
  2244  }
  2245  
  2246  // RemoveUserRestrictions removes the restrictions of a user from pushing to this branch.
  2247  // It requires the GitHub users to have `write` access to the `content` permission.
  2248  //
  2249  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2250  //
  2251  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2252  //
  2253  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#remove-user-access-restrictions
  2254  //
  2255  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users
  2256  func (s *RepositoriesService) RemoveUserRestrictions(ctx context.Context, owner, repo, branch string, users []string) ([]*User, *Response, error) {
  2257  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/users", owner, repo, url.PathEscape(branch))
  2258  	req, err := s.client.NewRequest("DELETE", u, users)
  2259  	if err != nil {
  2260  		return nil, nil, err
  2261  	}
  2262  
  2263  	var newUsers []*User
  2264  	resp, err := s.client.Do(ctx, req, &newUsers)
  2265  	if err != nil {
  2266  		return nil, resp, err
  2267  	}
  2268  
  2269  	return newUsers, resp, nil
  2270  }
  2271  
  2272  // TransferRequest represents a request to transfer a repository.
  2273  type TransferRequest struct {
  2274  	NewOwner string  `json:"new_owner"`
  2275  	NewName  *string `json:"new_name,omitempty"`
  2276  	TeamID   []int64 `json:"team_ids,omitempty"`
  2277  }
  2278  
  2279  // Transfer transfers a repository from one account or organization to another.
  2280  //
  2281  // This method might return an *AcceptedError and a status code of
  2282  // 202. This is because this is the status that GitHub returns to signify that
  2283  // it has now scheduled the transfer of the repository in a background task.
  2284  // A follow up request, after a delay of a second or so, should result
  2285  // in a successful request.
  2286  //
  2287  // GitHub API docs: https://docs.github.com/rest/repos/repos#transfer-a-repository
  2288  //
  2289  //meta:operation POST /repos/{owner}/{repo}/transfer
  2290  func (s *RepositoriesService) Transfer(ctx context.Context, owner, repo string, transfer TransferRequest) (*Repository, *Response, error) {
  2291  	u := fmt.Sprintf("repos/%v/%v/transfer", owner, repo)
  2292  
  2293  	req, err := s.client.NewRequest("POST", u, &transfer)
  2294  	if err != nil {
  2295  		return nil, nil, err
  2296  	}
  2297  
  2298  	r := new(Repository)
  2299  	resp, err := s.client.Do(ctx, req, r)
  2300  	if err != nil {
  2301  		return nil, resp, err
  2302  	}
  2303  
  2304  	return r, resp, nil
  2305  }
  2306  
  2307  // DispatchRequestOptions represents a request to trigger a repository_dispatch event.
  2308  type DispatchRequestOptions struct {
  2309  	// EventType is a custom webhook event name. (Required.)
  2310  	EventType string `json:"event_type"`
  2311  	// ClientPayload is a custom JSON payload with extra information about the webhook event.
  2312  	// Defaults to an empty JSON object.
  2313  	ClientPayload *json.RawMessage `json:"client_payload,omitempty"`
  2314  }
  2315  
  2316  // Dispatch triggers a repository_dispatch event in a GitHub Actions workflow.
  2317  //
  2318  // GitHub API docs: https://docs.github.com/rest/repos/repos#create-a-repository-dispatch-event
  2319  //
  2320  //meta:operation POST /repos/{owner}/{repo}/dispatches
  2321  func (s *RepositoriesService) Dispatch(ctx context.Context, owner, repo string, opts DispatchRequestOptions) (*Repository, *Response, error) {
  2322  	u := fmt.Sprintf("repos/%v/%v/dispatches", owner, repo)
  2323  
  2324  	req, err := s.client.NewRequest("POST", u, &opts)
  2325  	if err != nil {
  2326  		return nil, nil, err
  2327  	}
  2328  
  2329  	r := new(Repository)
  2330  	resp, err := s.client.Do(ctx, req, r)
  2331  	if err != nil {
  2332  		return nil, resp, err
  2333  	}
  2334  
  2335  	return r, resp, nil
  2336  }
  2337  
  2338  // isBranchNotProtected determines whether a branch is not protected
  2339  // based on the error message returned by GitHub API.
  2340  func isBranchNotProtected(err error) bool {
  2341  	errorResponse, ok := err.(*ErrorResponse)
  2342  	return ok && errorResponse.Message == githubBranchNotProtected
  2343  }
  2344  
  2345  // EnablePrivateReporting enables private reporting of vulnerabilities for a
  2346  // repository.
  2347  //
  2348  // GitHub API docs: https://docs.github.com/rest/repos/repos#enable-private-vulnerability-reporting-for-a-repository
  2349  //
  2350  //meta:operation PUT /repos/{owner}/{repo}/private-vulnerability-reporting
  2351  func (s *RepositoriesService) EnablePrivateReporting(ctx context.Context, owner, repo string) (*Response, error) {
  2352  	u := fmt.Sprintf("repos/%v/%v/private-vulnerability-reporting", owner, repo)
  2353  
  2354  	req, err := s.client.NewRequest("PUT", u, nil)
  2355  	if err != nil {
  2356  		return nil, err
  2357  	}
  2358  
  2359  	resp, err := s.client.Do(ctx, req, nil)
  2360  	if err != nil {
  2361  		return resp, err
  2362  	}
  2363  
  2364  	return resp, nil
  2365  }
  2366  
  2367  // DisablePrivateReporting disables private reporting of vulnerabilities for a
  2368  // repository.
  2369  //
  2370  // GitHub API docs: https://docs.github.com/rest/repos/repos#disable-private-vulnerability-reporting-for-a-repository
  2371  //
  2372  //meta:operation DELETE /repos/{owner}/{repo}/private-vulnerability-reporting
  2373  func (s *RepositoriesService) DisablePrivateReporting(ctx context.Context, owner, repo string) (*Response, error) {
  2374  	u := fmt.Sprintf("repos/%v/%v/private-vulnerability-reporting", owner, repo)
  2375  
  2376  	req, err := s.client.NewRequest("DELETE", u, nil)
  2377  	if err != nil {
  2378  		return nil, err
  2379  	}
  2380  
  2381  	resp, err := s.client.Do(ctx, req, nil)
  2382  	if err != nil {
  2383  		return resp, err
  2384  	}
  2385  
  2386  	return resp, nil
  2387  }