适用于依赖项提交的 REST API 终结点
使用 REST API 提交依赖项。
关于依赖项提交
可以使用 REST API 提交项目的依赖项。 这使你可以将依赖项(如编译或生成软件时解析的依赖项)添加到 GitHub 的依赖项关系图功能,从而更全面地了解项目的所有依赖项。
依赖项关系图显示你使用 API 提交的任何依赖项,以及从存储库中的清单或锁定文件(例如 package-lock.json
JavaScript 项目中的文件)标识的任何依赖项。 有关查看依赖项关系图的详细信息,请参阅“探索仓库的依赖项”。
提交的依赖项将收到 Dependabot alerts 和 Dependabot security updates 以处理任何已知的漏洞。 你只会收到来自 GitHub Advisory Database 支持的生态系统之一的依赖关系的 Dependabot alerts。 有关这些生态系统的详细信息,请参阅“关于 GitHub 公告数据库”。 对于通过 依赖项提交 API 提交的可传递依赖项,如果更新可用,Dependabot 将自动打开拉取请求以更新父依赖项。
提交的依赖项将会显示在依赖项审查中,但_不会_显示在组织的依赖项见解中。
Note
依赖关系审查 API 和 依赖项提交 API 协同工作。 这意味着依赖关系审查 API 将包括通过 依赖项提交 API 提交的依赖关系。 __
可以通过快照的形式提交依赖项。 快照是一组与提交 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.
The authenticated user must have access to the repository.
OAuth app tokens and personal access tokens (classic) need the repo
scope to use this endpoint.
“Create a snapshot of dependencies for a repository”的细粒度访问令牌
此端点支持以下精细令牌类型:
精细令牌必须具有以下权限集:
- "Contents" repository permissions (write)
“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.
“Create a snapshot of dependencies for a repository”的 HTTP 响应状态代码
状态代码 | 说明 |
---|---|
201 | Created |
“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" \
http(s)://HOSTNAME/api/v3/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