# 错误：403“无法通过集成访问资源”

此错误可能在 Dependabot 创建的拉取请求上出现，可以通过几种不同的方式解决。

> \[!NOTE]

```
          _仅_在 Dependabot 中看到此错误时本疑难解答文章才适用。 如果在其他 GitHub 产品中看到此错误并且难以排查故障，则可以联系 GitHub 支持。 有关详细信息，请参阅“[AUTOTITLE](/support/contacting-github-support)”。
```

## 关于此错误

```text
403: Resource not accessible by integration
```

Dependabot 在触发工作流运行时被视为不信任，如果工作流程将以只读范围运行。

## 确认错误原因

如果在 Dependabot 工作流中使用 code scanning，请调查它正在使用的范围。

为分支上传 code scanning 结果通常需要 `security-events: write` 范围。 但是，当 `pull_request` 事件触发操作运行时，code scanning 始终允许上传结果。 因此，对于 Dependabot 分支，建议使用 `pull_request` 事件，而不是 `push` 事件。

## 修复问题

可以推送到默认分支和任何其他重要的长期分支，以及在此组分支上打开的拉取请求：

```yaml
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
```

另一种方法是运行除 Dependabot 分支以外的所有推送：

```yaml
on:
  push:
    branches-ignore:
      - 'dependabot/**'
  pull_request:
```

### 默认分支上的分析仍然失败

如果 CodeQL 分析工作流程 在默认分支上的提交仍然失败，需要检查：

* Dependabot 是否撰写了提交
* 包含该提交的请求是否已使用 `@dependabot squash and merge` 进行合并

此类型的合并提交由 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)”。