Esta versión de GitHub Enterprise se discontinuó el 2022-06-03. No se realizarán lanzamientos de patch, ni siquiera para problemas de seguridad críticos. Para obtener un mejor desempeño, más seguridad y nuevas características, actualiza a la última versión de GitHub Enterprise. Para obtener ayuda con la actualización, contacta al soporte de GitHub Enterprise.
Code Scanning
La API del escaneo de código te permite recuperar y actualizar las alertas del escaneo de código desde un repositorio.
About the Code scanning API
La API del escaneo de código te permite recuperar y actualizar las alertas del escaneo de código desde un repositorio. Puedes utilizar las terminales para crear reportes automatizados para las alertas del escaneo de código en una organización o cargar resutlados de análisis que se hayan generado utilizando con herramientas fuera de línea del escaneo de código. Para obtener más información, consulta la sección "Encontrar vulnerabilidades de seguridad y errores en tu código".
Tipos de medios personalizados para el escaneo de código
Hay un tipo de medios personalizado compatible para la API de REST del escaneo de código.
application/sarif+json
Puedes utilizarla con las solicitudes de tipo GET
que envíes a la terminal de /analyses/{analysis_id}
. Para obtener más información sobre esta operación, consulta la sección Obtén un análisis del escaneo de código para un repositorio". Cuando utilices este tipo de medios con esta operación, la respuesta incluirá un subconjunto de los datos actuals que se cargaron para el análisis específico en vez del resumen del análisis que se devuelve cuando utilizas el tipo de medios predeterminado. La respuesta también incluye datos adicionales, tales como las propiedades de github/alertNumber
y github/alertUrl
. Estos datos tienen formato de SARIF versión 2.1.0.
Para obtener más información, consulta la sección "Tipos de medios".
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. 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).
Parámetros
Encabezados |
---|
Nombre, Tipo, Descripción |
accept stringSetting to |
Parámetros de ruta |
Nombre, Tipo, Descripción |
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. |
repo stringRequeridoThe name of the repository. The name is not case sensitive. |
Parámetros de consulta |
Nombre, Tipo, Descripción |
tool_name stringThe name of a code scanning tool. Only results by this tool will be listed. You can specify the tool by using either |
tool_guid string or nullThe GUID of a code scanning tool. Only results by this tool will be listed. Note that some code scanning tools may not include a GUID in their analysis data. You can specify the tool by using either |
page integerPage number of the results to fetch. Predeterminado: |
per_page integerThe number of results per page (max 100). Predeterminado: |
ref stringThe Git reference for the results you want to list. The |
state stringSet to Puede ser una de las siguientes: |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
200 | OK |
403 | Response if GitHub Advanced Security is not enabled for this repository |
404 | Resource not found |
503 | Service unavailable |
Ejemplos de código
curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/code-scanning/alerts
Response
Status: 200
[
{
"number": 4,
"created_at": "2020-02-13T12:29:18Z",
"url": "https://api.github.com/repos/octocat/hello-world/code-scanning/alerts/4",
"html_url": "https://github.com/octocat/hello-world/code-scanning/4",
"state": "open",
"dismissed_by": null,
"dismissed_at": null,
"dismissed_reason": null,
"rule": {
"id": "js/zipslip",
"severity": "error",
"description": "Arbitrary file write during zip extraction",
"name": "js/zipslip"
},
"tool": {
"name": "CodeQL",
"guid": null,
"version": "2.4.0"
},
"most_recent_instance": {
"ref": "refs/heads/main",
"analysis_key": ".github/workflows/codeql-analysis.yml:CodeQL-Build",
"environment": "{}",
"state": "open",
"commit_sha": "39406e42cb832f683daa691dd652a8dc36ee8930",
"message": {
"text": "This path depends on a user-provided value."
},
"location": {
"path": "spec-main/api-session-spec.ts",
"start_line": 917,
"end_line": 917,
"start_column": 7,
"end_column": 18
},
"classifications": [
"test"
]
},
"instances_url": "https://api.github.com/repos/octocat/hello-world/code-scanning/alerts/4/instances"
},
{
"number": 3,
"created_at": "2020-02-13T12:29:18Z",
"url": "https://api.github.com/repos/octocat/hello-world/code-scanning/alerts/3",
"html_url": "https://github.com/octocat/hello-world/code-scanning/3",
"state": "dismissed",
"dismissed_by": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
},
"dismissed_at": "2020-02-14T12:29:18Z",
"dismissed_reason": "false positive",
"rule": {
"id": "js/zipslip",
"severity": "error",
"description": "Arbitrary file write during zip extraction",
"name": "js/zipslip"
},
"tool": {
"name": "CodeQL",
"guid": null,
"version": "2.4.0"
},
"most_recent_instance": {
"ref": "refs/heads/main",
"analysis_key": ".github/workflows/codeql-analysis.yml:CodeQL-Build",
"environment": "{}",
"state": "open",
"commit_sha": "39406e42cb832f683daa691dd652a8dc36ee8930",
"message": {
"text": "This path depends on a user-provided value."
},
"location": {
"path": "lib/ab12-gen.js",
"start_line": 917,
"end_line": 917,
"start_column": 7,
"end_column": 18
},
"classifications": []
},
"instances_url": "https://api.github.com/repos/octocat/hello-world/code-scanning/alerts/3/instances"
}
]
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. 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
.
Parámetros
Encabezados |
---|
Nombre, Tipo, Descripción |
accept stringSetting to |
Parámetros de ruta |
Nombre, Tipo, Descripción |
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. |
repo stringRequeridoThe name of the repository. The name is not case sensitive. |
alert_number integerRequeridoThe number that identifies an alert. You can find this at the end of the URL for a code scanning alert within GitHub, and in the |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
200 | OK |
403 | Response if GitHub Advanced Security is not enabled for this repository |
404 | Resource not found |
503 | Service unavailable |
Ejemplos de código
curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/code-scanning/alerts/ALERT_NUMBER
Response
Status: 200
{
"number": 42,
"created_at": "2020-06-19T11:21:34Z",
"url": "https://api.github.com/repos/octocat/hello-world/code-scanning/alerts/42",
"html_url": "https://github.com/octocat/hello-world/code-scanning/42",
"state": "dismissed",
"dismissed_by": {
"login": "octocat",
"id": 54933897,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
},
"dismissed_at": "2020-02-14T12:29:18Z",
"dismissed_reason": "false positive",
"rule": {
"id": "js/zipslip",
"severity": "error",
"description": "Arbitrary file write during zip extraction (\"Zip Slip\")",
"name": "js/zipslip",
"full_description": "Extracting files from a malicious zip archive without validating that the destination file path is within the destination directory can cause files outside the destination directory to be overwritten.",
"tags": [
"security",
"external/cwe/cwe-022"
],
"help": "# Arbitrary file write during zip extraction (\"Zip Slip\")\\nExtracting files from a malicious zip archive without validating that the destination file path is within the destination directory can cause files outside the destination directory to be overwritten ..."
},
"tool": {
"name": "CodeQL",
"guid": null,
"version": "2.4.0"
},
"most_recent_instance": {
"ref": "refs/heads/main",
"analysis_key": ".github/workflows/codeql-analysis.yml:CodeQL-Build",
"environment": "{}",
"state": "dismissed",
"commit_sha": "39406e42cb832f683daa691dd652a8dc36ee8930",
"message": {
"text": "This path depends on a user-provided value."
},
"location": {
"path": "spec-main/api-session-spec.ts",
"start_line": 917,
"end_line": 917,
"start_column": 7,
"end_column": 18
},
"classifications": [
"test"
]
},
"instances_url": "https://api.github.com/repos/octocat/hello-world/code-scanning/alerts/42/instances"
}
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. GitHub Apps must have the security_events
write permission to use this endpoint.
Parámetros
Encabezados |
---|
Nombre, Tipo, Descripción |
accept stringSetting to |
Parámetros de ruta |
Nombre, Tipo, Descripción |
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. |
repo stringRequeridoThe name of the repository. The name is not case sensitive. |
alert_number integerRequeridoThe number that identifies an alert. You can find this at the end of the URL for a code scanning alert within GitHub, and in the |
Parámetros de cuerpo |
Nombre, Tipo, Descripción |
state stringRequeridoSets the state of the code scanning alert. You must provide Puede ser una de las siguientes: |
dismissed_reason string or nullRequired when the state is dismissed. The reason for dismissing or closing the alert. Puede ser una de las siguientes: |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
200 | OK |
403 | Response if the repository is archived or if github advanced security is not enabled for this repository |
404 | Resource not found |
503 | Service unavailable |
Ejemplos de código
curl \
-X PATCH \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/code-scanning/alerts/ALERT_NUMBER \
-d '{"state":"dismissed","dismissed_reason":"false positive","dismissed_comment":"This alert is not actually correct, because there's a sanitizer included in the library."}'
Response
Status: 200
{
"number": 42,
"created_at": "2020-08-25T21:28:36Z",
"url": "https://api.github.com/repos/octocat/hello-world/code-scanning/alerts/42",
"html_url": "https://github.com/octocat/hello-world/code-scanning/42",
"state": "dismissed",
"dismissed_by": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
},
"dismissed_at": "2020-09-02T22:34:56Z",
"dismissed_reason": "false positive",
"rule": {
"id": "js/zipslip",
"severity": "error",
"description": "Arbitrary file write during zip extraction (\"Zip Slip\")",
"name": "js/zipslip",
"full_description": "Extracting files from a malicious zip archive without validating that the destination file path is within the destination directory can cause files outside the destination directory to be overwritten.",
"tags": [
"security",
"external/cwe/cwe-022"
],
"help": "# Arbitrary file write during zip extraction (\"Zip Slip\")\\nExtracting files from a malicious zip archive without validating that the destination file path is within the destination directory can cause files outside the destination directory to be overwritten ..."
},
"tool": {
"name": "CodeQL",
"guid": null,
"version": "2.4.0"
},
"most_recent_instance": {
"ref": "refs/heads/main",
"analysis_key": ".github/workflows/codeql-analysis.yml:CodeQL-Build",
"environment": "{}",
"state": "dismissed",
"commit_sha": "39406e42cb832f683daa691dd652a8dc36ee8930",
"message": {
"text": "This path depends on a user-provided value."
},
"location": {
"path": "spec-main/api-session-spec.ts",
"start_line": 917,
"end_line": 917,
"start_column": 7,
"end_column": 18
},
"classifications": [
"test"
]
},
"instances_url": "https://api.github.com/repos/octocat/hello-world/code-scanning/alerts/42/instances"
}
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. GitHub Apps must have the security_events
read permission to use this endpoint.
Parámetros
Encabezados |
---|
Nombre, Tipo, Descripción |
accept stringSetting to |
Parámetros de ruta |
Nombre, Tipo, Descripción |
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. |
repo stringRequeridoThe name of the repository. The name is not case sensitive. |
alert_number integerRequeridoThe number that identifies an alert. You can find this at the end of the URL for a code scanning alert within GitHub, and in the |
Parámetros de consulta |
Nombre, Tipo, Descripción |
page integerPage number of the results to fetch. Predeterminado: |
per_page integerThe number of results per page (max 100). Predeterminado: |
ref stringThe Git reference for the results you want to list. The |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
200 | OK |
403 | Response if GitHub Advanced Security is not enabled for this repository |
404 | Resource not found |
503 | Service unavailable |
Ejemplos de código
curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/code-scanning/alerts/ALERT_NUMBER/instances
Response
Status: 200
[
{
"ref": "refs/heads/main",
"analysis_key": ".github/workflows/codeql-analysis.yml:CodeQL-Build",
"environment": "",
"state": "open",
"commit_sha": "39406e42cb832f683daa691dd652a8dc36ee8930",
"message": {
"text": "This path depends on a user-provided value."
},
"location": {
"path": "lib/ab12-gen.js",
"start_line": 917,
"end_line": 917,
"start_column": 7,
"end_column": 18
},
"classifications": [
"library"
]
},
{
"ref": "refs/pull/3740/merge",
"analysis_key": ".github/workflows/codeql-analysis.yml:CodeQL-Build",
"environment": "",
"category": ".github/workflows/codeql-analysis.yml:CodeQL-Build",
"state": "fixed",
"commit_sha": "b09da05606e27f463a2b49287684b4ae777092f2",
"message": {
"text": "This suffix check is missing a length comparison to correctly handle lastIndexOf returning -1."
},
"location": {
"path": "app/script.js",
"start_line": 2,
"end_line": 2,
"start_column": 10,
"end_column": 50
},
"classifications": [
"source"
]
}
]
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.
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.
Parámetros
Encabezados |
---|
Nombre, Tipo, Descripción |
accept stringSetting to |
Parámetros de ruta |
Nombre, Tipo, Descripción |
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. |
repo stringRequeridoThe name of the repository. The name is not case sensitive. |
Parámetros de consulta |
Nombre, Tipo, Descripción |
tool_name stringThe name of a code scanning tool. Only results by this tool will be listed. You can specify the tool by using either |
tool_guid string or nullThe GUID of a code scanning tool. Only results by this tool will be listed. Note that some code scanning tools may not include a GUID in their analysis data. You can specify the tool by using either |
page integerPage number of the results to fetch. Predeterminado: |
per_page integerThe number of results per page (max 100). Predeterminado: |
ref stringThe Git reference for the analyses you want to list. The |
sarif_id stringFilter analyses belonging to the same SARIF upload. |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
200 | OK |
403 | Response if GitHub Advanced Security is not enabled for this repository |
404 | Resource not found |
503 | Service unavailable |
Ejemplos de código
curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/code-scanning/analyses
Response
Status: 200
[
{
"ref": "refs/heads/main",
"commit_sha": "d99612c3e1f2970085cfbaeadf8f010ef69bad83",
"analysis_key": ".github/workflows/codeql-analysis.yml:analyze",
"environment": "{\"language\":\"python\"}",
"error": "",
"category": ".github/workflows/codeql-analysis.yml:analyze/language:python",
"created_at": "2020-08-27T15:05:21Z",
"results_count": 17,
"rules_count": 49,
"id": 201,
"url": "https://api.github.com/repos/octocat/hello-world/code-scanning/analyses/201",
"sarif_id": "6c81cd8e-b078-4ac3-a3be-1dad7dbd0b53",
"tool": {
"name": "CodeQL",
"guid": null,
"version": "2.4.0"
},
"deletable": true,
"warning": ""
},
{
"ref": "refs/heads/my-branch",
"commit_sha": "c8cff6510d4d084fb1b4aa13b64b97ca12b07321",
"analysis_key": ".github/workflows/shiftleft.yml:build",
"environment": "{}",
"error": "",
"category": ".github/workflows/shiftleft.yml:build/",
"created_at": "2020-08-31T22:46:44Z",
"results_count": 17,
"rules_count": 32,
"id": 200,
"url": "https://api.github.com/repos/octocat/hello-world/code-scanning/analyses/200",
"sarif_id": "8981cd8e-b078-4ac3-a3be-1dad7dbd0b582",
"tool": {
"name": "Python Security Analysis",
"guid": null,
"version": "1.2.0"
},
"deletable": true,
"warning": ""
}
]
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.
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.
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.
Parámetros
Encabezados |
---|
Nombre, Tipo, Descripción |
accept stringSetting to |
Parámetros de ruta |
Nombre, Tipo, Descripción |
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. |
repo stringRequeridoThe name of the repository. The name is not case sensitive. |
analysis_id integerRequeridoThe ID of the analysis, as returned from the |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
200 | OK |
403 | Response if GitHub Advanced Security is not enabled for this repository |
404 | Resource not found |
503 | Service unavailable |
Ejemplos de código
curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/code-scanning/analyses/ANALYSIS_ID
Default response
Status: 200
{
"ref": "refs/heads/main",
"commit_sha": "c18c69115654ff0166991962832dc2bd7756e655",
"analysis_key": ".github/workflows/codeql-analysis.yml:analyze",
"environment": "{\"language\":\"javascript\"}",
"error": "",
"category": ".github/workflows/codeql-analysis.yml:analyze/language:javascript",
"created_at": "2021-01-13T11:55:49Z",
"results_count": 3,
"rules_count": 67,
"id": 3602840,
"url": "https://api.github.com/repos/octocat/hello-world/code-scanning/analyses/201",
"sarif_id": "47177e22-5596-11eb-80a1-c1e54ef945c6",
"tool": {
"name": "CodeQL",
"guid": null,
"version": "2.4.0"
},
"deletable": true,
"warning": ""
}
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
and repo:security_events
scopes.
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.
Note: The ability to delete analyses was introduced in GitHub Enterprise Server 3.1. You can delete analyses that were generated prior to installing this release, however, if you do so, you will lose information about fixed alerts for all such analyses, for the relevant code scanning tool. We recommend that you only delete analyses that were generated with earlier releases if you don't need the details of fixed alerts from pre-3.1 releases.
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
(see the example default response below).
Use the next_analysis_url
URL if you want to avoid accidentally deleting the final analysis
in the 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 the deletable analysis for one of the sets, step through deleting the analyses in that set, and 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.
Parámetros
Encabezados |
---|
Nombre, Tipo, Descripción |
accept stringSetting to |
Parámetros de ruta |
Nombre, Tipo, Descripción |
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. |
repo stringRequeridoThe name of the repository. The name is not case sensitive. |
analysis_id integerRequeridoThe ID of the analysis, as returned from the |
Parámetros de consulta |
Nombre, Tipo, Descripción |
confirm_delete string or nullAllow deletion if the specified analysis is the last in a set. If you attempt to delete the final analysis in a set without setting this parameter to |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
200 | OK |
400 | Bad Request |
403 | Response if the repository is archived or if github advanced security is not enabled for this repository |
404 | Resource not found |
503 | Service unavailable |
Ejemplos de código
curl \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/code-scanning/analyses/ANALYSIS_ID
Default response
Status: 200
{
"next_analysis_url": "https://api.github.com/repos/octocat/hello-world/code-scanning/analyses/41",
"confirm_delete_url": "https://api.github.com/repos/octocat/hello-world/code-scanning/analyses/41?confirm_delete"
}
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. 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."
Parámetros
Encabezados |
---|
Nombre, Tipo, Descripción |
accept stringSetting to |
Parámetros de ruta |
Nombre, Tipo, Descripción |
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. |
repo stringRequeridoThe name of the repository. The name is not case sensitive. |
Parámetros de cuerpo |
Nombre, Tipo, Descripción |
commit_sha stringRequeridoThe SHA of the commit to which the analysis you are uploading relates. |
ref stringRequeridoThe full Git reference, formatted as |
sarif stringRequeridoA Base64 string representing the SARIF file to upload. You must first compress your SARIF file using |
checkout_uri stringThe base directory used in the analysis, as it appears in the SARIF file. This property is used to convert file paths from absolute to relative, so that alerts can be mapped to their correct location in the repository. |
started_at stringThe time that the analysis run began. This is a timestamp in ISO 8601 format: |
tool_name stringThe name of the tool used to generate the code scanning analysis. If this parameter is not used, the tool name defaults to "API". If the uploaded SARIF contains a tool GUID, this will be available for filtering using the |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
202 | Accepted |
400 | Bad Request if the sarif field is invalid |
403 | Response if the repository is archived or if github advanced security is not enabled for this repository |
404 | Resource not found |
413 | Payload Too Large if the sarif field is too large |
503 | Service unavailable |
Ejemplos de código
curl \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/code-scanning/sarifs
Default response
Status: 202
{
"id": "47177e22-5596-11eb-80a1-c1e54ef945c6",
"url": "https://api.github.com/repos/octocat/hello-world/code-scanning/sarifs/47177e22-5596-11eb-80a1-c1e54ef945c6"
}
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. GitHub Apps must have the security_events
read permission to use this endpoint.
Parámetros
Encabezados |
---|
Nombre, Tipo, Descripción |
accept stringSetting to |
Parámetros de ruta |
Nombre, Tipo, Descripción |
owner stringRequeridoThe account owner of the repository. The name is not case sensitive. |
repo stringRequeridoThe name of the repository. The name is not case sensitive. |
sarif_id stringRequeridoThe SARIF ID obtained after uploading. |
Códigos de estado de respuesta HTTP
Código de estado | Descripción |
---|---|
200 | OK |
403 | Response if GitHub Advanced Security is not enabled for this repository |
404 | Not Found if the sarif id does not match any upload |
503 | Service unavailable |
Ejemplos de código
curl \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token <TOKEN>" \
http(s)://HOSTNAME/api/v3/repos/OWNER/REPO/code-scanning/sarifs/SARIF_ID
Default response
Status: 200
{
"processing_status": "complete",
"analyses_url": "https://api.github.com/repos/octocat/hello-world/code-scanning/analyses?sarif_id=47177e22-5596-11eb-80a1-c1e54ef945c6"
}