はじめに
GitHub の Issue を作ったら Redmine のチケットに説明を記載する方法のメモです。
Redmine のプラグインなどをインストールするのも社内システムだとなかなかハードルが高いので、GitHub 側から Redmine のチケットを操作する方法を検討していました。
GitHub Actions を利用して Issue を作ったときにワークフローを起動させる方法です。
GitHub Actions の設定
まずは、GitHub Actions の設定 (yml) は以下の通り。
やることは、Redmine の URL と API キーを変更してください。
Issue を作るときに、Issue のタイトルを Redmine のチケット番号にする必要があります。
name: "Redmine Add Comment"
on:
issues:
types:
- opened
jobs:
sample:
name: Hello Redmine Ticket Add Comment
runs-on: ubuntu-latest
steps:
- name: Display Issue Title
run: |
echo "New Issue Title: ${{ github.event.issue.title }}"
if: github.event.issue.title
- name: Display Issue Comment
run: |
echo "New Issue Comment: ${{ github.event.issue.body }}"
- name: add note to redimne issue
run: curl -X PUT -H "Content-Type:application/json" -H "X-Redmine-API-Key:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -d '{"issue":{"notes":"${{ github.event.issue.body }}"}}' https://<RedmineURL>/issues/${{ github.event.issue.title }}.json
GitHub Actions の設定の説明
ワークフローが起動するタイミング
Issue が作られたときのタイミングで起動させたいので以下の設定にします。
詳細は以下の説明で「アクティビティの種類を使用する」のあたり説明を参考にしてください。
on:
issues:
types:
- opened
Issue のいろんな内容を取得して表示してみる
以下の例は Issue を作ったときのタイトルと内容を取得しています。
Issue のイベントタイプの詳細は以下を参考にしてください。
https://docs.github.com/en/rest/overview/issue-event-types?apiVersion=2022-11-28
タイトルの部分に「if: github.event.issue.title」は、タイトルに何か入力されていればというものです。
- name: Display Issue Title
run: |
echo "New Issue Title: ${{ github.event.issue.title }}"
if: github.event.issue.title
- name: Display Issue Comment
run: |
echo "New Issue Comment: ${{ github.event.issue.body }}"
Issue の内容をRedmine のコメントに追加
curl コマンドを利用して Redmine のチケットのコメントを追記します。
Redmine の URL と API キーの部分を修正して下さい。
- name: add note to redimne issue
run: curl -X PUT -H "Content-Type:application/json" -H "X-Redmine-API-Key:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" -d '{"issue":{"notes":"${{ github.event.issue.body }}"}}' https://<RedmineURL>/issues/${{ github.event.issue.title }}.json