{"meta":{"title":"错误：403“无法通过集成访问资源”","intro":"此错误可能在 Dependabot 创建的拉取请求上出现，可以通过几种不同的方式解决。","product":"安全性和代码质量","breadcrumbs":[{"href":"/zh/code-security","title":"安全性和代码质量"},{"href":"/zh/code-security/reference","title":"Reference"},{"href":"/zh/code-security/reference/code-scanning","title":"代码扫描"},{"href":"/zh/code-security/reference/code-scanning/troubleshoot-analysis-errors","title":"排查与解决分析错误"},{"href":"/zh/code-security/reference/code-scanning/troubleshoot-analysis-errors/resource-not-accessible","title":"无法访问资源"}],"documentType":"article"},"body":"# 错误：403“无法通过集成访问资源”\n\n此错误可能在 Dependabot 创建的拉取请求上出现，可以通过几种不同的方式解决。\n\n> \\[!NOTE]\n\n```\n          _仅_在 Dependabot 中看到此错误时本疑难解答文章才适用。 如果在其他 GitHub 产品中看到此错误并且难以排查故障，则可以联系 GitHub 支持。 有关详细信息，请参阅“[AUTOTITLE](/support/contacting-github-support)”。\n```\n\n## 关于此错误\n\n```text\n403: Resource not accessible by integration\n```\n\nDependabot 在触发工作流运行时被视为不信任，如果工作流程将以只读范围运行。\n\n## 确认错误原因\n\n如果在 Dependabot 工作流中使用 code scanning，请调查它正在使用的范围。\n\n为分支上传 code scanning 结果通常需要 `security-events: write` 范围。 但是，当 `pull_request` 事件触发操作运行时，code scanning 始终允许上传结果。 因此，对于 Dependabot 分支，建议使用 `pull_request` 事件，而不是 `push` 事件。\n\n## 修复问题\n\n可以推送到默认分支和任何其他重要的长期分支，以及在此组分支上打开的拉取请求：\n\n```yaml\non:\n  push:\n    branches:\n      - main\n  pull_request:\n    branches:\n      - main\n```\n\n另一种方法是运行除 Dependabot 分支以外的所有推送：\n\n```yaml\non:\n  push:\n    branches-ignore:\n      - 'dependabot/**'\n  pull_request:\n```\n\n### 默认分支上的分析仍然失败\n\n如果 CodeQL 分析工作流程 在默认分支上的提交仍然失败，需要检查：\n\n* Dependabot 是否撰写了提交\n* 包含该提交的请求是否已使用 `@dependabot squash and merge` 进行合并\n\n此类型的合并提交由 Dependabot 编写，因此在提交上运行的任何工作流程都将具有只读权限。 如果在存储库上启用了 code scanning 和 Dependabot 安全更新或版本更新，建议避免使用 Dependabot `@dependabot squash and merge` 命令。 不过，你可以为存储库启用自动合并。 这意味着，如果满足所有必需的评审并已通过状态检查，将自动合并拉取请求。 有关启用自动合并的详细信息，请参阅“[自动合并拉取请求](/zh/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/automatically-merging-a-pull-request#enabling-auto-merge)”。"}