Struct roctogen::endpoints::code_scanning::CodeScanning [−][src]
pub struct CodeScanning<'api> { /* fields omitted */ }
Implementations
pub async fn delete_analysis_async(
&self,
owner: &str,
repo: &str,
analysis_id: i32,
query_params: Option<impl Into<CodeScanningDeleteAnalysisParams<'api>>>
) -> Result<CodeScanningAnalysisDeletion, CodeScanningDeleteAnalysisError>
pub async fn delete_analysis_async(
&self,
owner: &str,
repo: &str,
analysis_id: i32,
query_params: Option<impl Into<CodeScanningDeleteAnalysisParams<'api>>>
) -> Result<CodeScanningAnalysisDeletion, CodeScanningDeleteAnalysisError>
Delete a code scanning analysis from a repository
Deletes a specified code scanning analysis from a repository. For
private repositories, you must use an access token with the repo
scope. For public repositories,
you must use an access token with public_repo
scope.
GitHub Apps must have the security_events
write permission to use this endpoint.
You can delete one analysis at a time. To delete a series of analyses, start with the most recent analysis and work backwards. Conceptually, the process is similar to the undo function in a text editor.
When you list the analyses for a repository, one or more will be identified as deletable in the response:
"deletable": true
An analysis is deletable when it’s the most recent in a set of analyses. Typically, a repository will have multiple sets of analyses for each enabled code scanning tool, where a set is determined by a unique combination of analysis values:
ref
tool
analysis_key
environment
If you attempt to delete an analysis that is not the most recent in a set, you’ll get a 400 response with the message:
Analysis specified is not deletable.
The response from a successful DELETE
operation provides you with
two alternative URLs for deleting the next analysis in the set:
next_analysis_url
and confirm_delete_url
.
Use the next_analysis_url
URL if you want to avoid accidentally deleting the final analysis
in a set. This is a useful option if you want to preserve at least one analysis
for the specified tool in your repository.
Use the confirm_delete_url
URL if you are content to remove all analyses for a tool.
When you delete the last analysis in a set, the value of next_analysis_url
and confirm_delete_url
in the 200 response is null
.
As an example of the deletion process, let’s imagine that you added a workflow that configured a particular code scanning tool to analyze the code in a repository. This tool has added 15 analyses: 10 on the default branch, and another 5 on a topic branch. You therefore have two separate sets of analyses for this tool. You’ve now decided that you want to remove all of the analyses for the tool. To do this you must make 15 separate deletion requests. To start, you must find an analysis that’s identified as deletable. Each set of analyses always has one that’s identified as deletable. Having found the deletable analysis for one of the two sets, delete this analysis and then continue deleting the next analysis in the set until they’re all deleted. Then repeat the process for the second set. The procedure therefore consists of a nested loop:
Outer loop:
-
List the analyses for the repository, filtered by tool.
-
Parse this list to find a deletable analysis. If found:
Inner loop:
- Delete the identified analysis.
- Parse the response for the value of
confirm_delete_url
and, if found, use this in the next iteration.
The above process assumes that you want to remove all trace of the tool’s analyses from the GitHub user interface, for the specified repository, and it therefore uses the confirm_delete_url
value. Alternatively, you could use the next_analysis_url
value, which would leave the last analysis in each set undeleted to avoid removing a tool’s analysis entirely.
GitHub API docs for delete_analysis
pub fn delete_analysis(
&self,
owner: &str,
repo: &str,
analysis_id: i32,
query_params: Option<impl Into<CodeScanningDeleteAnalysisParams<'api>>>
) -> Result<CodeScanningAnalysisDeletion, CodeScanningDeleteAnalysisError>
pub fn delete_analysis(
&self,
owner: &str,
repo: &str,
analysis_id: i32,
query_params: Option<impl Into<CodeScanningDeleteAnalysisParams<'api>>>
) -> Result<CodeScanningAnalysisDeletion, CodeScanningDeleteAnalysisError>
Delete a code scanning analysis from a repository
Deletes a specified code scanning analysis from a repository. For
private repositories, you must use an access token with the repo
scope. For public repositories,
you must use an access token with public_repo
scope.
GitHub Apps must have the security_events
write permission to use this endpoint.
You can delete one analysis at a time. To delete a series of analyses, start with the most recent analysis and work backwards. Conceptually, the process is similar to the undo function in a text editor.
When you list the analyses for a repository, one or more will be identified as deletable in the response:
"deletable": true
An analysis is deletable when it’s the most recent in a set of analyses. Typically, a repository will have multiple sets of analyses for each enabled code scanning tool, where a set is determined by a unique combination of analysis values:
ref
tool
analysis_key
environment
If you attempt to delete an analysis that is not the most recent in a set, you’ll get a 400 response with the message:
Analysis specified is not deletable.
The response from a successful DELETE
operation provides you with
two alternative URLs for deleting the next analysis in the set:
next_analysis_url
and confirm_delete_url
.
Use the next_analysis_url
URL if you want to avoid accidentally deleting the final analysis
in a set. This is a useful option if you want to preserve at least one analysis
for the specified tool in your repository.
Use the confirm_delete_url
URL if you are content to remove all analyses for a tool.
When you delete the last analysis in a set, the value of next_analysis_url
and confirm_delete_url
in the 200 response is null
.
As an example of the deletion process, let’s imagine that you added a workflow that configured a particular code scanning tool to analyze the code in a repository. This tool has added 15 analyses: 10 on the default branch, and another 5 on a topic branch. You therefore have two separate sets of analyses for this tool. You’ve now decided that you want to remove all of the analyses for the tool. To do this you must make 15 separate deletion requests. To start, you must find an analysis that’s identified as deletable. Each set of analyses always has one that’s identified as deletable. Having found the deletable analysis for one of the two sets, delete this analysis and then continue deleting the next analysis in the set until they’re all deleted. Then repeat the process for the second set. The procedure therefore consists of a nested loop:
Outer loop:
-
List the analyses for the repository, filtered by tool.
-
Parse this list to find a deletable analysis. If found:
Inner loop:
- Delete the identified analysis.
- Parse the response for the value of
confirm_delete_url
and, if found, use this in the next iteration.
The above process assumes that you want to remove all trace of the tool’s analyses from the GitHub user interface, for the specified repository, and it therefore uses the confirm_delete_url
value. Alternatively, you could use the next_analysis_url
value, which would leave the last analysis in each set undeleted to avoid removing a tool’s analysis entirely.
GitHub API docs for delete_analysis
pub async fn get_alert_async(
&self,
owner: &str,
repo: &str,
alert_number: AlertNumber
) -> Result<CodeScanningAlert, CodeScanningGetAlertError>
pub async fn get_alert_async(
&self,
owner: &str,
repo: &str,
alert_number: AlertNumber
) -> Result<CodeScanningAlert, CodeScanningGetAlertError>
Get a code scanning alert
Gets a single code scanning alert. You must use an access token with the security_events
scope to use this endpoint with private repos, the public_repo
scope also grants permission to read security events on public repos only. GitHub Apps must have the security_events
read permission to use this endpoint.
Deprecation notice:
The instances field is deprecated and will, in future, not be included in the response for this endpoint. The example response reflects this change. The same information can now be retrieved via a GET request to the URL specified by instances_url
.
pub fn get_alert(
&self,
owner: &str,
repo: &str,
alert_number: AlertNumber
) -> Result<CodeScanningAlert, CodeScanningGetAlertError>
pub fn get_alert(
&self,
owner: &str,
repo: &str,
alert_number: AlertNumber
) -> Result<CodeScanningAlert, CodeScanningGetAlertError>
Get a code scanning alert
Gets a single code scanning alert. You must use an access token with the security_events
scope to use this endpoint with private repos, the public_repo
scope also grants permission to read security events on public repos only. GitHub Apps must have the security_events
read permission to use this endpoint.
Deprecation notice:
The instances field is deprecated and will, in future, not be included in the response for this endpoint. The example response reflects this change. The same information can now be retrieved via a GET request to the URL specified by instances_url
.
pub async fn get_analysis_async(
&self,
owner: &str,
repo: &str,
analysis_id: i32
) -> Result<String, CodeScanningGetAnalysisError>
pub async fn get_analysis_async(
&self,
owner: &str,
repo: &str,
analysis_id: i32
) -> Result<String, CodeScanningGetAnalysisError>
Get a code scanning analysis for a repository
Gets a specified code scanning analysis for a repository.
You must use an access token with the security_events
scope to use this endpoint with private repos,
the public_repo
scope also grants permission to read security events on public repos only.
GitHub Apps must have the security_events
read permission to use this endpoint.
The default JSON response contains fields that describe the analysis. This includes the Git reference and commit SHA to which the analysis relates, the datetime of the analysis, the name of the code scanning tool, and the number of alerts.
The rules_count
field in the default response give the number of rules
that were run in the analysis.
For very old analyses this data is not available,
and 0
is returned in this field.
If you use the Accept header application/sarif+json
,
the response contains the analysis data that was uploaded.
This is formatted as
SARIF version 2.1.0.
GitHub API docs for get_analysis
pub fn get_analysis(
&self,
owner: &str,
repo: &str,
analysis_id: i32
) -> Result<String, CodeScanningGetAnalysisError>
pub fn get_analysis(
&self,
owner: &str,
repo: &str,
analysis_id: i32
) -> Result<String, CodeScanningGetAnalysisError>
Get a code scanning analysis for a repository
Gets a specified code scanning analysis for a repository.
You must use an access token with the security_events
scope to use this endpoint with private repos,
the public_repo
scope also grants permission to read security events on public repos only.
GitHub Apps must have the security_events
read permission to use this endpoint.
The default JSON response contains fields that describe the analysis. This includes the Git reference and commit SHA to which the analysis relates, the datetime of the analysis, the name of the code scanning tool, and the number of alerts.
The rules_count
field in the default response give the number of rules
that were run in the analysis.
For very old analyses this data is not available,
and 0
is returned in this field.
If you use the Accept header application/sarif+json
,
the response contains the analysis data that was uploaded.
This is formatted as
SARIF version 2.1.0.
GitHub API docs for get_analysis
pub async fn get_sarif_async(
&self,
owner: &str,
repo: &str,
sarif_id: &str
) -> Result<CodeScanningSarifsStatus, CodeScanningGetSarifError>
pub async fn get_sarif_async(
&self,
owner: &str,
repo: &str,
sarif_id: &str
) -> Result<CodeScanningSarifsStatus, CodeScanningGetSarifError>
Get information about a SARIF upload
Gets information about a SARIF upload, including the status and the URL of the analysis that was uploaded so that you can retrieve details of the analysis. For more information, see “Get a code scanning analysis for a repository.” You must use an access token with the security_events
scope to use this endpoint with private repos, the public_repo
scope also grants permission to read security events on public repos only. GitHub Apps must have the security_events
read permission to use this endpoint.
pub fn get_sarif(
&self,
owner: &str,
repo: &str,
sarif_id: &str
) -> Result<CodeScanningSarifsStatus, CodeScanningGetSarifError>
pub fn get_sarif(
&self,
owner: &str,
repo: &str,
sarif_id: &str
) -> Result<CodeScanningSarifsStatus, CodeScanningGetSarifError>
Get information about a SARIF upload
Gets information about a SARIF upload, including the status and the URL of the analysis that was uploaded so that you can retrieve details of the analysis. For more information, see “Get a code scanning analysis for a repository.” You must use an access token with the security_events
scope to use this endpoint with private repos, the public_repo
scope also grants permission to read security events on public repos only. GitHub Apps must have the security_events
read permission to use this endpoint.
pub async fn list_alert_instances_async(
&self,
owner: &str,
repo: &str,
alert_number: AlertNumber,
query_params: Option<impl Into<CodeScanningListAlertInstancesParams>>
) -> Result<Vec<CodeScanningAlertInstance>, CodeScanningListAlertInstancesError>
pub async fn list_alert_instances_async(
&self,
owner: &str,
repo: &str,
alert_number: AlertNumber,
query_params: Option<impl Into<CodeScanningListAlertInstancesParams>>
) -> Result<Vec<CodeScanningAlertInstance>, CodeScanningListAlertInstancesError>
List instances of a code scanning alert
Lists all instances of the specified code scanning alert.
You must use an access token with the security_events
scope to use this endpoint with private repos,
the public_repo
scope also grants permission to read security events on public repos only.
GitHub Apps must have the security_events
read permission to use this endpoint.
GitHub API docs for list_alert_instances
pub fn list_alert_instances(
&self,
owner: &str,
repo: &str,
alert_number: AlertNumber,
query_params: Option<impl Into<CodeScanningListAlertInstancesParams>>
) -> Result<Vec<CodeScanningAlertInstance>, CodeScanningListAlertInstancesError>
pub fn list_alert_instances(
&self,
owner: &str,
repo: &str,
alert_number: AlertNumber,
query_params: Option<impl Into<CodeScanningListAlertInstancesParams>>
) -> Result<Vec<CodeScanningAlertInstance>, CodeScanningListAlertInstancesError>
List instances of a code scanning alert
Lists all instances of the specified code scanning alert.
You must use an access token with the security_events
scope to use this endpoint with private repos,
the public_repo
scope also grants permission to read security events on public repos only.
GitHub Apps must have the security_events
read permission to use this endpoint.
GitHub API docs for list_alert_instances
pub async fn list_alerts_for_repo_async(
&self,
owner: &str,
repo: &str,
query_params: Option<impl Into<CodeScanningListAlertsForRepoParams<'api>>>
) -> Result<Vec<CodeScanningAlertItems>, CodeScanningListAlertsForRepoError>
pub async fn list_alerts_for_repo_async(
&self,
owner: &str,
repo: &str,
query_params: Option<impl Into<CodeScanningListAlertsForRepoParams<'api>>>
) -> Result<Vec<CodeScanningAlertItems>, CodeScanningListAlertsForRepoError>
List code scanning alerts for a repository
Lists all open code scanning alerts for the default branch (usually main
or master
). You must use an access token with the security_events
scope to use
this endpoint with private repos, the public_repo
scope also grants permission to read
security events on public repos only. GitHub Apps must have the security_events
read
permission to use this endpoint.
The response includes a most_recent_instance
object.
This provides details of the most recent instance of this alert
for the default branch or for the specified Git reference
(if you used ref
in the request).
GitHub API docs for list_alerts_for_repo
pub fn list_alerts_for_repo(
&self,
owner: &str,
repo: &str,
query_params: Option<impl Into<CodeScanningListAlertsForRepoParams<'api>>>
) -> Result<Vec<CodeScanningAlertItems>, CodeScanningListAlertsForRepoError>
pub fn list_alerts_for_repo(
&self,
owner: &str,
repo: &str,
query_params: Option<impl Into<CodeScanningListAlertsForRepoParams<'api>>>
) -> Result<Vec<CodeScanningAlertItems>, CodeScanningListAlertsForRepoError>
List code scanning alerts for a repository
Lists all open code scanning alerts for the default branch (usually main
or master
). You must use an access token with the security_events
scope to use
this endpoint with private repos, the public_repo
scope also grants permission to read
security events on public repos only. GitHub Apps must have the security_events
read
permission to use this endpoint.
The response includes a most_recent_instance
object.
This provides details of the most recent instance of this alert
for the default branch or for the specified Git reference
(if you used ref
in the request).
GitHub API docs for list_alerts_for_repo
pub async fn list_recent_analyses_async(
&self,
owner: &str,
repo: &str,
query_params: Option<impl Into<CodeScanningListRecentAnalysesParams>>
) -> Result<Vec<CodeScanningAnalysis>, CodeScanningListRecentAnalysesError>
pub async fn list_recent_analyses_async(
&self,
owner: &str,
repo: &str,
query_params: Option<impl Into<CodeScanningListRecentAnalysesParams>>
) -> Result<Vec<CodeScanningAnalysis>, CodeScanningListRecentAnalysesError>
List code scanning analyses for a repository
Lists the details of all code scanning analyses for a repository,
starting with the most recent.
The response is paginated and you can use the page
and per_page
parameters
to list the analyses you’re interested in.
By default 30 analyses are listed per page.
The rules_count
field in the response give the number of rules
that were run in the analysis.
For very old analyses this data is not available,
and 0
is returned in this field.
You must use an access token with the security_events
scope to use this endpoint with private repos,
the public_repo
scope also grants permission to read security events on public repos only.
GitHub Apps must have the security_events
read permission to use this endpoint.
Deprecation notice:
The tool_name
field is deprecated and will, in future, not be included in the response for this endpoint. The example response reflects this change. The tool name can now be found inside the tool
field.
GitHub API docs for list_recent_analyses
pub fn list_recent_analyses(
&self,
owner: &str,
repo: &str,
query_params: Option<impl Into<CodeScanningListRecentAnalysesParams>>
) -> Result<Vec<CodeScanningAnalysis>, CodeScanningListRecentAnalysesError>
pub fn list_recent_analyses(
&self,
owner: &str,
repo: &str,
query_params: Option<impl Into<CodeScanningListRecentAnalysesParams>>
) -> Result<Vec<CodeScanningAnalysis>, CodeScanningListRecentAnalysesError>
List code scanning analyses for a repository
Lists the details of all code scanning analyses for a repository,
starting with the most recent.
The response is paginated and you can use the page
and per_page
parameters
to list the analyses you’re interested in.
By default 30 analyses are listed per page.
The rules_count
field in the response give the number of rules
that were run in the analysis.
For very old analyses this data is not available,
and 0
is returned in this field.
You must use an access token with the security_events
scope to use this endpoint with private repos,
the public_repo
scope also grants permission to read security events on public repos only.
GitHub Apps must have the security_events
read permission to use this endpoint.
Deprecation notice:
The tool_name
field is deprecated and will, in future, not be included in the response for this endpoint. The example response reflects this change. The tool name can now be found inside the tool
field.
GitHub API docs for list_recent_analyses
pub async fn update_alert_async(
&self,
owner: &str,
repo: &str,
alert_number: AlertNumber,
body: PatchCodeScanningUpdateAlert
) -> Result<CodeScanningAlert, CodeScanningUpdateAlertError>
pub async fn update_alert_async(
&self,
owner: &str,
repo: &str,
alert_number: AlertNumber,
body: PatchCodeScanningUpdateAlert
) -> Result<CodeScanningAlert, CodeScanningUpdateAlertError>
Update a code scanning alert
Updates the status of a single code scanning alert. You must use an access token with the security_events
scope to use this endpoint with private repositories. You can also use tokens with the public_repo
scope for public repositories only. GitHub Apps must have the security_events
write permission to use this endpoint.
GitHub API docs for update_alert
pub fn update_alert(
&self,
owner: &str,
repo: &str,
alert_number: AlertNumber,
body: PatchCodeScanningUpdateAlert
) -> Result<CodeScanningAlert, CodeScanningUpdateAlertError>
pub fn update_alert(
&self,
owner: &str,
repo: &str,
alert_number: AlertNumber,
body: PatchCodeScanningUpdateAlert
) -> Result<CodeScanningAlert, CodeScanningUpdateAlertError>
Update a code scanning alert
Updates the status of a single code scanning alert. You must use an access token with the security_events
scope to use this endpoint with private repositories. You can also use tokens with the public_repo
scope for public repositories only. GitHub Apps must have the security_events
write permission to use this endpoint.
GitHub API docs for update_alert
pub async fn upload_sarif_async(
&self,
owner: &str,
repo: &str,
body: PostCodeScanningUploadSarif
) -> Result<CodeScanningSarifsReceipt, CodeScanningUploadSarifError>
pub async fn upload_sarif_async(
&self,
owner: &str,
repo: &str,
body: PostCodeScanningUploadSarif
) -> Result<CodeScanningSarifsReceipt, CodeScanningUploadSarifError>
Upload an analysis as SARIF data
Uploads SARIF data containing the results of a code scanning analysis to make the results available in a repository. You must use an access token with the security_events
scope to use this endpoint for private repositories. You can also use tokens with the public_repo
scope for public repositories only. GitHub Apps must have the security_events
write permission to use this endpoint.
There are two places where you can upload code scanning results.
- If you upload to a pull request, for example
--ref refs/pull/42/merge
or--ref refs/pull/42/head
, then the results appear as alerts in a pull request check. For more information, see “Triaging code scanning alerts in pull requests.” - If you upload to a branch, for example
--ref refs/heads/my-branch
, then the results appear in the Security tab for your repository. For more information, see “Managing code scanning alerts for your repository.”
You must compress the SARIF-formatted analysis data that you want to upload, using gzip
, and then encode it as a Base64 format string. For example:
gzip -c analysis-data.sarif | base64 -w0
SARIF upload supports a maximum of 5000 results per analysis run. Any results over this limit are ignored and any SARIF uploads with more than 25,000 results are rejected. Typically, but not necessarily, a SARIF file contains a single run of a single tool. If a code scanning tool generates too many results, you should update the analysis configuration to run only the most important rules or queries.
The 202 Accepted
, response includes an id
value.
You can use this ID to check the status of the upload by using this for the /sarifs/{sarif_id}
endpoint.
For more information, see “Get information about a SARIF upload.”
GitHub API docs for upload_sarif
pub fn upload_sarif(
&self,
owner: &str,
repo: &str,
body: PostCodeScanningUploadSarif
) -> Result<CodeScanningSarifsReceipt, CodeScanningUploadSarifError>
pub fn upload_sarif(
&self,
owner: &str,
repo: &str,
body: PostCodeScanningUploadSarif
) -> Result<CodeScanningSarifsReceipt, CodeScanningUploadSarifError>
Upload an analysis as SARIF data
Uploads SARIF data containing the results of a code scanning analysis to make the results available in a repository. You must use an access token with the security_events
scope to use this endpoint for private repositories. You can also use tokens with the public_repo
scope for public repositories only. GitHub Apps must have the security_events
write permission to use this endpoint.
There are two places where you can upload code scanning results.
- If you upload to a pull request, for example
--ref refs/pull/42/merge
or--ref refs/pull/42/head
, then the results appear as alerts in a pull request check. For more information, see “Triaging code scanning alerts in pull requests.” - If you upload to a branch, for example
--ref refs/heads/my-branch
, then the results appear in the Security tab for your repository. For more information, see “Managing code scanning alerts for your repository.”
You must compress the SARIF-formatted analysis data that you want to upload, using gzip
, and then encode it as a Base64 format string. For example:
gzip -c analysis-data.sarif | base64 -w0
SARIF upload supports a maximum of 5000 results per analysis run. Any results over this limit are ignored and any SARIF uploads with more than 25,000 results are rejected. Typically, but not necessarily, a SARIF file contains a single run of a single tool. If a code scanning tool generates too many results, you should update the analysis configuration to run only the most important rules or queries.
The 202 Accepted
, response includes an id
value.
You can use this ID to check the status of the upload by using this for the /sarifs/{sarif_id}
endpoint.
For more information, see “Get information about a SARIF upload.”
GitHub API docs for upload_sarif