Skip to content

Commit

Permalink
feat: adds support for Code scanning endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
nickfloyd authored Jun 11, 2024
2 parents 8b23a3c + b54f8b9 commit dd36a01
Show file tree
Hide file tree
Showing 14 changed files with 1,729 additions and 0 deletions.
138 changes: 138 additions & 0 deletions lib/octokit/client/code_scanning.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,144 @@ class Client
#
# @see https://docs.github.com/rest/code-scanning
module CodeScanning
# Updates a code scanning default setup configuration
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param state [String] The desired state of code scanning default setup
# @param query_suite [String] CodeQL query suite to be used
# @param languages [Array] List of CodeQL languages to be analyzed
#
# @return [Sawyer::Resource] Action Run information
# @see https://docs.github.com/en/rest/code-scanning/code-scanning#update-a-code-scanning-default-setup-configuration
def update_code_scanning_default_config(repo, state, query_suite = nil, languages = nil, options = {})
options[:state] = state
options[:query_suite] = query_suite if query_suite
options[:languages] = languages if languages

patch "#{Repository.path repo}/code-scanning/default-setup", options
end

# Get Code Scanning Default Configuration
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
#
# @return [Sawyer::Resource] CodeQl Default Setup Configuration Information
# @see https://docs.github.com/en/rest/code-scanning/code-scanning#get-a-code-scanning-default-setup-configuration
def get_code_scanning_default_config(repo, options = {})
get "#{Repository.path repo}/code-scanning/default-setup", options
end

# Gets a CodeQL database for a language in a repository
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param language [String]
#
# @return [Sawyer::Resource] CodeQl Default Setup Configuration Information
# @see https://docs.github.com/en/rest/code-scanning/code-scanning#get-a-codeql-database-for-a-repository
def get_codeql_database_for_repo(repo, language, options = {})
get "#{Repository.path repo}/code-scanning/codeql/databases/#{language}", options
end

# Lists the CodeQL databases that are available in a repository
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
#
# @return [Array] List of CodeQL Databases
# @see https://docs.github.com/en/rest/code-scanning/code-scanning#list-codeql-databases-for-a-repository
def list_codeql_database_for_repo(repo, options = {})
get "#{Repository.path repo}/code-scanning/codeql/databases", options
end

# Delete a specified code scanning analysis from a repository
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param analysis_id [Integer] ID of the code scanning analysis
#
# @return [Sawyer::Resource] Next Code Scanning Analysis Information
# @see https://docs.github.com/en/rest/code-scanning/code-scanning#delete-a-code-scanning-analysis-from-a-repository
def delete_code_scanning_analysis(repo, analysis_id, options = {})
delete "#{Repository.path repo}/code-scanning/analyses/#{analysis_id}", options
end

# Get a code scanning analysis for a repository
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param analysis_id [Integer] ID of the code scanning analysis
#
# @return [Sawyer::Resource] Code Scanning Analysis
# @see https://docs.github.com/en/rest/code-scanning/code-scanning#get-a-code-scanning-analysis-for-a-repository
def get_code_scanning_analysis(repo, analysis_id, options = {})
get "#{Repository.path repo}/code-scanning/analyses/#{analysis_id}", options
end

# List code scanning analyses for a repository
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
#
# @return [Array] List of Code Scanning Analyses
# @see https://docs.github.com/en/rest/code-scanning/code-scanning#list-code-scanning-analyses-for-a-repository
def list_code_scanning_analysis(repo, options = {})
paginate "#{Repository.path repo}/code-scanning/analyses", options
end

# List instances of a code scanning alert
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param alert_number [Integer] The number that identifies an alert
#
# @return [Array] List of Code Scanning Alerts
# @see https://docs.github.com/en/rest/code-scanning/code-scanning#list-instances-of-a-code-scanning-alert
def list_instances_of_code_scanning_alert(repo, alert_number, options = {})
paginate "#{Repository.path repo}/code-scanning/alerts/#{alert_number}/instances", options
end

# Update a code scanning alert
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param alert_number [Integer] The number that identifies an alert
# @param state [String] The reason for dismissing or closing the alert. Required when the state is dismissed
#
# @return [Sawyer::Resource] Code Scanning Alert information
# @see https://docs.github.com/en/rest/code-scanning/code-scanning#update-a-code-scanning-alert
def update_code_scanning_alert(repo, alert_number, state, reason, comment = nil, options = {})
options[:state] = state
options[:dismissed_reason] = reason
options[:dismissed_comment] = comment if comment

patch "#{Repository.path repo}/code-scanning/alerts/#{alert_number}", options
end

# Gets a single code scanning alert
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
# @param alert_number [Integer] The number that identifies an alert
#
# @return [Sawyer::Resource] Code Scanning Alert
# @see https://docs.github.com/en/rest/code-scanning/code-scanning#get-a-code-scanning-alert
def get_code_scanning_alert(repo, alert_number, options = {})
get "#{Repository.path repo}/code-scanning/alerts/#{alert_number}", options
end

# List code scanning alerts for a repository
#
# @param org [String] A GitHub organization
#
# @return [Array] Code Scanning Alert information
# @see https://docs.github.com/en/rest/code-scanning/code-scanning#list-code-scanning-alerts-for-a-repository
def list_code_scanning_alerts_for_repo(repo, options = {})
paginate "#{Repository.path repo}/code-scanning/alerts", options
end

# List code scanning alerts for an organization
#
# @param org [String] A GitHub organization
#
# @return [Array] Code Scanning Alert information
# @see https://docs.github.com/en/rest/code-scanning/code-scanning#list-code-scanning-alerts-for-an-organization
def list_code_scanning_alerts_for_org(org, options = {})
paginate "orgs/#{org}/code-scanning/alerts", options
end

# Uploads SARIF data containing the results of a code scanning analysis
#
# @param repo [Integer, String, Repository, Hash] A GitHub repository
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"http_interactions": [
{
"request": {
"method": "delete",
"uri": "https://api.github.com/repos/Caja-de-Dano/active-wrapper/code-scanning/analyses/225379147",
"body": {
"encoding": "UTF-8",
"base64_string": "e30=\n"
},
"headers": {
"Accept": [
"application/vnd.github.v3+json"
],
"User-Agent": [
"Octokit Ruby Gem 8.1.0"
],
"Content-Type": [
"application/json"
],
"Authorization": [
"token <<ACCESS_TOKEN>>"
],
"Accept-Encoding": [
"gzip;q=1.0,deflate;q=0.6,identity;q=0.3"
]
}
},
"response": {
"status": {
"code": 200,
"message": "OK"
},
"headers": {
"Server": [
"GitHub.com"
],
"Date": [
"Fri, 31 May 2024 06:04:21 GMT"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Transfer-Encoding": [
"chunked"
],
"Cache-Control": [
"private, max-age=60, s-maxage=60"
],
"Vary": [
"Accept, Authorization, Cookie, X-GitHub-OTP",
"Accept-Encoding, Accept, X-Requested-With"
],
"Etag": [
"W/\"4ff7c2d422afb104c75d7ed4869ad67d7d6c736670587a3a528fe04f23b92928\""
],
"X-Oauth-Scopes": [
"gist, read:org, repo, workflow"
],
"X-Accepted-Oauth-Scopes": [
"admin:repo_hook, delete_repo, read:repo_hook, repo, repo:invite, repo:status, repo_deployment, security_events, write:repo_hook"
],
"X-Oauth-Client-Id": [
"178c6fc778ccc68e1d6a"
],
"X-Github-Media-Type": [
"github.v3; format=json"
],
"X-Github-Api-Version-Selected": [
"2022-11-28"
],
"X-Ratelimit-Limit": [
"5000"
],
"X-Ratelimit-Remaining": [
"4999"
],
"X-Ratelimit-Reset": [
"1717139061"
],
"X-Ratelimit-Used": [
"1"
],
"X-Ratelimit-Resource": [
"core"
],
"Access-Control-Expose-Headers": [
"ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset"
],
"Access-Control-Allow-Origin": [
"*"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubdomains; preload"
],
"X-Frame-Options": [
"deny"
],
"X-Content-Type-Options": [
"nosniff"
],
"X-Xss-Protection": [
"0"
],
"Referrer-Policy": [
"origin-when-cross-origin, strict-origin-when-cross-origin"
],
"Content-Security-Policy": [
"default-src 'none'"
],
"X-Github-Request-Id": [
"DB89:3A257F:386B555:38D393B:66596865"
]
},
"body": {
"encoding": "ASCII-8BIT",
"base64_string": "eyJuZXh0X2FuYWx5c2lzX3VybCI6Imh0dHBzOi8vYXBpLmdpdGh1Yi5jb20v\ncmVwb3MvQ2FqYS1kZS1EYW5vL2FjdGl2ZS13cmFwcGVyL2NvZGUtc2Nhbm5p\nbmcvYW5hbHlzZXMvMjIwMTQ4NzQzIiwiY29uZmlybV9kZWxldGVfdXJsIjoi\naHR0cHM6Ly9hcGkuZ2l0aHViLmNvbS9yZXBvcy9DYWphLWRlLURhbm8vYWN0\naXZlLXdyYXBwZXIvY29kZS1zY2FubmluZy9hbmFseXNlcy8yMjAxNDg3NDM/\nY29uZmlybV9kZWxldGUifQ==\n"
}
},
"recorded_at": "Fri, 31 May 2024 06:04:21 GMT"
}
],
"recorded_with": "VCR 6.2.0"
}
Loading

0 comments on commit dd36a01

Please sign in to comment.