GitHub App で Checks API を使って Merge Queue をサポートする際の Webhook の Event Type について
Merge Queue をサポートするためには Merge Queue に入れた際に webhook を受け取って Checks を更新する必要がある。
- どの event を処理すればよいのか
- event type の名前はなにか
- 必要な permission はなにか
merge_group
GitHub App の Event として Merge Queue がある
Merge queue entry
Merge Queue entry added
merge_group
This event occurs when there is activity relating to a merge group in a merge queue.
For more information, see "Managing a merge queue."
To subscribe to this event, a GitHub App must have at least read-level access for the "Merge queues" repository permission.
GitHub App の Merge Queue の read 権限が必要
いかにもこれっぽいが、しかし権限を付与してこの event を subscribe しても Lambda に webhook が送られてこない。
push
Triggering merge group checks with GitHub Actions
You must use the merge_group event to trigger your GitHub Actions workflow when a pull request is added to a merge queue.
Triggering merge group checks with third-party CI providers
With third-party CI providers, you will need to update your CI configuration to run when a branch that begins with the special prefix gh-readonly-queue/{base_branch} is pushed to.
GitHub App だと Merge Queue で生成されるブランチ gh-readonly-queue/*
が push された際に Checks を更新する必要がありそう。
とすると push event か?
installation
ところで installation
という event が送られてきた。
installation
This event occurs when there is activity relating to a GitHub App installation.
All GitHub Apps receive this event by default. You cannot manually subscribe to this event.
For more information about GitHub Apps, see "About apps."
For information about the APIs to manage GitHub Apps, see the GraphQL API documentation or "Apps" in the REST API documentation.
すべての GitHub App はデフォルトでこのイベントを受け取る。
permission が変更されたときなんかにも webhook が送られるらしい。
まぁこれは無視すれば良さそう。
by default だから、無効化することもできるのか?
無駄に webhook を処理したくないので無効化したい。
けど無効化する設定が見つからない。
check_suite
また、 Merge Group Event を有効化すると check_suite
という event が送られてきた。
check_suite
This event occurs when there is activity relating to a check suite.
For information about check suites, see "Getting started with the Checks API."
For information about the APIs to manage check suites, see the GraphQL API documentation or "Check Suites" in the REST API documentation.
For activity relating to check runs, use the check_run event.
To subscribe to this event, a GitHub App must have at least read-level access for the "Checks" permission.
To receive the requested and rerequested event types, the app must have at least write-level access for the "Checks" permission.
GitHub Apps with write-level access for the "Checks" permission are automatically subscribed to this webhook event.
Repository and organization webhooks only receive payloads for the completed event types in repositories.
この event を subscribe するには、 Checks の read 権限が必要
Checks write 権限を持っている App は自動でこの event を subscribe する
つまり、 Merge Queue は関係ない?
このチュートリアルでは、GitHub の REST API を使用して、Webhook イベント check_run および check_suite を受信して応答するサーバーとして機能する GitHub App を構築および構成する方法を示します。
check_run と check_suite を受信すると言っている。
しかし、今回は merge queue のときのみこの event を処理したいのであって、 pull request に commit を push したときは処理したくない。
まぁ head branch でフィルタすれば済む話かもだけど、無駄にお金かかったり lambda に負荷がかかるのが嫌。
Merge Queue 使う場合でも Merge Queue event の subscribe や permission は不要なのかな?
動いた
- permissions は checks:write (read でも十分かもだけど check を更新するならどのみち write が必要)
- event の subscribe は特に不要
- checks:write 権限があれば event は勝手に送られてくる