0
0

GitHub Actionsでは、プルリクエストをトリガーに実行される場合、対象となるプルリクエストの情報を取得することができます。

プルリクエスト情報の取得方法

Github Actionsでは、${{ github.event.pull_request }}で渡される変数の中に、workflowがトリガーされた際の情報が入っています。

on:
  pull_request:
    types:
      - opened

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - タイトルを出力
        run: echo ${{ github.event.pull_request.title }}

取得できる情報は、例えば以下のようなものです。

  • URL:${{ github.event.pull_request.html_url }}
  • タイトル:${{ github.event.pull_request.title }}
  • 本文:${{ github.event.pull_request.body }}
  • PR番号:${{ github.event.pull_request.number }}
  • openかclosedか:${{ github.event.pull_request.state }}
  • 作成日時:${{ github.event.pull_request.created_at }}
  • プルリクを開いているブランチ:${{ github.event.pull_request.head.ref }}
  • プルリクのマージ先:${{ github.event.pull_request.base.ref }}
  • ドラフトかどうか:${{ github.event.pull_request.draft }}
  • マージされたかどうか:${{ github.event.pull_request.merged }}

上記のような情報を使うと、

  • プルリクエストが開かれたら自動でslackへ通知する
  • プルリクエストが開かれたら自動で開発環境にデプロイする
  • stagingブランチにマージされたらmainブランチへのプルリクエストを自動で開く

のようなworkflowを実現することができます。

こちらに記載した変数はほんの一部で、公式ドキュメントによると他にも様々な情報も取得することができるようです。
こちらのサイトの「Properties of pull_request」をクリックすると、取得できるプロパティの一覧を見ることができます。

プルリクエスト以外のイベントについても、こちらのページからgithub.eventからどのような変数が渡されるかを確認できます。

以上、GitHub Actionsからどのようなプルリクエスト情報が取れるかの紹介でした。

0
0
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
0
0