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

     1  // Copyright 2020 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  	"fmt"
    11  	"strconv"
    12  	"strings"
    13  )
    14  
    15  // CodeScanningService handles communication with the code scanning related
    16  // methods of the GitHub API.
    17  //
    18  // GitHub API docs: https://docs.github.com/rest/code-scanning
    19  type CodeScanningService service
    20  
    21  // Rule represents the complete details of GitHub Code Scanning alert type.
    22  type Rule struct {
    23  	ID                    *string  `json:"id,omitempty"`
    24  	Severity              *string  `json:"severity,omitempty"`
    25  	Description           *string  `json:"description,omitempty"`
    26  	Name                  *string  `json:"name,omitempty"`
    27  	SecuritySeverityLevel *string  `json:"security_severity_level,omitempty"`
    28  	FullDescription       *string  `json:"full_description,omitempty"`
    29  	Tags                  []string `json:"tags,omitempty"`
    30  	Help                  *string  `json:"help,omitempty"`
    31  }
    32  
    33  // Location represents the exact location of the GitHub Code Scanning Alert in the scanned project.
    34  type Location struct {
    35  	Path        *string `json:"path,omitempty"`
    36  	StartLine   *int    `json:"start_line,omitempty"`
    37  	EndLine     *int    `json:"end_line,omitempty"`
    38  	StartColumn *int    `json:"start_column,omitempty"`
    39  	EndColumn   *int    `json:"end_column,omitempty"`
    40  }
    41  
    42  // Message is a part of MostRecentInstance struct which provides the appropriate message when any action is performed on the analysis object.
    43  type Message struct {
    44  	Text *string `json:"text,omitempty"`
    45  }
    46  
    47  // MostRecentInstance provides details of the most recent instance of this alert for the default branch or for the specified Git reference.
    48  type MostRecentInstance struct {
    49  	Ref             *string   `json:"ref,omitempty"`
    50  	AnalysisKey     *string   `json:"analysis_key,omitempty"`
    51  	Category        *string   `json:"category,omitempty"`
    52  	Environment     *string   `json:"environment,omitempty"`
    53  	State           *string   `json:"state,omitempty"`
    54  	CommitSHA       *string   `json:"commit_sha,omitempty"`
    55  	Message         *Message  `json:"message,omitempty"`
    56  	Location        *Location `json:"location,omitempty"`
    57  	HTMLURL         *string   `json:"html_url,omitempty"`
    58  	Classifications []string  `json:"classifications,omitempty"`
    59  }
    60  
    61  // Tool represents the tool used to generate a GitHub Code Scanning Alert.
    62  type Tool struct {
    63  	Name    *string `json:"name,omitempty"`
    64  	GUID    *string `json:"guid,omitempty"`
    65  	Version *string `json:"version,omitempty"`
    66  }
    67  
    68  // Alert represents an individual GitHub Code Scanning Alert on a single repository.
    69  //
    70  // GitHub API docs: https://docs.github.com/rest/code-scanning
    71  type Alert struct {
    72  	Number             *int                  `json:"number,omitempty"`
    73  	Repository         *Repository           `json:"repository,omitempty"`
    74  	RuleID             *string               `json:"rule_id,omitempty"`
    75  	RuleSeverity       *string               `json:"rule_severity,omitempty"`
    76  	RuleDescription    *string               `json:"rule_description,omitempty"`
    77  	Rule               *Rule                 `json:"rule,omitempty"`
    78  	Tool               *Tool                 `json:"tool,omitempty"`
    79  	CreatedAt          *Timestamp            `json:"created_at,omitempty"`
    80  	UpdatedAt          *Timestamp            `json:"updated_at,omitempty"`
    81  	FixedAt            *Timestamp            `json:"fixed_at,omitempty"`
    82  	State              *string               `json:"state,omitempty"`
    83  	ClosedBy           *User                 `json:"closed_by,omitempty"`
    84  	ClosedAt           *Timestamp            `json:"closed_at,omitempty"`
    85  	URL                *string               `json:"url,omitempty"`
    86  	HTMLURL            *string               `json:"html_url,omitempty"`
    87  	MostRecentInstance *MostRecentInstance   `json:"most_recent_instance,omitempty"`
    88  	Instances          []*MostRecentInstance `json:"instances,omitempty"`
    89  	DismissedBy        *User                 `json:"dismissed_by,omitempty"`
    90  	DismissedAt        *Timestamp            `json:"dismissed_at,omitempty"`
    91  	DismissedReason    *string               `json:"dismissed_reason,omitempty"`
    92  	DismissedComment   *string               `json:"dismissed_comment,omitempty"`
    93  	InstancesURL       *string               `json:"instances_url,omitempty"`
    94  }
    95  
    96  // ID returns the ID associated with an alert. It is the number at the end of the security alert's URL.
    97  func (a *Alert) ID() int64 {
    98  	if a == nil {
    99  		return 0
   100  	}
   101  
   102  	s := a.GetHTMLURL()
   103  
   104  	// Check for an ID to parse at the end of the url
   105  	if i := strings.LastIndex(s, "/"); i >= 0 {
   106  		s = s[i+1:]
   107  	}
   108  
   109  	// Return the alert ID as a 64-bit integer. Unable to convert or out of range returns 0.
   110  	id, err := strconv.ParseInt(s, 10, 64)
   111  	if err != nil {
   112  		return 0
   113  	}
   114  
   115  	return id
   116  }
   117  
   118  // AlertInstancesListOptions specifies optional parameters to the CodeScanningService.ListAlertInstances method.
   119  type AlertInstancesListOptions struct {
   120  	// Return code scanning alert instances for a specific branch reference.
   121  	// The ref can be formatted as refs/heads/<branch name> or simply <branch name>. To reference a pull request use refs/pull/<number>/merge
   122  	Ref string `url:"ref,omitempty"`
   123  
   124  	ListOptions
   125  }
   126  
   127  // AlertListOptions specifies optional parameters to the CodeScanningService.ListAlerts method.
   128  type AlertListOptions struct {
   129  	// State of the code scanning alerts to list. Set to closed to list only closed code scanning alerts. Default: open
   130  	State string `url:"state,omitempty"`
   131  
   132  	// Return code scanning alerts for a specific branch reference.
   133  	// The ref can be formatted as refs/heads/<branch name> or simply <branch name>. To reference a pull request use refs/pull/<number>/merge
   134  	Ref string `url:"ref,omitempty"`
   135  
   136  	// If specified, only code scanning alerts with this severity will be returned. Possible values are: critical, high, medium, low, warning, note, error.
   137  	Severity string `url:"severity,omitempty"`
   138  
   139  	// The name of a code scanning tool. Only results by this tool will be listed.
   140  	ToolName string `url:"tool_name,omitempty"`
   141  
   142  	ListCursorOptions
   143  
   144  	// Add ListOptions so offset pagination with integer type "page" query parameter is accepted
   145  	// since ListCursorOptions accepts "page" as string only.
   146  	ListOptions
   147  }
   148  
   149  // AnalysesListOptions specifies optional parameters to the CodeScanningService.ListAnalysesForRepo method.
   150  type AnalysesListOptions struct {
   151  	// Return code scanning analyses belonging to the same SARIF upload.
   152  	SarifID *string `url:"sarif_id,omitempty"`
   153  
   154  	// Return code scanning analyses for a specific branch reference.
   155  	// The ref can be formatted as refs/heads/<branch name> or simply <branch name>. To reference a pull request use refs/pull/<number>/merge
   156  	Ref *string `url:"ref,omitempty"`
   157  
   158  	ListOptions
   159  }
   160  
   161  // CodeQLDatabase represents a metadata about the CodeQL database.
   162  //
   163  // GitHub API docs: https://docs.github.com/rest/code-scanning
   164  type CodeQLDatabase struct {
   165  	ID          *int64     `json:"id,omitempty"`
   166  	Name        *string    `json:"name,omitempty"`
   167  	Language    *string    `json:"language,omitempty"`
   168  	Uploader    *User      `json:"uploader,omitempty"`
   169  	ContentType *string    `json:"content_type,omitempty"`
   170  	Size        *int64     `json:"size,omitempty"`
   171  	CreatedAt   *Timestamp `json:"created_at,omitempty"`
   172  	UpdatedAt   *Timestamp `json:"updated_at,omitempty"`
   173  	URL         *string    `json:"url,omitempty"`
   174  }
   175  
   176  // ScanningAnalysis represents an individual GitHub Code Scanning ScanningAnalysis on a single repository.
   177  //
   178  // GitHub API docs: https://docs.github.com/rest/code-scanning
   179  type ScanningAnalysis struct {
   180  	ID           *int64     `json:"id,omitempty"`
   181  	Ref          *string    `json:"ref,omitempty"`
   182  	CommitSHA    *string    `json:"commit_sha,omitempty"`
   183  	AnalysisKey  *string    `json:"analysis_key,omitempty"`
   184  	Environment  *string    `json:"environment,omitempty"`
   185  	Error        *string    `json:"error,omitempty"`
   186  	Category     *string    `json:"category,omitempty"`
   187  	CreatedAt    *Timestamp `json:"created_at,omitempty"`
   188  	ResultsCount *int       `json:"results_count,omitempty"`
   189  	RulesCount   *int       `json:"rules_count,omitempty"`
   190  	URL          *string    `json:"url,omitempty"`
   191  	SarifID      *string    `json:"sarif_id,omitempty"`
   192  	Tool         *Tool      `json:"tool,omitempty"`
   193  	Deletable    *bool      `json:"deletable,omitempty"`
   194  	Warning      *string    `json:"warning,omitempty"`
   195  }
   196  
   197  // SarifAnalysis specifies the results of a code scanning job.
   198  //
   199  // GitHub API docs: https://docs.github.com/rest/code-scanning
   200  type SarifAnalysis struct {
   201  	CommitSHA   *string    `json:"commit_sha,omitempty"`
   202  	Ref         *string    `json:"ref,omitempty"`
   203  	Sarif       *string    `json:"sarif,omitempty"`
   204  	CheckoutURI *string    `json:"checkout_uri,omitempty"`
   205  	StartedAt   *Timestamp `json:"started_at,omitempty"`
   206  	ToolName    *string    `json:"tool_name,omitempty"`
   207  }
   208  
   209  // CodeScanningAlertState specifies the state of a code scanning alert.
   210  //
   211  // GitHub API docs: https://docs.github.com/rest/code-scanning
   212  type CodeScanningAlertState struct {
   213  	// State sets the state of the code scanning alert and is a required field.
   214  	// You must also provide DismissedReason when you set the state to "dismissed".
   215  	// State can be one of: "open", "dismissed".
   216  	State string `json:"state"`
   217  	// DismissedReason represents the reason for dismissing or closing the alert.
   218  	// It is required when the state is "dismissed".
   219  	// It can be one of: "false positive", "won't fix", "used in tests".
   220  	DismissedReason *string `json:"dismissed_reason,omitempty"`
   221  	// DismissedComment is associated with the dismissal of the alert.
   222  	DismissedComment *string `json:"dismissed_comment,omitempty"`
   223  }
   224  
   225  // SarifID identifies a sarif analysis upload.
   226  //
   227  // GitHub API docs: https://docs.github.com/rest/code-scanning
   228  type SarifID struct {
   229  	ID  *string `json:"id,omitempty"`
   230  	URL *string `json:"url,omitempty"`
   231  }
   232  
   233  // ListAlertsForOrg lists code scanning alerts for an org.
   234  //
   235  // You must use an access token with the security_events scope to use this endpoint. GitHub Apps must have the security_events
   236  // read permission to use this endpoint.
   237  //
   238  // GitHub API docs: https://docs.github.com/rest/code-scanning/code-scanning#list-code-scanning-alerts-for-an-organization
   239  //
   240  //meta:operation GET /orgs/{org}/code-scanning/alerts
   241  func (s *CodeScanningService) ListAlertsForOrg(ctx context.Context, org string, opts *AlertListOptions) ([]*Alert, *Response, error) {
   242  	u := fmt.Sprintf("orgs/%v/code-scanning/alerts", org)
   243  	u, err := addOptions(u, opts)
   244  	if err != nil {
   245  		return nil, nil, err
   246  	}
   247  
   248  	req, err := s.client.NewRequest("GET", u, nil)
   249  	if err != nil {
   250  		return nil, nil, err
   251  	}
   252  
   253  	var alerts []*Alert
   254  	resp, err := s.client.Do(ctx, req, &alerts)
   255  	if err != nil {
   256  		return nil, resp, err
   257  	}
   258  
   259  	return alerts, resp, nil
   260  }
   261  
   262  // ListAlertsForRepo lists code scanning alerts for a repository.
   263  //
   264  // Lists all open code scanning alerts for the default branch (usually master) and protected branches in a repository.
   265  // You must use an access token with the security_events scope to use this endpoint. GitHub Apps must have the security_events
   266  // read permission to use this endpoint.
   267  //
   268  // GitHub API docs: https://docs.github.com/rest/code-scanning/code-scanning#list-code-scanning-alerts-for-a-repository
   269  //
   270  //meta:operation GET /repos/{owner}/{repo}/code-scanning/alerts
   271  func (s *CodeScanningService) ListAlertsForRepo(ctx context.Context, owner, repo string, opts *AlertListOptions) ([]*Alert, *Response, error) {
   272  	u := fmt.Sprintf("repos/%v/%v/code-scanning/alerts", owner, repo)
   273  	u, err := addOptions(u, opts)
   274  	if err != nil {
   275  		return nil, nil, err
   276  	}
   277  
   278  	req, err := s.client.NewRequest("GET", u, nil)
   279  	if err != nil {
   280  		return nil, nil, err
   281  	}
   282  
   283  	var alerts []*Alert
   284  	resp, err := s.client.Do(ctx, req, &alerts)
   285  	if err != nil {
   286  		return nil, resp, err
   287  	}
   288  
   289  	return alerts, resp, nil
   290  }
   291  
   292  // GetAlert gets a single code scanning alert for a repository.
   293  //
   294  // You must use an access token with the security_events scope to use this endpoint.
   295  // GitHub Apps must have the security_events read permission to use this endpoint.
   296  //
   297  // The security alert_id is the number at the end of the security alert's URL.
   298  //
   299  // GitHub API docs: https://docs.github.com/rest/code-scanning/code-scanning#get-a-code-scanning-alert
   300  //
   301  //meta:operation GET /repos/{owner}/{repo}/code-scanning/alerts/{alert_number}
   302  func (s *CodeScanningService) GetAlert(ctx context.Context, owner, repo string, id int64) (*Alert, *Response, error) {
   303  	u := fmt.Sprintf("repos/%v/%v/code-scanning/alerts/%v", owner, repo, id)
   304  
   305  	req, err := s.client.NewRequest("GET", u, nil)
   306  	if err != nil {
   307  		return nil, nil, err
   308  	}
   309  
   310  	a := new(Alert)
   311  	resp, err := s.client.Do(ctx, req, a)
   312  	if err != nil {
   313  		return nil, resp, err
   314  	}
   315  
   316  	return a, resp, nil
   317  }
   318  
   319  // UpdateAlert updates the state of a single code scanning alert for a repository.
   320  //
   321  // You must use an access token with the security_events scope to use this endpoint.
   322  // GitHub Apps must have the security_events read permission to use this endpoint.
   323  //
   324  // The security alert_id is the number at the end of the security alert's URL.
   325  //
   326  // GitHub API docs: https://docs.github.com/rest/code-scanning/code-scanning#update-a-code-scanning-alert
   327  //
   328  //meta:operation PATCH /repos/{owner}/{repo}/code-scanning/alerts/{alert_number}
   329  func (s *CodeScanningService) UpdateAlert(ctx context.Context, owner, repo string, id int64, stateInfo *CodeScanningAlertState) (*Alert, *Response, error) {
   330  	u := fmt.Sprintf("repos/%v/%v/code-scanning/alerts/%v", owner, repo, id)
   331  
   332  	req, err := s.client.NewRequest("PATCH", u, stateInfo)
   333  	if err != nil {
   334  		return nil, nil, err
   335  	}
   336  
   337  	a := new(Alert)
   338  	resp, err := s.client.Do(ctx, req, a)
   339  	if err != nil {
   340  		return nil, resp, err
   341  	}
   342  
   343  	return a, resp, nil
   344  }
   345  
   346  // ListAlertInstances lists instances of a code scanning alert.
   347  //
   348  // You must use an access token with the security_events scope to use this endpoint.
   349  // GitHub Apps must have the security_events read permission to use this endpoint.
   350  //
   351  // GitHub API docs: https://docs.github.com/rest/code-scanning/code-scanning#list-instances-of-a-code-scanning-alert
   352  //
   353  //meta:operation GET /repos/{owner}/{repo}/code-scanning/alerts/{alert_number}/instances
   354  func (s *CodeScanningService) ListAlertInstances(ctx context.Context, owner, repo string, id int64, opts *AlertInstancesListOptions) ([]*MostRecentInstance, *Response, error) {
   355  	u := fmt.Sprintf("repos/%v/%v/code-scanning/alerts/%v/instances", owner, repo, id)
   356  	u, err := addOptions(u, opts)
   357  	if err != nil {
   358  		return nil, nil, err
   359  	}
   360  
   361  	req, err := s.client.NewRequest("GET", u, nil)
   362  	if err != nil {
   363  		return nil, nil, err
   364  	}
   365  
   366  	var alertInstances []*MostRecentInstance
   367  	resp, err := s.client.Do(ctx, req, &alertInstances)
   368  	if err != nil {
   369  		return nil, resp, err
   370  	}
   371  
   372  	return alertInstances, resp, nil
   373  }
   374  
   375  // UploadSarif uploads the result of code scanning job to GitHub.
   376  //
   377  // For the parameter sarif, you must first compress your SARIF file using gzip and then translate the contents of the file into a Base64 encoding string.
   378  // You must use an access token with the security_events scope to use this endpoint. GitHub Apps must have the security_events
   379  // write permission to use this endpoint.
   380  //
   381  // GitHub API docs: https://docs.github.com/rest/code-scanning/code-scanning#upload-an-analysis-as-sarif-data
   382  //
   383  //meta:operation POST /repos/{owner}/{repo}/code-scanning/sarifs
   384  func (s *CodeScanningService) UploadSarif(ctx context.Context, owner, repo string, sarif *SarifAnalysis) (*SarifID, *Response, error) {
   385  	u := fmt.Sprintf("repos/%v/%v/code-scanning/sarifs", owner, repo)
   386  
   387  	req, err := s.client.NewRequest("POST", u, sarif)
   388  	if err != nil {
   389  		return nil, nil, err
   390  	}
   391  
   392  	sarifID := new(SarifID)
   393  	resp, err := s.client.Do(ctx, req, sarifID)
   394  	if err != nil {
   395  		return nil, resp, err
   396  	}
   397  
   398  	return sarifID, resp, nil
   399  }
   400  
   401  // SARIFUpload represents information about a SARIF upload.
   402  type SARIFUpload struct {
   403  	// `pending` files have not yet been processed, while `complete` means results from the SARIF have been stored.
   404  	// `failed` files have either not been processed at all, or could only be partially processed.
   405  	ProcessingStatus *string `json:"processing_status,omitempty"`
   406  	// The REST API URL for getting the analyses associated with the upload.
   407  	AnalysesURL *string `json:"analyses_url,omitempty"`
   408  }
   409  
   410  // GetSARIF gets information about a SARIF upload.
   411  //
   412  // You must use an access token with the security_events scope to use this endpoint.
   413  // GitHub Apps must have the security_events read permission to use this endpoint.
   414  //
   415  // GitHub API docs: https://docs.github.com/rest/code-scanning/code-scanning#get-information-about-a-sarif-upload
   416  //
   417  //meta:operation GET /repos/{owner}/{repo}/code-scanning/sarifs/{sarif_id}
   418  func (s *CodeScanningService) GetSARIF(ctx context.Context, owner, repo, sarifID string) (*SARIFUpload, *Response, error) {
   419  	u := fmt.Sprintf("repos/%v/%v/code-scanning/sarifs/%v", owner, repo, sarifID)
   420  
   421  	req, err := s.client.NewRequest("GET", u, nil)
   422  	if err != nil {
   423  		return nil, nil, err
   424  	}
   425  
   426  	sarifUpload := new(SARIFUpload)
   427  	resp, err := s.client.Do(ctx, req, sarifUpload)
   428  	if err != nil {
   429  		return nil, resp, err
   430  	}
   431  
   432  	return sarifUpload, resp, nil
   433  }
   434  
   435  // ListAnalysesForRepo lists code scanning analyses for a repository.
   436  //
   437  // Lists the details of all code scanning analyses for a repository, starting with the most recent.
   438  // You must use an access token with the security_events scope to use this endpoint.
   439  // GitHub Apps must have the security_events read permission to use this endpoint.
   440  //
   441  // GitHub API docs: https://docs.github.com/rest/code-scanning/code-scanning#list-code-scanning-analyses-for-a-repository
   442  //
   443  //meta:operation GET /repos/{owner}/{repo}/code-scanning/analyses
   444  func (s *CodeScanningService) ListAnalysesForRepo(ctx context.Context, owner, repo string, opts *AnalysesListOptions) ([]*ScanningAnalysis, *Response, error) {
   445  	u := fmt.Sprintf("repos/%v/%v/code-scanning/analyses", owner, repo)
   446  	u, err := addOptions(u, opts)
   447  	if err != nil {
   448  		return nil, nil, err
   449  	}
   450  
   451  	req, err := s.client.NewRequest("GET", u, nil)
   452  	if err != nil {
   453  		return nil, nil, err
   454  	}
   455  
   456  	var analyses []*ScanningAnalysis
   457  	resp, err := s.client.Do(ctx, req, &analyses)
   458  	if err != nil {
   459  		return nil, resp, err
   460  	}
   461  
   462  	return analyses, resp, nil
   463  }
   464  
   465  // GetAnalysis gets a single code scanning analysis for a repository.
   466  //
   467  // You must use an access token with the security_events scope to use this endpoint.
   468  // GitHub Apps must have the security_events read permission to use this endpoint.
   469  //
   470  // The security analysis_id is the ID of the analysis, as returned from the ListAnalysesForRepo operation.
   471  //
   472  // GitHub API docs: https://docs.github.com/rest/code-scanning/code-scanning#get-a-code-scanning-analysis-for-a-repository
   473  //
   474  //meta:operation GET /repos/{owner}/{repo}/code-scanning/analyses/{analysis_id}
   475  func (s *CodeScanningService) GetAnalysis(ctx context.Context, owner, repo string, id int64) (*ScanningAnalysis, *Response, error) {
   476  	u := fmt.Sprintf("repos/%v/%v/code-scanning/analyses/%v", owner, repo, id)
   477  
   478  	req, err := s.client.NewRequest("GET", u, nil)
   479  	if err != nil {
   480  		return nil, nil, err
   481  	}
   482  
   483  	analysis := new(ScanningAnalysis)
   484  	resp, err := s.client.Do(ctx, req, analysis)
   485  	if err != nil {
   486  		return nil, resp, err
   487  	}
   488  
   489  	return analysis, resp, nil
   490  }
   491  
   492  // DeleteAnalysis represents a successful deletion of a code scanning analysis.
   493  type DeleteAnalysis struct {
   494  	// Next deletable analysis in chain, without last analysis deletion confirmation
   495  	NextAnalysisURL *string `json:"next_analysis_url,omitempty"`
   496  	// Next deletable analysis in chain, with last analysis deletion confirmation
   497  	ConfirmDeleteURL *string `json:"confirm_delete_url,omitempty"`
   498  }
   499  
   500  // DeleteAnalysis deletes a single code scanning analysis from a repository.
   501  //
   502  // You must use an access token with the repo scope to use this endpoint.
   503  // GitHub Apps must have the security_events read permission to use this endpoint.
   504  //
   505  // The security analysis_id is the ID of the analysis, as returned from the ListAnalysesForRepo operation.
   506  //
   507  // GitHub API docs: https://docs.github.com/rest/code-scanning/code-scanning#delete-a-code-scanning-analysis-from-a-repository
   508  //
   509  //meta:operation DELETE /repos/{owner}/{repo}/code-scanning/analyses/{analysis_id}
   510  func (s *CodeScanningService) DeleteAnalysis(ctx context.Context, owner, repo string, id int64) (*DeleteAnalysis, *Response, error) {
   511  	u := fmt.Sprintf("repos/%v/%v/code-scanning/analyses/%v", owner, repo, id)
   512  
   513  	req, err := s.client.NewRequest("DELETE", u, nil)
   514  	if err != nil {
   515  		return nil, nil, err
   516  	}
   517  
   518  	deleteAnalysis := new(DeleteAnalysis)
   519  	resp, err := s.client.Do(ctx, req, deleteAnalysis)
   520  	if err != nil {
   521  		return nil, resp, err
   522  	}
   523  
   524  	return deleteAnalysis, resp, nil
   525  }
   526  
   527  // ListCodeQLDatabases lists the CodeQL databases that are available in a repository.
   528  //
   529  // You must use an access token with the security_events scope to use this endpoint.
   530  // GitHub Apps must have the contents read permission to use this endpoint.
   531  //
   532  // GitHub API docs: https://docs.github.com/rest/code-scanning/code-scanning#list-codeql-databases-for-a-repository
   533  //
   534  //meta:operation GET /repos/{owner}/{repo}/code-scanning/codeql/databases
   535  func (s *CodeScanningService) ListCodeQLDatabases(ctx context.Context, owner, repo string) ([]*CodeQLDatabase, *Response, error) {
   536  	u := fmt.Sprintf("repos/%v/%v/code-scanning/codeql/databases", owner, repo)
   537  
   538  	req, err := s.client.NewRequest("GET", u, nil)
   539  	if err != nil {
   540  		return nil, nil, err
   541  	}
   542  
   543  	var codeqlDatabases []*CodeQLDatabase
   544  	resp, err := s.client.Do(ctx, req, &codeqlDatabases)
   545  	if err != nil {
   546  		return nil, resp, err
   547  	}
   548  
   549  	return codeqlDatabases, resp, nil
   550  }
   551  
   552  // GetCodeQLDatabase gets a CodeQL database for a language in a repository.
   553  //
   554  // You must use an access token with the security_events scope to use this endpoint.
   555  // GitHub Apps must have the contents read permission to use this endpoint.
   556  //
   557  // GitHub API docs: https://docs.github.com/rest/code-scanning/code-scanning#get-a-codeql-database-for-a-repository
   558  //
   559  //meta:operation GET /repos/{owner}/{repo}/code-scanning/codeql/databases/{language}
   560  func (s *CodeScanningService) GetCodeQLDatabase(ctx context.Context, owner, repo, language string) (*CodeQLDatabase, *Response, error) {
   561  	u := fmt.Sprintf("repos/%v/%v/code-scanning/codeql/databases/%v", owner, repo, language)
   562  
   563  	req, err := s.client.NewRequest("GET", u, nil)
   564  	if err != nil {
   565  		return nil, nil, err
   566  	}
   567  
   568  	codeqlDatabase := new(CodeQLDatabase)
   569  	resp, err := s.client.Do(ctx, req, codeqlDatabase)
   570  	if err != nil {
   571  		return nil, resp, err
   572  	}
   573  
   574  	return codeqlDatabase, resp, nil
   575  }
   576  
   577  // DefaultSetupConfiguration represents a code scanning default setup configuration.
   578  type DefaultSetupConfiguration struct {
   579  	State      *string    `json:"state,omitempty"`
   580  	Languages  []string   `json:"languages,omitempty"`
   581  	QuerySuite *string    `json:"query_suite,omitempty"`
   582  	UpdatedAt  *Timestamp `json:"updated_at,omitempty"`
   583  }
   584  
   585  // GetDefaultSetupConfiguration gets a code scanning default setup configuration.
   586  //
   587  // You must use an access token with the repo scope to use this
   588  // endpoint with private repos or the public_repo scope for public repos. GitHub Apps must have the repo write
   589  // permission to use this endpoint.
   590  //
   591  // GitHub API docs: https://docs.github.com/rest/code-scanning/code-scanning#get-a-code-scanning-default-setup-configuration
   592  //
   593  //meta:operation GET /repos/{owner}/{repo}/code-scanning/default-setup
   594  func (s *CodeScanningService) GetDefaultSetupConfiguration(ctx context.Context, owner, repo string) (*DefaultSetupConfiguration, *Response, error) {
   595  	u := fmt.Sprintf("repos/%s/%s/code-scanning/default-setup", owner, repo)
   596  
   597  	req, err := s.client.NewRequest("GET", u, nil)
   598  	if err != nil {
   599  		return nil, nil, err
   600  	}
   601  
   602  	cfg := new(DefaultSetupConfiguration)
   603  	resp, err := s.client.Do(ctx, req, cfg)
   604  	if err != nil {
   605  		return nil, resp, err
   606  	}
   607  
   608  	return cfg, resp, nil
   609  }
   610  
   611  // UpdateDefaultSetupConfigurationOptions specifies parameters to the CodeScanningService.UpdateDefaultSetupConfiguration
   612  // method.
   613  type UpdateDefaultSetupConfigurationOptions struct {
   614  	State      string   `json:"state"`
   615  	QuerySuite *string  `json:"query_suite,omitempty"`
   616  	Languages  []string `json:"languages,omitempty"`
   617  }
   618  
   619  // UpdateDefaultSetupConfigurationResponse represents a response from updating a code scanning default setup configuration.
   620  type UpdateDefaultSetupConfigurationResponse struct {
   621  	RunID  *int64  `json:"run_id,omitempty"`
   622  	RunURL *string `json:"run_url,omitempty"`
   623  }
   624  
   625  // UpdateDefaultSetupConfiguration updates a code scanning default setup configuration.
   626  //
   627  // You must use an access token with the repo scope to use this
   628  // endpoint with private repos or the public_repo scope for public repos. GitHub Apps must have the repo write
   629  // permission to use this endpoint.
   630  //
   631  // This method might return an AcceptedError and a status code of 202. This is because this is the status that GitHub
   632  // returns to signify that it has now scheduled the update of the pull request branch in a background task.
   633  //
   634  // GitHub API docs: https://docs.github.com/rest/code-scanning/code-scanning#update-a-code-scanning-default-setup-configuration
   635  //
   636  //meta:operation PATCH /repos/{owner}/{repo}/code-scanning/default-setup
   637  func (s *CodeScanningService) UpdateDefaultSetupConfiguration(ctx context.Context, owner, repo string, options *UpdateDefaultSetupConfigurationOptions) (*UpdateDefaultSetupConfigurationResponse, *Response, error) {
   638  	u := fmt.Sprintf("repos/%s/%s/code-scanning/default-setup", owner, repo)
   639  
   640  	req, err := s.client.NewRequest("PATCH", u, options)
   641  	if err != nil {
   642  		return nil, nil, err
   643  	}
   644  
   645  	a := new(UpdateDefaultSetupConfigurationResponse)
   646  	resp, err := s.client.Do(ctx, req, a)
   647  	if err != nil {
   648  		return nil, resp, err
   649  	}
   650  
   651  	return a, resp, nil
   652  }