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