You need to enable JavaScript to run this app. 如何通过GitHub API查询代码仓库是否已启用Dependabot?
优惠活动
大模型
产品
解决方案
定价
更多

如何通过GitHub API查询代码仓库是否已启用Dependabot?

解决方案

GitHub REST API 方案

你可以使用Repositories分类下的Dependabot相关端点完成查询:

  • 查询仓库是否启用Dependabot告警功能,调用GET /repos/{owner}/{repo}/vulnerability-alerts接口,返回204状态码代表已启用,404代表未启用或你没有对应访问权限
  • 查询仓库是否启用Dependabot安全更新功能,调用GET /repos/{owner}/{repo}/automated-security-fixes接口,返回200状态码时响应体中的enabled字段即为功能开关状态
  • 如果需要确认Dependabot版本更新功能是否启用,可以调用GET /repos/{owner}/{repo}/dependabot/alerts接口,接口返回正常且存在有效告警记录即可证明功能已启用;也可以直接查询仓库根目录下的.github/dependabot.yml配置文件是否存在作为辅助判断依据

GitHub GraphQL API 方案

你可以调用Repository对象下的专属字段完成查询,对应字段如下:

  • hasVulnerabilityAlertsEnabled:直接返回布尔值,代表Dependabot告警功能的启用状态
  • automatedSecurityFixes:返回对象中的enabled属性即为Dependabot安全更新功能的开关状态

参考查询语句示例:

query($owner: String!, $repo: String!) {
  repository(owner: $owner, name: $repo) {
    hasVulnerabilityAlertsEnabled
    automatedSecurityFixes {
      enabled
    }
  }
}

注意:所有接口调用都需要你持有对应仓库repo权限范围的访问令牌,私有仓库需要管理员或维护者身份才能查询上述配置。

内容的提问来源于stack exchange,提问作者Karan Tikku

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.09 11:39:02