github.com/google/go-github/v64@v64.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]interface{} `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-automated-security-fixes-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-automated-security-fixes
   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-automated-security-fixes
   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  }
  1015  
  1016  // Protection represents a repository branch's protection.
  1017  type Protection struct {
  1018  	RequiredStatusChecks           *RequiredStatusChecks           `json:"required_status_checks"`
  1019  	RequiredPullRequestReviews     *PullRequestReviewsEnforcement  `json:"required_pull_request_reviews"`
  1020  	EnforceAdmins                  *AdminEnforcement               `json:"enforce_admins"`
  1021  	Restrictions                   *BranchRestrictions             `json:"restrictions"`
  1022  	RequireLinearHistory           *RequireLinearHistory           `json:"required_linear_history"`
  1023  	AllowForcePushes               *AllowForcePushes               `json:"allow_force_pushes"`
  1024  	AllowDeletions                 *AllowDeletions                 `json:"allow_deletions"`
  1025  	RequiredConversationResolution *RequiredConversationResolution `json:"required_conversation_resolution"`
  1026  	BlockCreations                 *BlockCreations                 `json:"block_creations,omitempty"`
  1027  	LockBranch                     *LockBranch                     `json:"lock_branch,omitempty"`
  1028  	AllowForkSyncing               *AllowForkSyncing               `json:"allow_fork_syncing,omitempty"`
  1029  	RequiredSignatures             *SignaturesProtectedBranch      `json:"required_signatures,omitempty"`
  1030  	URL                            *string                         `json:"url,omitempty"`
  1031  }
  1032  
  1033  // BlockCreations represents whether users can push changes that create branches. If this is true, this
  1034  // setting blocks pushes that create new branches, unless the push is initiated by a user, team, or app
  1035  // which has the ability to push.
  1036  type BlockCreations struct {
  1037  	Enabled *bool `json:"enabled,omitempty"`
  1038  }
  1039  
  1040  // LockBranch represents if the branch is marked as read-only. If this is true, users will not be able to push to the branch.
  1041  type LockBranch struct {
  1042  	Enabled *bool `json:"enabled,omitempty"`
  1043  }
  1044  
  1045  // AllowForkSyncing represents whether users can pull changes from upstream when the branch is locked.
  1046  type AllowForkSyncing struct {
  1047  	Enabled *bool `json:"enabled,omitempty"`
  1048  }
  1049  
  1050  // BranchProtectionRule represents the rule applied to a repositories branch.
  1051  type BranchProtectionRule struct {
  1052  	ID                                       *int64     `json:"id,omitempty"`
  1053  	RepositoryID                             *int64     `json:"repository_id,omitempty"`
  1054  	Name                                     *string    `json:"name,omitempty"`
  1055  	CreatedAt                                *Timestamp `json:"created_at,omitempty"`
  1056  	UpdatedAt                                *Timestamp `json:"updated_at,omitempty"`
  1057  	PullRequestReviewsEnforcementLevel       *string    `json:"pull_request_reviews_enforcement_level,omitempty"`
  1058  	RequiredApprovingReviewCount             *int       `json:"required_approving_review_count,omitempty"`
  1059  	DismissStaleReviewsOnPush                *bool      `json:"dismiss_stale_reviews_on_push,omitempty"`
  1060  	AuthorizedDismissalActorsOnly            *bool      `json:"authorized_dismissal_actors_only,omitempty"`
  1061  	IgnoreApprovalsFromContributors          *bool      `json:"ignore_approvals_from_contributors,omitempty"`
  1062  	RequireCodeOwnerReview                   *bool      `json:"require_code_owner_review,omitempty"`
  1063  	RequiredStatusChecks                     []string   `json:"required_status_checks,omitempty"`
  1064  	RequiredStatusChecksEnforcementLevel     *string    `json:"required_status_checks_enforcement_level,omitempty"`
  1065  	StrictRequiredStatusChecksPolicy         *bool      `json:"strict_required_status_checks_policy,omitempty"`
  1066  	SignatureRequirementEnforcementLevel     *string    `json:"signature_requirement_enforcement_level,omitempty"`
  1067  	LinearHistoryRequirementEnforcementLevel *string    `json:"linear_history_requirement_enforcement_level,omitempty"`
  1068  	AdminEnforced                            *bool      `json:"admin_enforced,omitempty"`
  1069  	AllowForcePushesEnforcementLevel         *string    `json:"allow_force_pushes_enforcement_level,omitempty"`
  1070  	AllowDeletionsEnforcementLevel           *string    `json:"allow_deletions_enforcement_level,omitempty"`
  1071  	MergeQueueEnforcementLevel               *string    `json:"merge_queue_enforcement_level,omitempty"`
  1072  	RequiredDeploymentsEnforcementLevel      *string    `json:"required_deployments_enforcement_level,omitempty"`
  1073  	RequiredConversationResolutionLevel      *string    `json:"required_conversation_resolution_level,omitempty"`
  1074  	AuthorizedActorsOnly                     *bool      `json:"authorized_actors_only,omitempty"`
  1075  	AuthorizedActorNames                     []string   `json:"authorized_actor_names,omitempty"`
  1076  }
  1077  
  1078  // ProtectionChanges represents the changes to the rule if the BranchProtection was edited.
  1079  type ProtectionChanges struct {
  1080  	AdminEnforced                            *AdminEnforcedChanges                            `json:"admin_enforced,omitempty"`
  1081  	AllowDeletionsEnforcementLevel           *AllowDeletionsEnforcementLevelChanges           `json:"allow_deletions_enforcement_level,omitempty"`
  1082  	AuthorizedActorNames                     *AuthorizedActorNames                            `json:"authorized_actor_names,omitempty"`
  1083  	AuthorizedActorsOnly                     *AuthorizedActorsOnly                            `json:"authorized_actors_only,omitempty"`
  1084  	AuthorizedDismissalActorsOnly            *AuthorizedDismissalActorsOnlyChanges            `json:"authorized_dismissal_actors_only,omitempty"`
  1085  	CreateProtected                          *CreateProtectedChanges                          `json:"create_protected,omitempty"`
  1086  	DismissStaleReviewsOnPush                *DismissStaleReviewsOnPushChanges                `json:"dismiss_stale_reviews_on_push,omitempty"`
  1087  	LinearHistoryRequirementEnforcementLevel *LinearHistoryRequirementEnforcementLevelChanges `json:"linear_history_requirement_enforcement_level,omitempty"`
  1088  	PullRequestReviewsEnforcementLevel       *PullRequestReviewsEnforcementLevelChanges       `json:"pull_request_reviews_enforcement_level,omitempty"`
  1089  	RequireCodeOwnerReview                   *RequireCodeOwnerReviewChanges                   `json:"require_code_owner_review,omitempty"`
  1090  	RequiredConversationResolutionLevel      *RequiredConversationResolutionLevelChanges      `json:"required_conversation_resolution_level,omitempty"`
  1091  	RequiredDeploymentsEnforcementLevel      *RequiredDeploymentsEnforcementLevelChanges      `json:"required_deployments_enforcement_level,omitempty"`
  1092  	RequiredStatusChecks                     *RequiredStatusChecksChanges                     `json:"required_status_checks,omitempty"`
  1093  	RequiredStatusChecksEnforcementLevel     *RequiredStatusChecksEnforcementLevelChanges     `json:"required_status_checks_enforcement_level,omitempty"`
  1094  	SignatureRequirementEnforcementLevel     *SignatureRequirementEnforcementLevelChanges     `json:"signature_requirement_enforcement_level,omitempty"`
  1095  }
  1096  
  1097  // AdminEnforcedChanges represents the changes made to the AdminEnforced policy.
  1098  type AdminEnforcedChanges struct {
  1099  	From *bool `json:"from,omitempty"`
  1100  }
  1101  
  1102  // AllowDeletionsEnforcementLevelChanges represents the changes made to the AllowDeletionsEnforcementLevel policy.
  1103  type AllowDeletionsEnforcementLevelChanges struct {
  1104  	From *string `json:"from,omitempty"`
  1105  }
  1106  
  1107  // AuthorizedActorNames represents who are authorized to edit the branch protection rules.
  1108  type AuthorizedActorNames struct {
  1109  	From []string `json:"from,omitempty"`
  1110  }
  1111  
  1112  // AuthorizedActorsOnly represents if the branch rule can be edited by authorized actors only.
  1113  type AuthorizedActorsOnly struct {
  1114  	From *bool `json:"from,omitempty"`
  1115  }
  1116  
  1117  // AuthorizedDismissalActorsOnlyChanges represents the changes made to the AuthorizedDismissalActorsOnly policy.
  1118  type AuthorizedDismissalActorsOnlyChanges struct {
  1119  	From *bool `json:"from,omitempty"`
  1120  }
  1121  
  1122  // CreateProtectedChanges represents the changes made to the CreateProtected policy.
  1123  type CreateProtectedChanges struct {
  1124  	From *bool `json:"from,omitempty"`
  1125  }
  1126  
  1127  // DismissStaleReviewsOnPushChanges represents the changes made to the DismissStaleReviewsOnPushChanges policy.
  1128  type DismissStaleReviewsOnPushChanges struct {
  1129  	From *bool `json:"from,omitempty"`
  1130  }
  1131  
  1132  // LinearHistoryRequirementEnforcementLevelChanges represents the changes made to the LinearHistoryRequirementEnforcementLevel policy.
  1133  type LinearHistoryRequirementEnforcementLevelChanges struct {
  1134  	From *string `json:"from,omitempty"`
  1135  }
  1136  
  1137  // PullRequestReviewsEnforcementLevelChanges represents the changes made to the PullRequestReviewsEnforcementLevel policy.
  1138  type PullRequestReviewsEnforcementLevelChanges struct {
  1139  	From *string `json:"from,omitempty"`
  1140  }
  1141  
  1142  // RequireCodeOwnerReviewChanges represents the changes made to the RequireCodeOwnerReview policy.
  1143  type RequireCodeOwnerReviewChanges struct {
  1144  	From *bool `json:"from,omitempty"`
  1145  }
  1146  
  1147  // RequiredConversationResolutionLevelChanges represents the changes made to the RequiredConversationResolutionLevel policy.
  1148  type RequiredConversationResolutionLevelChanges struct {
  1149  	From *string `json:"from,omitempty"`
  1150  }
  1151  
  1152  // RequiredDeploymentsEnforcementLevelChanges represents the changes made to the RequiredDeploymentsEnforcementLevel policy.
  1153  type RequiredDeploymentsEnforcementLevelChanges struct {
  1154  	From *string `json:"from,omitempty"`
  1155  }
  1156  
  1157  // RequiredStatusChecksChanges represents the changes made to the RequiredStatusChecks policy.
  1158  type RequiredStatusChecksChanges struct {
  1159  	From []string `json:"from,omitempty"`
  1160  }
  1161  
  1162  // RequiredStatusChecksEnforcementLevelChanges represents the changes made to the RequiredStatusChecksEnforcementLevel policy.
  1163  type RequiredStatusChecksEnforcementLevelChanges struct {
  1164  	From *string `json:"from,omitempty"`
  1165  }
  1166  
  1167  // SignatureRequirementEnforcementLevelChanges represents the changes made to the SignatureRequirementEnforcementLevel policy.
  1168  type SignatureRequirementEnforcementLevelChanges struct {
  1169  	From *string `json:"from,omitempty"`
  1170  }
  1171  
  1172  // ProtectionRequest represents a request to create/edit a branch's protection.
  1173  type ProtectionRequest struct {
  1174  	RequiredStatusChecks       *RequiredStatusChecks                 `json:"required_status_checks"`
  1175  	RequiredPullRequestReviews *PullRequestReviewsEnforcementRequest `json:"required_pull_request_reviews"`
  1176  	EnforceAdmins              bool                                  `json:"enforce_admins"`
  1177  	Restrictions               *BranchRestrictionsRequest            `json:"restrictions"`
  1178  	// Enforces a linear commit Git history, which prevents anyone from pushing merge commits to a branch.
  1179  	RequireLinearHistory *bool `json:"required_linear_history,omitempty"`
  1180  	// Permits force pushes to the protected branch by anyone with write access to the repository.
  1181  	AllowForcePushes *bool `json:"allow_force_pushes,omitempty"`
  1182  	// Allows deletion of the protected branch by anyone with write access to the repository.
  1183  	AllowDeletions *bool `json:"allow_deletions,omitempty"`
  1184  	// RequiredConversationResolution, if set to true, requires all comments
  1185  	// on the pull request to be resolved before it can be merged to a protected branch.
  1186  	RequiredConversationResolution *bool `json:"required_conversation_resolution,omitempty"`
  1187  	// BlockCreations, if set to true, will cause the restrictions setting to also block pushes
  1188  	// which create new branches, unless initiated by a user, team, app with the ability to push.
  1189  	BlockCreations *bool `json:"block_creations,omitempty"`
  1190  	// LockBranch, if set to true, will prevent users from pushing to the branch.
  1191  	LockBranch *bool `json:"lock_branch,omitempty"`
  1192  	// AllowForkSyncing, if set to true, will allow users to pull changes from upstream
  1193  	// when the branch is locked.
  1194  	AllowForkSyncing *bool `json:"allow_fork_syncing,omitempty"`
  1195  }
  1196  
  1197  // RequiredStatusChecks represents the protection status of a individual branch.
  1198  type RequiredStatusChecks struct {
  1199  	// Require branches to be up to date before merging. (Required.)
  1200  	Strict bool `json:"strict"`
  1201  	// The list of status checks to require in order to merge into this
  1202  	// branch. An empty slice is valid. (Deprecated. Note: only one of
  1203  	// Contexts/Checks can be populated, but at least one must be populated).
  1204  	Contexts *[]string `json:"contexts,omitempty"`
  1205  	// The list of status checks to require in order to merge into this
  1206  	// branch. An empty slice is valid.
  1207  	Checks      *[]*RequiredStatusCheck `json:"checks,omitempty"`
  1208  	ContextsURL *string                 `json:"contexts_url,omitempty"`
  1209  	URL         *string                 `json:"url,omitempty"`
  1210  }
  1211  
  1212  // RequiredStatusChecksRequest represents a request to edit a protected branch's status checks.
  1213  type RequiredStatusChecksRequest struct {
  1214  	Strict *bool `json:"strict,omitempty"`
  1215  	// Deprecated. Note: if both Contexts and Checks are populated,
  1216  	// the GitHub API will only use Checks.
  1217  	Contexts []string               `json:"contexts,omitempty"`
  1218  	Checks   []*RequiredStatusCheck `json:"checks,omitempty"`
  1219  }
  1220  
  1221  // RequiredStatusCheck represents a status check of a protected branch.
  1222  type RequiredStatusCheck struct {
  1223  	// The name of the required check.
  1224  	Context string `json:"context"`
  1225  	// The ID of the GitHub App that must provide this check.
  1226  	// Omit this field to automatically select the GitHub App
  1227  	// that has recently provided this check,
  1228  	// or any app if it was not set by a GitHub App.
  1229  	// Pass -1 to explicitly allow any app to set the status.
  1230  	AppID *int64 `json:"app_id,omitempty"`
  1231  }
  1232  
  1233  // PullRequestReviewsEnforcement represents the pull request reviews enforcement of a protected branch.
  1234  type PullRequestReviewsEnforcement struct {
  1235  	// Allow specific users, teams, or apps to bypass pull request requirements.
  1236  	BypassPullRequestAllowances *BypassPullRequestAllowances `json:"bypass_pull_request_allowances,omitempty"`
  1237  	// Specifies which users, teams and apps can dismiss pull request reviews.
  1238  	DismissalRestrictions *DismissalRestrictions `json:"dismissal_restrictions,omitempty"`
  1239  	// Specifies if approved reviews are dismissed automatically, when a new commit is pushed.
  1240  	DismissStaleReviews bool `json:"dismiss_stale_reviews"`
  1241  	// RequireCodeOwnerReviews specifies if an approved review is required in pull requests including files with a designated code owner.
  1242  	RequireCodeOwnerReviews bool `json:"require_code_owner_reviews"`
  1243  	// RequiredApprovingReviewCount specifies the number of approvals required before the pull request can be merged.
  1244  	// Valid values are 1-6.
  1245  	RequiredApprovingReviewCount int `json:"required_approving_review_count"`
  1246  	// RequireLastPushApproval specifies whether the last pusher to a pull request branch can approve it.
  1247  	RequireLastPushApproval bool `json:"require_last_push_approval"`
  1248  }
  1249  
  1250  // PullRequestReviewsEnforcementRequest represents request to set the pull request review
  1251  // enforcement of a protected branch. It is separate from PullRequestReviewsEnforcement above
  1252  // because the request structure is different from the response structure.
  1253  type PullRequestReviewsEnforcementRequest struct {
  1254  	// Allow specific users, teams, or apps to bypass pull request requirements.
  1255  	BypassPullRequestAllowancesRequest *BypassPullRequestAllowancesRequest `json:"bypass_pull_request_allowances,omitempty"`
  1256  	// Specifies which users, teams and apps should be allowed to dismiss pull request reviews.
  1257  	// User, team and app dismissal restrictions are only available for
  1258  	// organization-owned repositories. Must be nil for personal repositories.
  1259  	DismissalRestrictionsRequest *DismissalRestrictionsRequest `json:"dismissal_restrictions,omitempty"`
  1260  	// Specifies if approved reviews can be dismissed automatically, when a new commit is pushed. (Required)
  1261  	DismissStaleReviews bool `json:"dismiss_stale_reviews"`
  1262  	// RequireCodeOwnerReviews specifies if an approved review is required in pull requests including files with a designated code owner.
  1263  	RequireCodeOwnerReviews bool `json:"require_code_owner_reviews"`
  1264  	// RequiredApprovingReviewCount specifies the number of approvals required before the pull request can be merged.
  1265  	// Valid values are 1-6.
  1266  	RequiredApprovingReviewCount int `json:"required_approving_review_count"`
  1267  	// RequireLastPushApproval specifies whether the last pusher to a pull request branch can approve it.
  1268  	RequireLastPushApproval *bool `json:"require_last_push_approval,omitempty"`
  1269  }
  1270  
  1271  // PullRequestReviewsEnforcementUpdate represents request to patch the pull request review
  1272  // enforcement of a protected branch. It is separate from PullRequestReviewsEnforcementRequest above
  1273  // because the patch request does not require all fields to be initialized.
  1274  type PullRequestReviewsEnforcementUpdate struct {
  1275  	// Allow specific users, teams, or apps to bypass pull request requirements.
  1276  	BypassPullRequestAllowancesRequest *BypassPullRequestAllowancesRequest `json:"bypass_pull_request_allowances,omitempty"`
  1277  	// Specifies which users, teams and apps can dismiss pull request reviews. Can be omitted.
  1278  	DismissalRestrictionsRequest *DismissalRestrictionsRequest `json:"dismissal_restrictions,omitempty"`
  1279  	// Specifies if approved reviews can be dismissed automatically, when a new commit is pushed. Can be omitted.
  1280  	DismissStaleReviews *bool `json:"dismiss_stale_reviews,omitempty"`
  1281  	// RequireCodeOwnerReviews specifies if merging pull requests is blocked until code owners have reviewed.
  1282  	RequireCodeOwnerReviews *bool `json:"require_code_owner_reviews,omitempty"`
  1283  	// RequiredApprovingReviewCount specifies the number of approvals required before the pull request can be merged.
  1284  	// Valid values are 1 - 6 or 0 to not require reviewers.
  1285  	RequiredApprovingReviewCount int `json:"required_approving_review_count"`
  1286  	// RequireLastPushApproval specifies whether the last pusher to a pull request branch can approve it.
  1287  	RequireLastPushApproval *bool `json:"require_last_push_approval,omitempty"`
  1288  }
  1289  
  1290  // RequireLinearHistory represents the configuration to enforce branches with no merge commit.
  1291  type RequireLinearHistory struct {
  1292  	Enabled bool `json:"enabled"`
  1293  }
  1294  
  1295  // AllowDeletions represents the configuration to accept deletion of protected branches.
  1296  type AllowDeletions struct {
  1297  	Enabled bool `json:"enabled"`
  1298  }
  1299  
  1300  // AllowForcePushes represents the configuration to accept forced pushes on protected branches.
  1301  type AllowForcePushes struct {
  1302  	Enabled bool `json:"enabled"`
  1303  }
  1304  
  1305  // RequiredConversationResolution requires all comments on the pull request to be resolved before it can be
  1306  // merged to a protected branch when enabled.
  1307  type RequiredConversationResolution struct {
  1308  	Enabled bool `json:"enabled"`
  1309  }
  1310  
  1311  // AdminEnforcement represents the configuration to enforce required status checks for repository administrators.
  1312  type AdminEnforcement struct {
  1313  	URL     *string `json:"url,omitempty"`
  1314  	Enabled bool    `json:"enabled"`
  1315  }
  1316  
  1317  // BranchRestrictions represents the restriction that only certain users or
  1318  // teams may push to a branch.
  1319  type BranchRestrictions struct {
  1320  	// The list of user logins with push access.
  1321  	Users []*User `json:"users"`
  1322  	// The list of team slugs with push access.
  1323  	Teams []*Team `json:"teams"`
  1324  	// The list of app slugs with push access.
  1325  	Apps []*App `json:"apps"`
  1326  }
  1327  
  1328  // BranchRestrictionsRequest represents the request to create/edit the
  1329  // restriction that only certain users or teams may push to a branch. It is
  1330  // separate from BranchRestrictions above because the request structure is
  1331  // different from the response structure.
  1332  type BranchRestrictionsRequest struct {
  1333  	// The list of user logins with push access. (Required; use []string{} instead of nil for empty list.)
  1334  	Users []string `json:"users"`
  1335  	// The list of team slugs with push access. (Required; use []string{} instead of nil for empty list.)
  1336  	Teams []string `json:"teams"`
  1337  	// The list of app slugs with push access.
  1338  	Apps []string `json:"apps"`
  1339  }
  1340  
  1341  // BypassPullRequestAllowances represents the people, teams, or apps who are allowed to bypass required pull requests.
  1342  type BypassPullRequestAllowances struct {
  1343  	// The list of users allowed to bypass pull request requirements.
  1344  	Users []*User `json:"users"`
  1345  	// The list of teams allowed to bypass pull request requirements.
  1346  	Teams []*Team `json:"teams"`
  1347  	// The list of apps allowed to bypass pull request requirements.
  1348  	Apps []*App `json:"apps"`
  1349  }
  1350  
  1351  // BypassPullRequestAllowancesRequest represents the people, teams, or apps who are
  1352  // allowed to bypass required pull requests.
  1353  // It is separate from BypassPullRequestAllowances above because the request structure is
  1354  // different from the response structure.
  1355  type BypassPullRequestAllowancesRequest struct {
  1356  	// The list of user logins allowed to bypass pull request requirements.
  1357  	Users []string `json:"users"`
  1358  	// The list of team slugs allowed to bypass pull request requirements.
  1359  	Teams []string `json:"teams"`
  1360  	// The list of app slugs allowed to bypass pull request requirements.
  1361  	Apps []string `json:"apps"`
  1362  }
  1363  
  1364  // DismissalRestrictions specifies which users and teams can dismiss pull request reviews.
  1365  type DismissalRestrictions struct {
  1366  	// The list of users who can dimiss pull request reviews.
  1367  	Users []*User `json:"users"`
  1368  	// The list of teams which can dismiss pull request reviews.
  1369  	Teams []*Team `json:"teams"`
  1370  	// The list of apps which can dismiss pull request reviews.
  1371  	Apps []*App `json:"apps"`
  1372  }
  1373  
  1374  // DismissalRestrictionsRequest represents the request to create/edit the
  1375  // restriction to allows only specific users, teams or apps to dimiss pull request reviews. It is
  1376  // separate from DismissalRestrictions above because the request structure is
  1377  // different from the response structure.
  1378  // Note: Both Users and Teams must be nil, or both must be non-nil.
  1379  type DismissalRestrictionsRequest struct {
  1380  	// The list of user logins who can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.)
  1381  	Users *[]string `json:"users,omitempty"`
  1382  	// The list of team slugs which can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.)
  1383  	Teams *[]string `json:"teams,omitempty"`
  1384  	// The list of app slugs which can dismiss pull request reviews. (Required; use nil to disable dismissal_restrictions or &[]string{} otherwise.)
  1385  	Apps *[]string `json:"apps,omitempty"`
  1386  }
  1387  
  1388  // SignaturesProtectedBranch represents the protection status of an individual branch.
  1389  type SignaturesProtectedBranch struct {
  1390  	URL *string `json:"url,omitempty"`
  1391  	// Commits pushed to matching branches must have verified signatures.
  1392  	Enabled *bool `json:"enabled,omitempty"`
  1393  }
  1394  
  1395  // AutomatedSecurityFixes represents their status.
  1396  type AutomatedSecurityFixes struct {
  1397  	Enabled *bool `json:"enabled"`
  1398  	Paused  *bool `json:"paused"`
  1399  }
  1400  
  1401  // ListBranches lists branches for the specified repository.
  1402  //
  1403  // GitHub API docs: https://docs.github.com/rest/branches/branches#list-branches
  1404  //
  1405  //meta:operation GET /repos/{owner}/{repo}/branches
  1406  func (s *RepositoriesService) ListBranches(ctx context.Context, owner string, repo string, opts *BranchListOptions) ([]*Branch, *Response, error) {
  1407  	u := fmt.Sprintf("repos/%v/%v/branches", owner, repo)
  1408  	u, err := addOptions(u, opts)
  1409  	if err != nil {
  1410  		return nil, nil, err
  1411  	}
  1412  
  1413  	req, err := s.client.NewRequest("GET", u, nil)
  1414  	if err != nil {
  1415  		return nil, nil, err
  1416  	}
  1417  
  1418  	var branches []*Branch
  1419  	resp, err := s.client.Do(ctx, req, &branches)
  1420  	if err != nil {
  1421  		return nil, resp, err
  1422  	}
  1423  
  1424  	return branches, resp, nil
  1425  }
  1426  
  1427  // GetBranch gets the specified branch for a repository.
  1428  //
  1429  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1430  //
  1431  // GitHub API docs: https://docs.github.com/rest/branches/branches#get-a-branch
  1432  //
  1433  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}
  1434  func (s *RepositoriesService) GetBranch(ctx context.Context, owner, repo, branch string, maxRedirects int) (*Branch, *Response, error) {
  1435  	u := fmt.Sprintf("repos/%v/%v/branches/%v", owner, repo, url.PathEscape(branch))
  1436  
  1437  	resp, err := s.client.roundTripWithOptionalFollowRedirect(ctx, u, maxRedirects)
  1438  	if err != nil {
  1439  		return nil, nil, err
  1440  	}
  1441  	defer resp.Body.Close()
  1442  
  1443  	if resp.StatusCode != http.StatusOK {
  1444  		return nil, newResponse(resp), fmt.Errorf("unexpected status code: %s", resp.Status)
  1445  	}
  1446  
  1447  	b := new(Branch)
  1448  	err = json.NewDecoder(resp.Body).Decode(b)
  1449  	return b, newResponse(resp), err
  1450  }
  1451  
  1452  // renameBranchRequest represents a request to rename a branch.
  1453  type renameBranchRequest struct {
  1454  	NewName string `json:"new_name"`
  1455  }
  1456  
  1457  // RenameBranch renames a branch in a repository.
  1458  //
  1459  // To rename a non-default branch: Users must have push access. GitHub Apps must have the `contents:write` repository permission.
  1460  // To rename the default branch: Users must have admin or owner permissions. GitHub Apps must have the `administration:write` repository permission.
  1461  //
  1462  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1463  //
  1464  // GitHub API docs: https://docs.github.com/rest/branches/branches#rename-a-branch
  1465  //
  1466  //meta:operation POST /repos/{owner}/{repo}/branches/{branch}/rename
  1467  func (s *RepositoriesService) RenameBranch(ctx context.Context, owner, repo, branch, newName string) (*Branch, *Response, error) {
  1468  	u := fmt.Sprintf("repos/%v/%v/branches/%v/rename", owner, repo, url.PathEscape(branch))
  1469  	r := &renameBranchRequest{NewName: newName}
  1470  	req, err := s.client.NewRequest("POST", u, r)
  1471  	if err != nil {
  1472  		return nil, nil, err
  1473  	}
  1474  
  1475  	b := new(Branch)
  1476  	resp, err := s.client.Do(ctx, req, b)
  1477  	if err != nil {
  1478  		return nil, resp, err
  1479  	}
  1480  
  1481  	return b, resp, nil
  1482  }
  1483  
  1484  // GetBranchProtection gets the protection of a given branch.
  1485  //
  1486  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1487  //
  1488  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-branch-protection
  1489  //
  1490  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection
  1491  func (s *RepositoriesService) GetBranchProtection(ctx context.Context, owner, repo, branch string) (*Protection, *Response, error) {
  1492  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, url.PathEscape(branch))
  1493  	req, err := s.client.NewRequest("GET", u, nil)
  1494  	if err != nil {
  1495  		return nil, nil, err
  1496  	}
  1497  
  1498  	// TODO: remove custom Accept header when this API fully launches
  1499  	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
  1500  
  1501  	p := new(Protection)
  1502  	resp, err := s.client.Do(ctx, req, p)
  1503  	if err != nil {
  1504  		if isBranchNotProtected(err) {
  1505  			err = ErrBranchNotProtected
  1506  		}
  1507  		return nil, resp, err
  1508  	}
  1509  
  1510  	return p, resp, nil
  1511  }
  1512  
  1513  // GetRequiredStatusChecks gets the required status checks for a given protected branch.
  1514  //
  1515  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1516  //
  1517  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-status-checks-protection
  1518  //
  1519  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks
  1520  func (s *RepositoriesService) GetRequiredStatusChecks(ctx context.Context, owner, repo, branch string) (*RequiredStatusChecks, *Response, error) {
  1521  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks", owner, repo, url.PathEscape(branch))
  1522  	req, err := s.client.NewRequest("GET", u, nil)
  1523  	if err != nil {
  1524  		return nil, nil, err
  1525  	}
  1526  
  1527  	p := new(RequiredStatusChecks)
  1528  	resp, err := s.client.Do(ctx, req, p)
  1529  	if err != nil {
  1530  		if isBranchNotProtected(err) {
  1531  			err = ErrBranchNotProtected
  1532  		}
  1533  		return nil, resp, err
  1534  	}
  1535  
  1536  	return p, resp, nil
  1537  }
  1538  
  1539  // ListRequiredStatusChecksContexts lists the required status checks contexts for a given protected branch.
  1540  //
  1541  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1542  //
  1543  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-all-status-check-contexts
  1544  //
  1545  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks/contexts
  1546  func (s *RepositoriesService) ListRequiredStatusChecksContexts(ctx context.Context, owner, repo, branch string) (contexts []string, resp *Response, err error) {
  1547  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks/contexts", owner, repo, url.PathEscape(branch))
  1548  	req, err := s.client.NewRequest("GET", u, nil)
  1549  	if err != nil {
  1550  		return nil, nil, err
  1551  	}
  1552  
  1553  	resp, err = s.client.Do(ctx, req, &contexts)
  1554  	if err != nil {
  1555  		if isBranchNotProtected(err) {
  1556  			err = ErrBranchNotProtected
  1557  		}
  1558  		return nil, resp, err
  1559  	}
  1560  
  1561  	return contexts, resp, nil
  1562  }
  1563  
  1564  // UpdateBranchProtection updates the protection of a given branch.
  1565  //
  1566  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1567  //
  1568  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#update-branch-protection
  1569  //
  1570  //meta:operation PUT /repos/{owner}/{repo}/branches/{branch}/protection
  1571  func (s *RepositoriesService) UpdateBranchProtection(ctx context.Context, owner, repo, branch string, preq *ProtectionRequest) (*Protection, *Response, error) {
  1572  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, url.PathEscape(branch))
  1573  	req, err := s.client.NewRequest("PUT", u, preq)
  1574  	if err != nil {
  1575  		return nil, nil, err
  1576  	}
  1577  
  1578  	// TODO: remove custom Accept header when this API fully launches
  1579  	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
  1580  
  1581  	p := new(Protection)
  1582  	resp, err := s.client.Do(ctx, req, p)
  1583  	if err != nil {
  1584  		return nil, resp, err
  1585  	}
  1586  
  1587  	return p, resp, nil
  1588  }
  1589  
  1590  // RemoveBranchProtection removes the protection of a given branch.
  1591  //
  1592  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1593  //
  1594  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#delete-branch-protection
  1595  //
  1596  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection
  1597  func (s *RepositoriesService) RemoveBranchProtection(ctx context.Context, owner, repo, branch string) (*Response, error) {
  1598  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection", owner, repo, url.PathEscape(branch))
  1599  	req, err := s.client.NewRequest("DELETE", u, nil)
  1600  	if err != nil {
  1601  		return nil, err
  1602  	}
  1603  
  1604  	return s.client.Do(ctx, req, nil)
  1605  }
  1606  
  1607  // GetSignaturesProtectedBranch gets required signatures of protected branch.
  1608  //
  1609  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1610  //
  1611  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-commit-signature-protection
  1612  //
  1613  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures
  1614  func (s *RepositoriesService) GetSignaturesProtectedBranch(ctx context.Context, owner, repo, branch string) (*SignaturesProtectedBranch, *Response, error) {
  1615  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_signatures", owner, repo, url.PathEscape(branch))
  1616  	req, err := s.client.NewRequest("GET", u, nil)
  1617  	if err != nil {
  1618  		return nil, nil, err
  1619  	}
  1620  
  1621  	// TODO: remove custom Accept header when this API fully launches
  1622  	req.Header.Set("Accept", mediaTypeSignaturePreview)
  1623  
  1624  	p := new(SignaturesProtectedBranch)
  1625  	resp, err := s.client.Do(ctx, req, p)
  1626  	if err != nil {
  1627  		return nil, resp, err
  1628  	}
  1629  
  1630  	return p, resp, nil
  1631  }
  1632  
  1633  // RequireSignaturesOnProtectedBranch makes signed commits required on a protected branch.
  1634  // It requires admin access and branch protection to be enabled.
  1635  //
  1636  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1637  //
  1638  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#create-commit-signature-protection
  1639  //
  1640  //meta:operation POST /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures
  1641  func (s *RepositoriesService) RequireSignaturesOnProtectedBranch(ctx context.Context, owner, repo, branch string) (*SignaturesProtectedBranch, *Response, error) {
  1642  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_signatures", owner, repo, url.PathEscape(branch))
  1643  	req, err := s.client.NewRequest("POST", u, nil)
  1644  	if err != nil {
  1645  		return nil, nil, err
  1646  	}
  1647  
  1648  	// TODO: remove custom Accept header when this API fully launches
  1649  	req.Header.Set("Accept", mediaTypeSignaturePreview)
  1650  
  1651  	r := new(SignaturesProtectedBranch)
  1652  	resp, err := s.client.Do(ctx, req, r)
  1653  	if err != nil {
  1654  		return nil, resp, err
  1655  	}
  1656  
  1657  	return r, resp, nil
  1658  }
  1659  
  1660  // OptionalSignaturesOnProtectedBranch removes required signed commits on a given branch.
  1661  //
  1662  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1663  //
  1664  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#delete-commit-signature-protection
  1665  //
  1666  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_signatures
  1667  func (s *RepositoriesService) OptionalSignaturesOnProtectedBranch(ctx context.Context, owner, repo, branch string) (*Response, error) {
  1668  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_signatures", owner, repo, url.PathEscape(branch))
  1669  	req, err := s.client.NewRequest("DELETE", u, nil)
  1670  	if err != nil {
  1671  		return nil, err
  1672  	}
  1673  
  1674  	// TODO: remove custom Accept header when this API fully launches
  1675  	req.Header.Set("Accept", mediaTypeSignaturePreview)
  1676  
  1677  	return s.client.Do(ctx, req, nil)
  1678  }
  1679  
  1680  // UpdateRequiredStatusChecks updates the required status checks for a given protected branch.
  1681  //
  1682  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1683  //
  1684  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#update-status-check-protection
  1685  //
  1686  //meta:operation PATCH /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks
  1687  func (s *RepositoriesService) UpdateRequiredStatusChecks(ctx context.Context, owner, repo, branch string, sreq *RequiredStatusChecksRequest) (*RequiredStatusChecks, *Response, error) {
  1688  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks", owner, repo, url.PathEscape(branch))
  1689  	req, err := s.client.NewRequest("PATCH", u, sreq)
  1690  	if err != nil {
  1691  		return nil, nil, err
  1692  	}
  1693  
  1694  	sc := new(RequiredStatusChecks)
  1695  	resp, err := s.client.Do(ctx, req, sc)
  1696  	if err != nil {
  1697  		return nil, resp, err
  1698  	}
  1699  
  1700  	return sc, resp, nil
  1701  }
  1702  
  1703  // RemoveRequiredStatusChecks removes the required status checks for a given protected branch.
  1704  //
  1705  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1706  //
  1707  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#remove-status-check-protection
  1708  //
  1709  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_status_checks
  1710  func (s *RepositoriesService) RemoveRequiredStatusChecks(ctx context.Context, owner, repo, branch string) (*Response, error) {
  1711  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_status_checks", owner, repo, url.PathEscape(branch))
  1712  	req, err := s.client.NewRequest("DELETE", u, nil)
  1713  	if err != nil {
  1714  		return nil, err
  1715  	}
  1716  
  1717  	return s.client.Do(ctx, req, nil)
  1718  }
  1719  
  1720  // License gets the contents of a repository's license if one is detected.
  1721  //
  1722  // GitHub API docs: https://docs.github.com/rest/licenses/licenses#get-the-license-for-a-repository
  1723  //
  1724  //meta:operation GET /repos/{owner}/{repo}/license
  1725  func (s *RepositoriesService) License(ctx context.Context, owner, repo string) (*RepositoryLicense, *Response, error) {
  1726  	u := fmt.Sprintf("repos/%v/%v/license", owner, repo)
  1727  	req, err := s.client.NewRequest("GET", u, nil)
  1728  	if err != nil {
  1729  		return nil, nil, err
  1730  	}
  1731  
  1732  	r := &RepositoryLicense{}
  1733  	resp, err := s.client.Do(ctx, req, r)
  1734  	if err != nil {
  1735  		return nil, resp, err
  1736  	}
  1737  
  1738  	return r, resp, nil
  1739  }
  1740  
  1741  // GetPullRequestReviewEnforcement gets pull request review enforcement of a protected branch.
  1742  //
  1743  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1744  //
  1745  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-pull-request-review-protection
  1746  //
  1747  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews
  1748  func (s *RepositoriesService) GetPullRequestReviewEnforcement(ctx context.Context, owner, repo, branch string) (*PullRequestReviewsEnforcement, *Response, error) {
  1749  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, url.PathEscape(branch))
  1750  	req, err := s.client.NewRequest("GET", u, nil)
  1751  	if err != nil {
  1752  		return nil, nil, err
  1753  	}
  1754  
  1755  	// TODO: remove custom Accept header when this API fully launches
  1756  	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
  1757  
  1758  	r := new(PullRequestReviewsEnforcement)
  1759  	resp, err := s.client.Do(ctx, req, r)
  1760  	if err != nil {
  1761  		return nil, resp, err
  1762  	}
  1763  
  1764  	return r, resp, nil
  1765  }
  1766  
  1767  // UpdatePullRequestReviewEnforcement patches pull request review enforcement of a protected branch.
  1768  // It requires admin access and branch protection to be enabled.
  1769  //
  1770  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1771  //
  1772  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#update-pull-request-review-protection
  1773  //
  1774  //meta:operation PATCH /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews
  1775  func (s *RepositoriesService) UpdatePullRequestReviewEnforcement(ctx context.Context, owner, repo, branch string, patch *PullRequestReviewsEnforcementUpdate) (*PullRequestReviewsEnforcement, *Response, error) {
  1776  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, url.PathEscape(branch))
  1777  	req, err := s.client.NewRequest("PATCH", u, patch)
  1778  	if err != nil {
  1779  		return nil, nil, err
  1780  	}
  1781  
  1782  	// TODO: remove custom Accept header when this API fully launches
  1783  	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
  1784  
  1785  	r := new(PullRequestReviewsEnforcement)
  1786  	resp, err := s.client.Do(ctx, req, r)
  1787  	if err != nil {
  1788  		return nil, resp, err
  1789  	}
  1790  
  1791  	return r, resp, nil
  1792  }
  1793  
  1794  // DisableDismissalRestrictions disables dismissal restrictions of a protected branch.
  1795  // It requires admin access and branch protection to be enabled.
  1796  //
  1797  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1798  //
  1799  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#update-pull-request-review-protection
  1800  //
  1801  //meta:operation PATCH /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews
  1802  func (s *RepositoriesService) DisableDismissalRestrictions(ctx context.Context, owner, repo, branch string) (*PullRequestReviewsEnforcement, *Response, error) {
  1803  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, url.PathEscape(branch))
  1804  
  1805  	data := new(struct {
  1806  		DismissalRestrictionsRequest `json:"dismissal_restrictions"`
  1807  	})
  1808  
  1809  	req, err := s.client.NewRequest("PATCH", u, data)
  1810  	if err != nil {
  1811  		return nil, nil, err
  1812  	}
  1813  
  1814  	// TODO: remove custom Accept header when this API fully launches
  1815  	req.Header.Set("Accept", mediaTypeRequiredApprovingReviewsPreview)
  1816  
  1817  	r := new(PullRequestReviewsEnforcement)
  1818  	resp, err := s.client.Do(ctx, req, r)
  1819  	if err != nil {
  1820  		return nil, resp, err
  1821  	}
  1822  
  1823  	return r, resp, nil
  1824  }
  1825  
  1826  // RemovePullRequestReviewEnforcement removes pull request enforcement of a protected branch.
  1827  //
  1828  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1829  //
  1830  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#delete-pull-request-review-protection
  1831  //
  1832  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection/required_pull_request_reviews
  1833  func (s *RepositoriesService) RemovePullRequestReviewEnforcement(ctx context.Context, owner, repo, branch string) (*Response, error) {
  1834  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/required_pull_request_reviews", owner, repo, url.PathEscape(branch))
  1835  	req, err := s.client.NewRequest("DELETE", u, nil)
  1836  	if err != nil {
  1837  		return nil, err
  1838  	}
  1839  
  1840  	return s.client.Do(ctx, req, nil)
  1841  }
  1842  
  1843  // GetAdminEnforcement gets admin enforcement information of a protected branch.
  1844  //
  1845  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1846  //
  1847  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-admin-branch-protection
  1848  //
  1849  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins
  1850  func (s *RepositoriesService) GetAdminEnforcement(ctx context.Context, owner, repo, branch string) (*AdminEnforcement, *Response, error) {
  1851  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/enforce_admins", owner, repo, url.PathEscape(branch))
  1852  	req, err := s.client.NewRequest("GET", u, nil)
  1853  	if err != nil {
  1854  		return nil, nil, err
  1855  	}
  1856  
  1857  	r := new(AdminEnforcement)
  1858  	resp, err := s.client.Do(ctx, req, r)
  1859  	if err != nil {
  1860  		return nil, resp, err
  1861  	}
  1862  
  1863  	return r, resp, nil
  1864  }
  1865  
  1866  // AddAdminEnforcement adds admin enforcement to a protected branch.
  1867  // It requires admin access and branch protection to be enabled.
  1868  //
  1869  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1870  //
  1871  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#set-admin-branch-protection
  1872  //
  1873  //meta:operation POST /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins
  1874  func (s *RepositoriesService) AddAdminEnforcement(ctx context.Context, owner, repo, branch string) (*AdminEnforcement, *Response, error) {
  1875  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/enforce_admins", owner, repo, url.PathEscape(branch))
  1876  	req, err := s.client.NewRequest("POST", u, nil)
  1877  	if err != nil {
  1878  		return nil, nil, err
  1879  	}
  1880  
  1881  	r := new(AdminEnforcement)
  1882  	resp, err := s.client.Do(ctx, req, r)
  1883  	if err != nil {
  1884  		return nil, resp, err
  1885  	}
  1886  
  1887  	return r, resp, nil
  1888  }
  1889  
  1890  // RemoveAdminEnforcement removes admin enforcement from a protected branch.
  1891  //
  1892  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1893  //
  1894  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#delete-admin-branch-protection
  1895  //
  1896  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection/enforce_admins
  1897  func (s *RepositoriesService) RemoveAdminEnforcement(ctx context.Context, owner, repo, branch string) (*Response, error) {
  1898  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/enforce_admins", owner, repo, url.PathEscape(branch))
  1899  	req, err := s.client.NewRequest("DELETE", u, nil)
  1900  	if err != nil {
  1901  		return nil, err
  1902  	}
  1903  
  1904  	return s.client.Do(ctx, req, nil)
  1905  }
  1906  
  1907  // repositoryTopics represents a collection of repository topics.
  1908  type repositoryTopics struct {
  1909  	Names []string `json:"names"`
  1910  }
  1911  
  1912  // ListAllTopics lists topics for a repository.
  1913  //
  1914  // GitHub API docs: https://docs.github.com/rest/repos/repos#get-all-repository-topics
  1915  //
  1916  //meta:operation GET /repos/{owner}/{repo}/topics
  1917  func (s *RepositoriesService) ListAllTopics(ctx context.Context, owner, repo string) ([]string, *Response, error) {
  1918  	u := fmt.Sprintf("repos/%v/%v/topics", owner, repo)
  1919  	req, err := s.client.NewRequest("GET", u, nil)
  1920  	if err != nil {
  1921  		return nil, nil, err
  1922  	}
  1923  
  1924  	// TODO: remove custom Accept header when this API fully launches.
  1925  	req.Header.Set("Accept", mediaTypeTopicsPreview)
  1926  
  1927  	topics := new(repositoryTopics)
  1928  	resp, err := s.client.Do(ctx, req, topics)
  1929  	if err != nil {
  1930  		return nil, resp, err
  1931  	}
  1932  
  1933  	return topics.Names, resp, nil
  1934  }
  1935  
  1936  // ReplaceAllTopics replaces all repository topics.
  1937  //
  1938  // GitHub API docs: https://docs.github.com/rest/repos/repos#replace-all-repository-topics
  1939  //
  1940  //meta:operation PUT /repos/{owner}/{repo}/topics
  1941  func (s *RepositoriesService) ReplaceAllTopics(ctx context.Context, owner, repo string, topics []string) ([]string, *Response, error) {
  1942  	u := fmt.Sprintf("repos/%v/%v/topics", owner, repo)
  1943  	t := &repositoryTopics{
  1944  		Names: topics,
  1945  	}
  1946  	if t.Names == nil {
  1947  		t.Names = []string{}
  1948  	}
  1949  	req, err := s.client.NewRequest("PUT", u, t)
  1950  	if err != nil {
  1951  		return nil, nil, err
  1952  	}
  1953  
  1954  	// TODO: remove custom Accept header when this API fully launches.
  1955  	req.Header.Set("Accept", mediaTypeTopicsPreview)
  1956  
  1957  	t = new(repositoryTopics)
  1958  	resp, err := s.client.Do(ctx, req, t)
  1959  	if err != nil {
  1960  		return nil, resp, err
  1961  	}
  1962  
  1963  	return t.Names, resp, nil
  1964  }
  1965  
  1966  // ListApps lists the GitHub apps that have push access to a given protected branch.
  1967  // It requires the GitHub apps to have `write` access to the `content` permission.
  1968  //
  1969  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  1970  //
  1971  // Deprecated: Please use ListAppRestrictions instead.
  1972  //
  1973  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-apps-with-access-to-the-protected-branch
  1974  //
  1975  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps
  1976  func (s *RepositoriesService) ListApps(ctx context.Context, owner, repo, branch string) ([]*App, *Response, error) {
  1977  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, url.PathEscape(branch))
  1978  	req, err := s.client.NewRequest("GET", u, nil)
  1979  	if err != nil {
  1980  		return nil, nil, err
  1981  	}
  1982  
  1983  	var apps []*App
  1984  	resp, err := s.client.Do(ctx, req, &apps)
  1985  	if err != nil {
  1986  		return nil, resp, err
  1987  	}
  1988  
  1989  	return apps, resp, nil
  1990  }
  1991  
  1992  // ListAppRestrictions lists the GitHub apps that have push access to a given protected branch.
  1993  // It requires the GitHub apps to have `write` access to the `content` permission.
  1994  //
  1995  // Note: This is a wrapper around ListApps so a naming convention with ListUserRestrictions and ListTeamRestrictions is preserved.
  1996  //
  1997  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-apps-with-access-to-the-protected-branch
  1998  //
  1999  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps
  2000  func (s *RepositoriesService) ListAppRestrictions(ctx context.Context, owner, repo, branch string) ([]*App, *Response, error) {
  2001  	return s.ListApps(ctx, owner, repo, branch)
  2002  }
  2003  
  2004  // ReplaceAppRestrictions replaces the apps that have push access to a given protected branch.
  2005  // It removes all apps that previously had push access and grants push access to the new list of apps.
  2006  // It requires the GitHub apps to have `write` access to the `content` permission.
  2007  //
  2008  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2009  //
  2010  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2011  //
  2012  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#set-app-access-restrictions
  2013  //
  2014  //meta:operation PUT /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps
  2015  func (s *RepositoriesService) ReplaceAppRestrictions(ctx context.Context, owner, repo, branch string, apps []string) ([]*App, *Response, error) {
  2016  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, url.PathEscape(branch))
  2017  	req, err := s.client.NewRequest("PUT", u, apps)
  2018  	if err != nil {
  2019  		return nil, nil, err
  2020  	}
  2021  
  2022  	var newApps []*App
  2023  	resp, err := s.client.Do(ctx, req, &newApps)
  2024  	if err != nil {
  2025  		return nil, resp, err
  2026  	}
  2027  
  2028  	return newApps, resp, nil
  2029  }
  2030  
  2031  // AddAppRestrictions grants the specified apps push access to a given protected branch.
  2032  // It requires the GitHub apps to have `write` access to the `content` permission.
  2033  //
  2034  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2035  //
  2036  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2037  //
  2038  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#add-app-access-restrictions
  2039  //
  2040  //meta:operation POST /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps
  2041  func (s *RepositoriesService) AddAppRestrictions(ctx context.Context, owner, repo, branch string, apps []string) ([]*App, *Response, error) {
  2042  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, url.PathEscape(branch))
  2043  	req, err := s.client.NewRequest("POST", u, apps)
  2044  	if err != nil {
  2045  		return nil, nil, err
  2046  	}
  2047  
  2048  	var newApps []*App
  2049  	resp, err := s.client.Do(ctx, req, &newApps)
  2050  	if err != nil {
  2051  		return nil, resp, err
  2052  	}
  2053  
  2054  	return newApps, resp, nil
  2055  }
  2056  
  2057  // RemoveAppRestrictions removes the restrictions of an app from pushing to this branch.
  2058  // It requires the GitHub apps to have `write` access to the `content` permission.
  2059  //
  2060  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2061  //
  2062  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2063  //
  2064  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#remove-app-access-restrictions
  2065  //
  2066  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/apps
  2067  func (s *RepositoriesService) RemoveAppRestrictions(ctx context.Context, owner, repo, branch string, apps []string) ([]*App, *Response, error) {
  2068  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/apps", owner, repo, url.PathEscape(branch))
  2069  	req, err := s.client.NewRequest("DELETE", u, apps)
  2070  	if err != nil {
  2071  		return nil, nil, err
  2072  	}
  2073  
  2074  	var newApps []*App
  2075  	resp, err := s.client.Do(ctx, req, &newApps)
  2076  	if err != nil {
  2077  		return nil, resp, err
  2078  	}
  2079  
  2080  	return newApps, resp, nil
  2081  }
  2082  
  2083  // ListTeamRestrictions lists the GitHub teams that have push access to a given protected branch.
  2084  // It requires the GitHub teams to have `write` access to the `content` permission.
  2085  //
  2086  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2087  //
  2088  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-teams-with-access-to-the-protected-branch
  2089  //
  2090  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams
  2091  func (s *RepositoriesService) ListTeamRestrictions(ctx context.Context, owner, repo, branch string) ([]*Team, *Response, error) {
  2092  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/teams", owner, repo, url.PathEscape(branch))
  2093  	req, err := s.client.NewRequest("GET", u, nil)
  2094  	if err != nil {
  2095  		return nil, nil, err
  2096  	}
  2097  
  2098  	var teams []*Team
  2099  	resp, err := s.client.Do(ctx, req, &teams)
  2100  	if err != nil {
  2101  		return nil, resp, err
  2102  	}
  2103  
  2104  	return teams, resp, nil
  2105  }
  2106  
  2107  // ReplaceTeamRestrictions replaces the team that have push access to a given protected branch.
  2108  // This removes all teams that previously had push access and grants push access to the new list of teams.
  2109  // It requires the GitHub teams to have `write` access to the `content` permission.
  2110  //
  2111  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2112  //
  2113  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2114  //
  2115  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#set-team-access-restrictions
  2116  //
  2117  //meta:operation PUT /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams
  2118  func (s *RepositoriesService) ReplaceTeamRestrictions(ctx context.Context, owner, repo, branch string, teams []string) ([]*Team, *Response, error) {
  2119  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/teams", owner, repo, url.PathEscape(branch))
  2120  	req, err := s.client.NewRequest("PUT", u, teams)
  2121  	if err != nil {
  2122  		return nil, nil, err
  2123  	}
  2124  
  2125  	var newTeams []*Team
  2126  	resp, err := s.client.Do(ctx, req, &newTeams)
  2127  	if err != nil {
  2128  		return nil, resp, err
  2129  	}
  2130  
  2131  	return newTeams, resp, nil
  2132  }
  2133  
  2134  // AddTeamRestrictions grants the specified teams push access to a given protected branch.
  2135  // It requires the GitHub teams to have `write` access to the `content` permission.
  2136  //
  2137  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2138  //
  2139  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2140  //
  2141  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#add-team-access-restrictions
  2142  //
  2143  //meta:operation POST /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams
  2144  func (s *RepositoriesService) AddTeamRestrictions(ctx context.Context, owner, repo, branch string, teams []string) ([]*Team, *Response, error) {
  2145  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/teams", owner, repo, url.PathEscape(branch))
  2146  	req, err := s.client.NewRequest("POST", u, teams)
  2147  	if err != nil {
  2148  		return nil, nil, err
  2149  	}
  2150  
  2151  	var newTeams []*Team
  2152  	resp, err := s.client.Do(ctx, req, &newTeams)
  2153  	if err != nil {
  2154  		return nil, resp, err
  2155  	}
  2156  
  2157  	return newTeams, resp, nil
  2158  }
  2159  
  2160  // RemoveTeamRestrictions removes the restrictions of a team from pushing to this branch.
  2161  // It requires the GitHub teams to have `write` access to the `content` permission.
  2162  //
  2163  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2164  //
  2165  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2166  //
  2167  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#remove-team-access-restrictions
  2168  //
  2169  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/teams
  2170  func (s *RepositoriesService) RemoveTeamRestrictions(ctx context.Context, owner, repo, branch string, teams []string) ([]*Team, *Response, error) {
  2171  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/teams", owner, repo, url.PathEscape(branch))
  2172  	req, err := s.client.NewRequest("DELETE", u, teams)
  2173  	if err != nil {
  2174  		return nil, nil, err
  2175  	}
  2176  
  2177  	var newTeams []*Team
  2178  	resp, err := s.client.Do(ctx, req, &newTeams)
  2179  	if err != nil {
  2180  		return nil, resp, err
  2181  	}
  2182  
  2183  	return newTeams, resp, nil
  2184  }
  2185  
  2186  // ListUserRestrictions lists the GitHub users that have push access to a given protected branch.
  2187  // It requires the GitHub users to have `write` access to the `content` permission.
  2188  //
  2189  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2190  //
  2191  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#get-users-with-access-to-the-protected-branch
  2192  //
  2193  //meta:operation GET /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users
  2194  func (s *RepositoriesService) ListUserRestrictions(ctx context.Context, owner, repo, branch string) ([]*User, *Response, error) {
  2195  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/users", owner, repo, url.PathEscape(branch))
  2196  	req, err := s.client.NewRequest("GET", u, nil)
  2197  	if err != nil {
  2198  		return nil, nil, err
  2199  	}
  2200  
  2201  	var users []*User
  2202  	resp, err := s.client.Do(ctx, req, &users)
  2203  	if err != nil {
  2204  		return nil, resp, err
  2205  	}
  2206  
  2207  	return users, resp, nil
  2208  }
  2209  
  2210  // ReplaceUserRestrictions replaces the user that have push access to a given protected branch.
  2211  // It removes all users that previously had push access and grants push access to the new list of users.
  2212  // It requires the GitHub users to have `write` access to the `content` permission.
  2213  //
  2214  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2215  //
  2216  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2217  //
  2218  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#set-user-access-restrictions
  2219  //
  2220  //meta:operation PUT /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users
  2221  func (s *RepositoriesService) ReplaceUserRestrictions(ctx context.Context, owner, repo, branch string, users []string) ([]*User, *Response, error) {
  2222  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/users", owner, repo, url.PathEscape(branch))
  2223  	req, err := s.client.NewRequest("PUT", u, users)
  2224  	if err != nil {
  2225  		return nil, nil, err
  2226  	}
  2227  
  2228  	var newUsers []*User
  2229  	resp, err := s.client.Do(ctx, req, &newUsers)
  2230  	if err != nil {
  2231  		return nil, resp, err
  2232  	}
  2233  
  2234  	return newUsers, resp, nil
  2235  }
  2236  
  2237  // AddUserRestrictions grants the specified users push access to a given protected branch.
  2238  // It requires the GitHub users to have `write` access to the `content` permission.
  2239  //
  2240  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2241  //
  2242  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2243  //
  2244  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#add-user-access-restrictions
  2245  //
  2246  //meta:operation POST /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users
  2247  func (s *RepositoriesService) AddUserRestrictions(ctx context.Context, owner, repo, branch string, users []string) ([]*User, *Response, error) {
  2248  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/users", owner, repo, url.PathEscape(branch))
  2249  	req, err := s.client.NewRequest("POST", u, users)
  2250  	if err != nil {
  2251  		return nil, nil, err
  2252  	}
  2253  
  2254  	var newUsers []*User
  2255  	resp, err := s.client.Do(ctx, req, &newUsers)
  2256  	if err != nil {
  2257  		return nil, resp, err
  2258  	}
  2259  
  2260  	return newUsers, resp, nil
  2261  }
  2262  
  2263  // RemoveUserRestrictions removes the restrictions of a user from pushing to this branch.
  2264  // It requires the GitHub users to have `write` access to the `content` permission.
  2265  //
  2266  // Note: The list of users, apps, and teams in total is limited to 100 items.
  2267  //
  2268  // Note: the branch name is URL path escaped for you. See: https://pkg.go.dev/net/url#PathEscape .
  2269  //
  2270  // GitHub API docs: https://docs.github.com/rest/branches/branch-protection#remove-user-access-restrictions
  2271  //
  2272  //meta:operation DELETE /repos/{owner}/{repo}/branches/{branch}/protection/restrictions/users
  2273  func (s *RepositoriesService) RemoveUserRestrictions(ctx context.Context, owner, repo, branch string, users []string) ([]*User, *Response, error) {
  2274  	u := fmt.Sprintf("repos/%v/%v/branches/%v/protection/restrictions/users", owner, repo, url.PathEscape(branch))
  2275  	req, err := s.client.NewRequest("DELETE", u, users)
  2276  	if err != nil {
  2277  		return nil, nil, err
  2278  	}
  2279  
  2280  	var newUsers []*User
  2281  	resp, err := s.client.Do(ctx, req, &newUsers)
  2282  	if err != nil {
  2283  		return nil, resp, err
  2284  	}
  2285  
  2286  	return newUsers, resp, nil
  2287  }
  2288  
  2289  // TransferRequest represents a request to transfer a repository.
  2290  type TransferRequest struct {
  2291  	NewOwner string  `json:"new_owner"`
  2292  	NewName  *string `json:"new_name,omitempty"`
  2293  	TeamID   []int64 `json:"team_ids,omitempty"`
  2294  }
  2295  
  2296  // Transfer transfers a repository from one account or organization to another.
  2297  //
  2298  // This method might return an *AcceptedError and a status code of
  2299  // 202. This is because this is the status that GitHub returns to signify that
  2300  // it has now scheduled the transfer of the repository in a background task.
  2301  // A follow up request, after a delay of a second or so, should result
  2302  // in a successful request.
  2303  //
  2304  // GitHub API docs: https://docs.github.com/rest/repos/repos#transfer-a-repository
  2305  //
  2306  //meta:operation POST /repos/{owner}/{repo}/transfer
  2307  func (s *RepositoriesService) Transfer(ctx context.Context, owner, repo string, transfer TransferRequest) (*Repository, *Response, error) {
  2308  	u := fmt.Sprintf("repos/%v/%v/transfer", owner, repo)
  2309  
  2310  	req, err := s.client.NewRequest("POST", u, &transfer)
  2311  	if err != nil {
  2312  		return nil, nil, err
  2313  	}
  2314  
  2315  	r := new(Repository)
  2316  	resp, err := s.client.Do(ctx, req, r)
  2317  	if err != nil {
  2318  		return nil, resp, err
  2319  	}
  2320  
  2321  	return r, resp, nil
  2322  }
  2323  
  2324  // DispatchRequestOptions represents a request to trigger a repository_dispatch event.
  2325  type DispatchRequestOptions struct {
  2326  	// EventType is a custom webhook event name. (Required.)
  2327  	EventType string `json:"event_type"`
  2328  	// ClientPayload is a custom JSON payload with extra information about the webhook event.
  2329  	// Defaults to an empty JSON object.
  2330  	ClientPayload *json.RawMessage `json:"client_payload,omitempty"`
  2331  }
  2332  
  2333  // Dispatch triggers a repository_dispatch event in a GitHub Actions workflow.
  2334  //
  2335  // GitHub API docs: https://docs.github.com/rest/repos/repos#create-a-repository-dispatch-event
  2336  //
  2337  //meta:operation POST /repos/{owner}/{repo}/dispatches
  2338  func (s *RepositoriesService) Dispatch(ctx context.Context, owner, repo string, opts DispatchRequestOptions) (*Repository, *Response, error) {
  2339  	u := fmt.Sprintf("repos/%v/%v/dispatches", owner, repo)
  2340  
  2341  	req, err := s.client.NewRequest("POST", u, &opts)
  2342  	if err != nil {
  2343  		return nil, nil, err
  2344  	}
  2345  
  2346  	r := new(Repository)
  2347  	resp, err := s.client.Do(ctx, req, r)
  2348  	if err != nil {
  2349  		return nil, resp, err
  2350  	}
  2351  
  2352  	return r, resp, nil
  2353  }
  2354  
  2355  // isBranchNotProtected determines whether a branch is not protected
  2356  // based on the error message returned by GitHub API.
  2357  func isBranchNotProtected(err error) bool {
  2358  	errorResponse, ok := err.(*ErrorResponse)
  2359  	return ok && errorResponse.Message == githubBranchNotProtected
  2360  }
  2361  
  2362  // EnablePrivateReporting enables private reporting of vulnerabilities for a
  2363  // repository.
  2364  //
  2365  // GitHub API docs: https://docs.github.com/rest/repos/repos#enable-private-vulnerability-reporting-for-a-repository
  2366  //
  2367  //meta:operation PUT /repos/{owner}/{repo}/private-vulnerability-reporting
  2368  func (s *RepositoriesService) EnablePrivateReporting(ctx context.Context, owner, repo string) (*Response, error) {
  2369  	u := fmt.Sprintf("repos/%v/%v/private-vulnerability-reporting", owner, repo)
  2370  
  2371  	req, err := s.client.NewRequest("PUT", u, nil)
  2372  	if err != nil {
  2373  		return nil, err
  2374  	}
  2375  
  2376  	resp, err := s.client.Do(ctx, req, nil)
  2377  	if err != nil {
  2378  		return resp, err
  2379  	}
  2380  
  2381  	return resp, nil
  2382  }
  2383  
  2384  // DisablePrivateReporting disables private reporting of vulnerabilities for a
  2385  // repository.
  2386  //
  2387  // GitHub API docs: https://docs.github.com/rest/repos/repos#disable-private-vulnerability-reporting-for-a-repository
  2388  //
  2389  //meta:operation DELETE /repos/{owner}/{repo}/private-vulnerability-reporting
  2390  func (s *RepositoriesService) DisablePrivateReporting(ctx context.Context, owner, repo string) (*Response, error) {
  2391  	u := fmt.Sprintf("repos/%v/%v/private-vulnerability-reporting", owner, repo)
  2392  
  2393  	req, err := s.client.NewRequest("DELETE", u, nil)
  2394  	if err != nil {
  2395  		return nil, err
  2396  	}
  2397  
  2398  	resp, err := s.client.Do(ctx, req, nil)
  2399  	if err != nil {
  2400  		return resp, err
  2401  	}
  2402  
  2403  	return resp, nil
  2404  }
  2405  
  2406  // checkPrivateReporting represents whether private vulnerability reporting is enabled.
  2407  type checkPrivateReporting struct {
  2408  	Enabled bool `json:"enabled,omitempty"`
  2409  }
  2410  
  2411  // IsPrivateReportingEnabled checks if private vulnerability reporting is enabled
  2412  // for the repository and returns a boolean indicating the status.
  2413  //
  2414  // GitHub API docs: https://docs.github.com/rest/repos/repos#check-if-private-vulnerability-reporting-is-enabled-for-a-repository
  2415  //
  2416  //meta:operation GET /repos/{owner}/{repo}/private-vulnerability-reporting
  2417  func (s *RepositoriesService) IsPrivateReportingEnabled(ctx context.Context, owner, repo string) (bool, *Response, error) {
  2418  	u := fmt.Sprintf("repos/%v/%v/private-vulnerability-reporting", owner, repo)
  2419  
  2420  	req, err := s.client.NewRequest("GET", u, nil)
  2421  	if err != nil {
  2422  		return false, nil, err
  2423  	}
  2424  
  2425  	privateReporting := new(checkPrivateReporting)
  2426  	resp, err := s.client.Do(ctx, req, privateReporting)
  2427  	return privateReporting.Enabled, resp, err
  2428  }