依赖项提交
通过依赖项提交 API,可以提交项目依赖项,例如生成或编译项目时解析的依赖项。
关于依赖项提交 API
注意:依赖项提交 API 目前以公共 Beta 版本提供,可能会发生更改。
使用依赖项提交 API,可以提交项目的依赖项。 这使你可以将依赖项(如编译或生成软件时解析的依赖项)添加到 GitHub 的依赖项关系图功能,从而更全面地了解项目的所有依赖项。
依赖项关系图显示你使用 API 提交的任何依赖项,以及从存储库中的清单或锁定文件(例如 package-lock.json JavaScript 项目中的文件)标识的任何依赖项。 若要详细了解如何查看依赖项关系图,请参阅“探索存储库的依赖项”。
提交的依赖项将收到 Dependabot alerts 和 Dependabot security updates 以处理任何已知的漏洞。 你只会收到来自 GitHub Advisory Database 支持的生态系统之一的依赖项的 Dependabot alerts。 提交的依赖项将不会显示在依赖项评审或组织的依赖项见解中。
依赖项以快照的形式提交到依赖项提交 API。 快照是一组与提交 SHA 和其他元数据关联的依赖项,反映提交存储库的当前状态。 可以选择使用预先创建的操作,或创建自己的操作,以在每次生成项目时,以所需的格式将依赖项提交到依赖项提交 API。 有关使用依赖项提交 API 的详细信息,请参阅“使用依赖项提交 API”。
可以将多个依赖项集提交到依赖项提交 API,以包含在依赖项关系图中。 API 使用快照的 job.correlator 属性和 detector.name 类别来确保显示每个工作流的最新提交。 属性 correlator 本身是用于保持独立提交不同的主要字段。 例如 correlator 可以是操作运行中两个可用变量的简单组合:<GITHUB_WORKFLOW> <GITHUB_JOB>。
Create a snapshot of dependencies for a repository
Create a new snapshot of a repository's dependencies. You must authenticate using an access token with the repo scope to use this endpoint for a repository that the requesting user has access to.
Parameters
| Headers | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Name, Type, Description | ||||||||||||||||||||||||||||||||||||
acceptstringSetting to | ||||||||||||||||||||||||||||||||||||
| Path parameters | ||||||||||||||||||||||||||||||||||||
| Name, Type, Description | ||||||||||||||||||||||||||||||||||||
ownerstringRequiredThe account owner of the repository. The name is not case sensitive. | ||||||||||||||||||||||||||||||||||||
repostringRequiredThe name of the repository. The name is not case sensitive. | ||||||||||||||||||||||||||||||||||||
| Body parameters | ||||||||||||||||||||||||||||||||||||
| Name, Type, Description | ||||||||||||||||||||||||||||||||||||
versionintegerRequiredThe version of the repository snapshot submission. | ||||||||||||||||||||||||||||||||||||
jobobjectRequired | ||||||||||||||||||||||||||||||||||||
Properties of | ||||||||||||||||||||||||||||||||||||
| Name, Type, Description |
|---|
idstringRequiredThe external ID of the job. |
correlatorstringRequiredCorrelator provides a key that is used to group snapshots submitted over time. Only the "latest" submitted snapshot for a given combination of |
html_urlstringThe url for the job. |
shastringRequiredThe commit SHA associated with this dependency snapshot. Maximum length: 40 characters.
refstringRequiredThe repository branch that triggered this snapshot.
detectorobjectRequiredA description of the detector used.
Properties of detector
| Name, Type, Description |
|---|
namestringRequiredThe name of the detector used. |
versionstringRequiredThe version of the detector used. |
urlstringRequiredThe url of the detector used. |
metadataobjectUser-defined metadata to store domain-specific information limited to 8 keys with scalar values.
manifestsobjectA collection of package manifests, which are a collection of related dependencies declared in a file or representing a logical group of dependencies.
Properties of manifests
| Name, Type, Description | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
keyobjectA user-defined key to represent an item in | ||||||||||||||||||||||||||||||
Properties of | ||||||||||||||||||||||||||||||
| Name, Type, Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
namestringRequiredThe name of the manifest. | |||||||||||||||
fileobject | |||||||||||||||
Properties of | |||||||||||||||
| Name, Type, Description |
|---|
source_locationstringThe path of the manifest file relative to the root of the Git repository. |
metadataobjectUser-defined metadata to store domain-specific information limited to 8 keys with scalar values.
resolvedobjectA collection of resolved package dependencies.
Properties of resolved
| Name, Type, Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|
keyobjectA user-defined key to represent an item in | |||||||||
Properties of | |||||||||
| Name, Type, Description |
|---|
package_urlstringPackage-url (PURL) of dependency. See https://github.com/package-url/purl-spec for more details. |
metadataobjectUser-defined metadata to store domain-specific information limited to 8 keys with scalar values. |
relationshipstringA notation of whether a dependency is requested directly by this manifest or is a dependency of another dependency. Can be one of: |
scopestringA notation of whether the dependency is required for the primary build artifact (runtime) or is only used for development. Future versions of this specification may allow for more granular scopes. Can be one of: |
dependenciesarray of stringsArray of package-url (PURLs) of direct child dependencies. |
scannedstringRequiredThe time at which the snapshot was scanned.
HTTP response status codes
| Status code | Description |
|---|---|
201 | Created |
Code samples
curl \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer <YOUR-TOKEN>"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/OWNER/REPO/dependency-graph/snapshots \
-d '{"version":0,"sha":"ce587453ced02b1526dfb4cb910479d431683101","ref":"refs/heads/main","job":{"correlator":"yourworkflowname_youractionname","id":"yourrunid"},"detector":{"name":"octo-detector","version":"0.0.1","url":"https://github.com/octo-org/octo-repo"},"scanned":"2022-06-14T20:25:00Z","manifests":{"package-lock.json":{"name":"package-lock.json","file":{"source_location":"src/package-lock.json"},"resolved":{"@actions/core":{"package_url":"pkg:/npm/%40actions/core@1.1.9","dependencies":["@actions/http-client"]},"@actions/http-client":{"package_url":"pkg:/npm/%40actions/http-client@1.0.7","dependencies":["tunnel"]},"tunnel":{"package_url":"pkg:/npm/tunnel@0.0.6"}}}}}'Response
Status: 201{
"id": 12345,
"created_at": "2018-05-04T01:14:52Z",
"message": "Dependency results for the repo have been successfully updated.",
"result": "SUCCESS"
}