Skip to main content
The REST API is now versioned. For more information, see "About API versioning."

Codeüberprüfung

Mit der code scanning-API kannst du code scanning-Warnungen aus einem Repository abrufen und aktualisieren.

Informationen zur Codeüberprüfungs-API

Mit der code scanning-API kannst du code scanning-Warnungen aus einem Repository abrufen und aktualisieren. Du kannst die Endpunkte verwenden, um automatisierte Berichte für code scanning-Warnungen in einer Organisation zu erstellen oder Analyseergebnisse hochzuladen, die mit Offline-code scanning-Tools generiert wurden. Weitere Informationen findest du unter Suchen von Sicherheitsrisiken und Fehlern in deinem Code.

Benutzerdefinierter Medientyp für die code scanning

Es gibt einen unterstützten benutzerdefinierten Medientyp für die code scanning-REST-API.

application/sarif+json

Du kannst diesen mit GET-Anforderungen an den /analyses/{analysis_id}-Endpunkt senden. Weitere Informationen zu diesem Vorgang findest du unter Abrufen einer code scanning-Analyse für ein Repository. Wenn du diesen Medientyp mit diesem Vorgang verwendest, enthält die Antwort eine Teilmenge der tatsächlichen Daten, die für die angegebene Analyse hochgeladen wurden, anstatt der Zusammenfassung der Analyse, die zurückgegeben wird, wenn du den Standardmedientyp verwendest. Die Antwort enthält auch zusätzliche Daten, z. B. die github/alertNumber- und github/alertUrl-Eigenschaften. Die Daten werden mit der SARIF-Version 2.1.0 formatiert.

Weitere Informationen findest du unter Medientypen.

List code scanning alerts for an enterprise

Lists code scanning alerts for the default branch for all eligible repositories in an enterprise. Eligible repositories are repositories that are owned by organizations that you own or for which you are a security manager. For more information, see "Managing security managers in your organization."

To use this endpoint, you must be a member of the enterprise, and you must use an access token with the repo scope or security_events scope.

Parameters

Headers
Name, Type, Description
acceptstring

Setting to application/vnd.github+json is recommended.

Path parameters
Name, Type, Description
enterprisestringRequired

The slug version of the enterprise name. You can also substitute this value with the enterprise id.

Query parameters
Name, Type, Description
tool_namestring

The name of a code scanning tool. Only results by this tool will be listed. You can specify the tool by using either tool_name or tool_guid, but not both.

tool_guidstringnull

The 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 tool_guid or tool_name, but not both.

beforestring

A cursor, as given in the Link header. If specified, the query only searches for results before this cursor.

afterstring

A cursor, as given in the Link header. If specified, the query only searches for results after this cursor.

pageinteger

Page number of the results to fetch.

Default: 1

per_pageinteger

The number of results per page (max 100).

Default: 30

directionstring

The direction to sort the results by.

Default: desc

Can be one of: asc, desc

statestring

If specified, only code scanning alerts with this state will be returned.

Can be one of: open, closed, dismissed, fixed

sortstring

The property by which to sort the results.

Default: created

Can be one of: created, updated

HTTP response status codes

Status codeDescription
200

OK

404

Resource not found

503

Service unavailable

Code samples

get/enterprises/{enterprise}/code-scanning/alerts
curl \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer <YOUR-TOKEN>"\ -H "X-GitHub-Api-Version: 2022-11-28" \ https://api.github.com/enterprises/ENTERPRISE/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, "dismissed_comment": null, "rule": { "id": "js/zipslip", "severity": "error", "tags": [ "security", "external/cwe/cwe-022" ], "description": "Arbitrary