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