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_TOKEN
はread:org
を持っておらず持たせる手段もないため、どちらもread:org
の権限が必要だろうと推測した。
実際、repo
とread:org
の権限を持った PAT を利用して workflow を実行したところ、問題なく PR が作成された。
余談
チームをレビュワーとして指定した場合に動かなくなる問題については、次の Issue で報告されている。
https://github.com/cli/cli/issues/6395
チーム情報を取得するのにread:org
の権限が必要になるのは理解できると思うが、レビュワーを変更するだけという認識だとread:org
の権限が必要になるのは意外性があるため、混乱が生じるのだと思う。
実際、今回のケースもレビュワーを変更しただけという感覚であり、これで動かなくなるとは思ってもいなかったため、動作していないことに気づかれていなかったのだと思う。