依赖项提交
使用 REST API 提交依赖项。
关于依赖项提交
注意:使用 REST API 进行依赖项提交的功能目前为公共 beta 版本,可能会发生更改。
可以使用 REST API 提交项目的依赖项。 这使你可以将依赖项(如编译或生成软件时解析的依赖项)添加到 GitHub 的依赖项关系图功能,从而更全面地了解项目的所有依赖项。
依赖项关系图显示你使用 API 提交的任何依赖项,以及从存储库中的清单或锁定文件(例如 package-lock.json
JavaScript 项目中的文件)标识的任何依赖项。 有关查看依赖项关系图的详细信息,请参阅“探索仓库的依赖项”。
提交的依赖项将收到 Dependabot alerts 和 Dependabot security updates 以处理任何已知的漏洞。 你只会收到来自 GitHub Advisory Database 支持的生态系统之一的依赖关系的 Dependabot alerts。 有关这些生态系统的详细信息,请参阅“关于 GitHub 公告数据库”。 提交的依赖关系将会显示在依赖关系审查或组织的依赖关系见解中。
注意: 依赖关系审查 API 和依赖关系提交 API 协同工作。 这意味着依赖关系审查 API 将包括通过依赖关系提交 API 提交的依赖关系。 此功能目前为公共 beta 版本,可能会有变动。
可以通过快照的形式提交依赖项。 快照是一组与提交 SHA 和其他元数据关联的依赖项,反映提交存储库的当前状态。 可以选择使用预先创建的操作,或创建自己的操作,在每次生成项目时,以所需的格式提交依赖项。 有关详细信息,请参阅“使用依赖项提交 API”。
可以提交多个依赖项集,以包含在依赖项关系图中。 REST 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 for "Create a snapshot of dependencies for a repository"
名称, 类型, 说明 |
---|
accept string Setting to |
名称, 类型, 说明 |
---|
owner string 必须The account owner of the repository. The name is not case sensitive. |
repo string 必须The name of the repository without the |
名称, 类型, 说明 | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
version integer 必须The version of the repository snapshot submission. | |||||||||||||||||||||
job object 必须 | |||||||||||||||||||||
Properties of |
名称, 类型, 说明 |
---|
id string 必须The external ID of the job. |
correlator string 必须Correlator provides a key that is used to group snapshots submitted over time. Only the "latest" submitted snapshot for a given combination of |
html_url string The url for the job. |
sha
string 必须The commit SHA associated with this dependency snapshot. Maximum length: 40 characters.
ref
string 必须The repository branch that triggered this snapshot.
detector
object 必须A description of the detector used.
Properties of detector
名称, 类型, 说明 |
---|
name string 必须The name of the detector used. |
version string 必须The version of the detector used. |
url string 必须The url of the detector used. |
metadata
object User-defined metadata to store domain-specific information limited to 8 keys with scalar values.
manifests
object A 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
名称, 类型, 说明 | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
key object A user-defined key to represent an item in | ||||||||||||||||||
Properties of |
名称, 类型, 说明 | |||||||||
---|---|---|---|---|---|---|---|---|---|
name string 必须The name of the manifest. | |||||||||
file object | |||||||||
Properties of |
名称, 类型, 说明 |
---|
source_location string The path of the manifest file relative to the root of the Git repository. |
metadata
object User-defined metadata to store domain-specific information limited to 8 keys with scalar values.
resolved
object A collection of resolved package dependencies.
Properties of resolved
名称, 类型, 说明 | ||||||
---|---|---|---|---|---|---|
key object A user-defined key to represent an item in | ||||||
Properties of |
名称, 类型, 说明 |
---|
package_url string Package-url (PURL) of dependency. See https://github.com/package-url/purl-spec for more details. |
metadata object User-defined metadata to store domain-specific information limited to 8 keys with scalar values. |
relationship string A notation of whether a dependency is requested directly by this manifest or is a dependency of another dependency. 可以是以下选项之一: |
scope string A 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. 可以是以下选项之一: |
dependencies array of strings Array of package-url (PURLs) of direct child dependencies. |
scanned
string 必须The time at which the snapshot was scanned.
HTTP response status codes for "Create a snapshot of dependencies for a repository"
Status code | Description |
---|---|
201 | Created |
Code samples for "Create a snapshot of dependencies for a repository"
curl -L \
-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"
}