14
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

レビュー可能な状態になったらコメントする GitHub Actions

Posted at

現状の GitHub の通知だと、下記のアクション(プルリクエストをレビュー可能なステータスへ変更するアクション)は他人に通知されません。

  • Draft pull request を通常のプルリクエストへ変更する([Ready for review]ボタンの押下)
  • プルリクエストのタイトルから「WIP」または「wip」を外す
    • Draft pull request を利用しない旧来の運用をしている場合
    • 要はプルリクエストのタイトルや説明文の変更は他人へ通知されない
スクリーンショット_2020-01-12_22_24_36.png

準備できたよ〜と自分でコメントでもすればいいのですが(コメントは他人に通知される)、忘れる場合もあったり毎回手間であったりするので、そういうものは自動化してしまいましょう。これを実現する GitHub Actions は次のとおりです。

.github/workflows/comment-ready-for-review
name: pull request CI

on:
  pull_request:
    types: [ready_for_review, edited]

jobs:
  comment:
    name: Comment ready for review
    runs-on: ubuntu-18.04
    if: (contains(github.event.pull_request.title, 'wip') == false && github.event.pull_request.draft == false) && (github.event.action != 'edited' || (github.event.action == 'edited' && contains(github.event.changes.title.from, 'wip') == true))
    steps:
      - name: Run GitHub API
        run: |
          curl -X POST \
               -H "Content-Type: application/json" \
               -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
               -d "{ \"body\": \"Ready for review :rocket:\" }" \
               https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments

if が結構 長くなってしまっていますが、( ) で複雑な論理グループ化をしても正しく動いてくれます。

このアクションが動くと次のようにプルリクエストへコメントが追記されます。

スクリーンショット 2020-01-12 22.32.31.png
14
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?