You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub App使用Access Token创建PR报错:resource not accessible by integration

GitHub App发起PR时遭遇「resource not accessible by integration」错误排查

我们开发了一款GitHub App,核心功能包括:代表GitHub用户派生上游仓库、创建分支、向分支提交代码,随后从用户的派生仓库向上游仓库发起Pull Request(PR)。

我们采用以应用安装身份认证的方式,目的是让应用的所有活动都归因于App本身。

但当App尝试向上游仓库发起PR时,GitHub API返回错误:resource not accessible by integration。

我们注意到Dependabot等同类App可实现该功能,例如某PR的描述中显示「dependabot bot commented on behalf of github on Aug 31, 2023」。

以下是我们使用JavaScript及GitHub官方Octokit库实现该功能的代码片段,请帮忙排查问题:

// 获取安装的访问令牌
const installationId = 0; // 你的安装ID

// 使用JWT以GitHub App身份认证
const jwttoken = ``

const octokitApp = new Octokit({
  auth: jwttoken,
});

const response = await octokitApp.request('POST /app/installations/{installation_id}/access_tokens', {
  installation_id: installationId, // 你的安装ID
});

const accessToken = response.data.token;

const octokit = new Octokit({
  auth: accessToken
});

const response = await octokit.pulls.create({
  owner: 'evolvedbinary',
  repo: 'prosemirror-lwdita',
  title: 'Update README.md',
  body: `This pull request was created by **Petal-demo bot**`,
  head: 'marmoure:patch-1',
  base: 'main',
});

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 13:16:13