577 文字
3 分

Q. gh pr createでレビュワーをチームに変更したら、Github Actions上で動作しなくなった

状況#

動作していない workflow の調査を受けて実施していたところ、他のリポジトリでも同様の workflow がしばらく動作していないことに気づいた。

次のようにgh pr createを利用して PR を作成する workflow のいくつかが動作していなかった。

- name: Create PR
run: gh pr create --base main --title "Add auto-generated code" --reviewer my-org/some-team
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}

原因#

原因は、Actions のログを見れば、次のようなエラーが出力されておりread:orgの権限が必要であることが明白だった。

GraphQL: Your token has not been granted the required scopes to execute this query. The ‘id’ field requires one of the following scopes: [‘read’, ‘read’], but your token has only been granted the: [‘repo’] scopes. Please modify your token’s scopes at: https://github.com/settings/tokens., Your token has not been granted the required scopes to execute this query. The ‘slug’ field requires one of the following scopes: [‘read’, ‘read’], but your token has only been granted the: [‘repo’] scopes. Please modify your token’s scopes at: https://github.com/settings/tokens.

ただし別のリポジトリでは、次のようなエラーが出ていた。

could not request reviewer: ‘my-org/some-team’ not found

前者はrepoの権限のみを持った PAT を利用しており、後者はsecrets.GITHUB_TOKENを利用していた。

対応#

2 つのリポジトリの差分は深掘りしていないが、secret.GITHUB_TOKENread:orgを持っておらず持たせる手段もないため、どちらもread:orgの権限が必要だろうと推測した。

実際、reporead:orgの権限を持った PAT を利用して workflow を実行したところ、問題なく PR が作成された。

余談#

チームをレビュワーとして指定した場合に動かなくなる問題については、次の Issue で報告されている。

https://github.com/cli/cli/issues/6395

チーム情報を取得するのにread:orgの権限が必要になるのは理解できると思うが、レビュワーを変更するだけという認識だとread:orgの権限が必要になるのは意外性があるため、混乱が生じるのだと思う。

実際、今回のケースもレビュワーを変更しただけという感覚であり、これで動かなくなるとは思ってもいなかったため、動作していないことに気づかれていなかったのだと思う。

Q. gh pr createでレビュワーをチームに変更したら、Github Actions上で動作しなくなった
https://blog.ohirunewani.com/posts/q-gh-pr-create-with-team-reviewer-is-not-working-on-github-actions/
作者
hrdtbs
公開日
2024-10-24
ライセンス
CC BY-NC-SA 4.0