Skip to content

Commit 83b8649

Browse files
authored
feat: Supports pull request (#67)
1 parent 976db4d commit 83b8649

15 files changed

Lines changed: 1497 additions & 89 deletions

README.md

Lines changed: 181 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,52 @@ Notify commit messages to [Backlog.com](https://backlog.com/) issue.
1111

1212
GitHub 上のプッシュとプルリクエストを Backlog 課題に連携する GitHub Action です。キーワードによる課題の状態変更も可能です。
1313

14-
個人が開発した Action です。ヌーラボさまへのお問い合わせはご遠慮ください
14+
個人が開発した Action です。ヌーラボ様へのお問い合わせはご遠慮ください
1515

16-
![Backlog Notifyの動作をイメージした図。GitHub にプッシュすると Backlog にコミット情報のコメントがされる](./docs/readme_images/backlog-notify.png)
16+
## 機能
17+
18+
### プッシュ
19+
20+
![Backlog Notifyの動作をイメージした図。GitHub にプッシュすると Backlog にコミット情報のコメントがされる](./docs/readme_images/backlog-notify-push.png)
21+
22+
コミットメッセージの中に課題番号 (例: `PROJECT-123` ) がある場合は、その課題にコミットログに関するコメントを送信します。課題キーは先頭にある 1 つのみ認識します。
23+
24+
```plan
25+
PROJECT-123 不具合修正
26+
```
27+
28+
また、キーワードがある場合は、プッシュされたタイミングで課題ステータスを変更します。キーワードは末尾にある 1 つのみ認識します。
29+
30+
- `#fix` `#fixes` `#fixed` のどれかで処理済み
31+
- `#close` `#closes` `#closed` のどれかで完了
32+
33+
```plan
34+
PROJECT-123 不具合修正 #fix
35+
```
36+
37+
※ 大量にプッシュするとそのまま投稿され、 Backlog に負荷がかかるのでご注意ください。
38+
39+
### プルリクエスト
40+
41+
![Backlog Notifyの動作をイメージした図。GitHub にプルリクエストを作成すると Backlog にプルリクエスト情報のコメントがされる](./docs/readme_images/backlog-notify-pull-request.png)
42+
43+
プルリクエストのタイトルの中に課題番号 (例: `PROJECT-123` ) がある場合は、その課題にプルリクエストに関するコメントを送信します。課題キーは先頭にある 1 つのみ認識します。
44+
45+
```plan
46+
PROJECT-123 不具合修正
47+
```
48+
49+
また、キーワードがある場合は、マージされたタイミングで課題ステータスを変更します。キーワードは末尾にある 1 つのみ認識します。
50+
51+
- `#fix` `#fixes` `#fixed` のどれかで処理済み
52+
- `#close` `#closes` `#closed` のどれかで完了
53+
54+
```plan
55+
PROJECT-123 不具合修正 #fix
56+
```
57+
58+
※ プルリクエストが Draft の状態である場合はコメント送信・ステータス操作をしません。
59+
※ タイトルを変更した場合の通知は今のところ対応していません(対応予定)。Close → タイトルを変更 → Reopen を行うと通知されます。
1760

1861
## 設定方法
1962

@@ -44,21 +87,58 @@ GitHub 上のプッシュとプルリクエストを Backlog 課題に連携す
4487
### Workflow の作成
4588

4689
GitHub Actions workflow を作成します (例: `.github/workflows/backlog-notify.yml` )。
47-
下記のような形式である必要があります。
4890

4991
```yaml
5092
name: Backlog Notify
5193

5294
on:
53-
- push
95+
push:
96+
pull_request:
97+
types:
98+
- opened
99+
- reopened
100+
- ready_for_review
101+
- closed
54102

55103
jobs:
56104
notify:
57105
runs-on: ubuntu-latest
106+
steps:
107+
- name: Backlog Notify
108+
uses: bicstone/backlog-notify@v4
109+
with:
110+
project_key: PROJECT_KEY
111+
api_host: example.backlog.jp
112+
api_key: ${{ secrets.BACKLOG_API_KEY }}
113+
```
58114
115+
## 高度な設定
116+
117+
[Workflow syntax for GitHub Actions - GitHub Docs](https://docs.github.com/ja/actions/using-workflows/workflow-syntax-for-github-actions#on) を参照に実行する条件を制御することができます。
118+
また、コメントのフォーマットや、メッセージを解析する際の正規表現などをカスタマイズすることもできます。
119+
120+
```yaml
121+
name: Backlog Notify
122+
123+
on:
124+
push:
125+
branches:
126+
- main
127+
pull_request:
128+
types:
129+
- opened
130+
- reopened
131+
- ready_for_review
132+
- closed
133+
branches:
134+
- releases/**
135+
136+
jobs:
137+
notify:
138+
runs-on: ubuntu-latest
59139
steps:
60140
- name: Backlog Notify
61-
uses: bicstone/backlog-notify@v3
141+
uses: bicstone/backlog-notify@v4
62142
with:
63143
# 必須設定 (The following are required settings)
64144
project_key: PROJECT_KEY
@@ -77,33 +157,66 @@ jobs:
77157
push_comment_template: |-
78158
<%= commits[0].author.name %>さんが[<%= ref.name %>](<%= ref.url %>)にプッシュしました
79159
<% commits.forEach(commit=>{ %>
80-
+ <%= commit.comment %> ([<% print(commit.id.slice(0, 7)) %>](<%= commit.url %>))<% }); %>
160+
+ [<%= commit.comment %>](<%= commit.url %>) (<% print(commit.id.slice(0, 7)) %>)<% }); %>
161+
pr_opened_comment_template: |-
162+
<%= sender.login %>さんがプルリクエストを作成しました
163+
164+
+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)
165+
pr_reopened_comment_template: |-
166+
<%= sender.login %>さんがプルリクエストを作成しました
167+
168+
+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)
169+
pr_ready_for_review_comment_template: |-
170+
<%= sender.login %>さんがプルリクエストを作成しました
171+
172+
+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)
173+
pr_closed_comment_template: |-
174+
<%= sender.login %>さんがプルリクエストをクローズしました
175+
176+
+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)
177+
pr_merged_comment_template: |-
178+
<%= sender.login %>さんがプルリクエストをマージしました
179+
180+
+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)
81181
commit_message_reg_template: "\
82182
^\
83183
(<%= projectKey %>\\-\\d+)\\s?\
84184
(.*?)?\\s?\
85185
(<% print(fixKeywords.join('|')) %>|<% print(closeKeywords.join('|')) %>)?\
86186
$\
87187
"
188+
pr_title_reg_template: "\
189+
^\
190+
(<%= projectKey %>\\-\\d+)\\s?\
191+
(.*?)?\\s?\
192+
(<% print(fixKeywords.join('|')) %>|<% print(closeKeywords.join('|')) %>)?\
193+
$\
194+
"
88195
fix_status_id: 3
89196
close_status_id: 4
90197
```
91198
92-
## 設定一覧
93-
94-
| 設定名 | 説明 |
95-
| ----------------------------- | ------------------------------------ |
96-
| `project_key` | Backlog プロジェクトキー (必須) |
97-
| `api_host` | Backlog のホスト (必須) |
98-
| `api_key` | Backlog API キー (必須) |
99-
| `fix_keywords` | 処理済みにするキーワード |
100-
| `close_keywords` | 完了にするキーワード |
101-
| `push_comment_template` | プッシュ時のコメント雛形 |
102-
| `commit_message_reg_template` | コミットメッセージ解析の正規表現雛形 |
103-
| `fix_status_id` | 処理済みの 状態 ID |
104-
| `close_status_id` | 完了の 状態 ID |
105-
106-
### `push_comment_template`
199+
### 設定一覧
200+
201+
| 設定名 | 説明 |
202+
| -------------------------------------- | ---------------------------------------- |
203+
| `project_key` | Backlog プロジェクトキー (必須) |
204+
| `api_host` | Backlog のホスト (必須) |
205+
| `api_key` | Backlog API キー (必須) |
206+
| `fix_keywords` | 処理済みにするキーワード |
207+
| `close_keywords` | 完了にするキーワード |
208+
| `push_comment_template` | プッシュ時のコメント雛形 |
209+
| `pr_opened_comment_template` | プルリクエストオープン時のコメント雛形 |
210+
| `pr_reopened_comment_template` | プルリクエスト再オープン時のコメント雛形 |
211+
| `pr_ready_for_review_comment_template` | プルリクエスト下書き解除時のコメント雛形 |
212+
| `pr_closed_comment_template` | プルリクエストクローズ時のコメント雛形 |
213+
| `pr_merged_comment_template` | プルリクエストマージ時のコメント雛形 |
214+
| `commit_message_reg_template` | コミットメッセージ解析の正規表現雛形 |
215+
| `pr_title_reg_template` | プルリクエストタイトル解析の正規表現雛形 |
216+
| `fix_status_id` | 処理済みの 状態 ID |
217+
| `close_status_id` | 完了の 状態 ID |
218+
219+
#### `push_comment_template`
107220

108221
プッシュ時のコメントの雛形を変更できます。
109222
構文については [lodash/template](https://lodash.com/docs/4.17.15#template) をご参照ください。
@@ -156,7 +269,40 @@ Committer
156269

157270
</details>
158271

159-
### `commit_message_reg_template`
272+
#### `pr_*_comment_template`
273+
274+
プルリクエストイベントのコメントの雛形を変更できます。
275+
構文については [lodash/template](https://lodash.com/docs/4.17.15#template) をご参照ください。
276+
277+
<details>
278+
279+
<summary>使用可能な変数</summary>
280+
281+
| 変数名 | 型 |
282+
| ---------- | ----------------------------------------------------------------------- |
283+
| `pr` | PullRequest |
284+
| `action` | "opened" &#124; "reopened" &#124; "ready_for_review" &#124; "closed" ※1 |
285+
| `sender` | User |
286+
| `issueKey` | string |
287+
| `title` | string ※2 |
288+
| `keywords` | string |
289+
| `isFix` | boolean |
290+
| `isClose` | boolean |
291+
292+
※1 マージとクローズは共に `"closed"` となります。マージかどうか判別したい場合は `pr.merged` を参照ください。
293+
※2 課題キーとキーワードを除いたタイトルです。加工前のタイトルは `pr.title` を参照ください。
294+
295+
PullRequest
296+
297+
[Get a pull request - GitHub Docs](https://docs.github.com/en/rest/pulls/pulls#get-a-pull-request) の Response schema をご参照ください。
298+
299+
User
300+
301+
[Get the authenticated user - GitHub Docs](https://docs.github.com/en/rest/users/users#get-the-authenticated-user) の Response schema をご参照ください。
302+
303+
</details>
304+
305+
#### `commit_message_reg_template`
160306

161307
コミットメッセージ解析の正規表現雛形を変更できます。
162308
構文については [lodash/template](https://lodash.com/docs/4.17.15#template) をご参照ください。
@@ -173,29 +319,30 @@ Committer
173319

174320
</details>
175321

176-
## 使用方法
322+
#### `pr_title_reg_template`
177323

178-
[Backlog の Git](https://support-ja.backlog.com/hc/ja/articles/360035640734) と同様です。課題キーは先頭にある 1 つ目のキーのみ認識します
179-
付加機能として、コミットログで課題を操作することができます
324+
プルリクエストタイトル解析の正規表現雛形を変更できます
325+
構文については [lodash/template](https://lodash.com/docs/4.17.15#template) をご参照ください
180326

181-
- `#fix` `#fixes` `#fixed` のどれかで処理済み
182-
- `#close` `#closes` `#closed` のどれかで完了
327+
<details>
183328

184-
例えば下記のようにコミットメッセージを設定してください。
329+
<summary>使用可能な変数</summary>
185330

186-
```
187-
PROJECT-123 不具合修正 #fix
188-
```
331+
| 変数名 | 型 |
332+
| --------------- | -------- |
333+
| `projectKey` | string |
334+
| `fixKeywords` | string[] |
335+
| `closeKeywords` | string[] |
189336

190-
大量にプッシュするとそのまま投稿され、 Backlog に負荷がかかるのでご注意ください。
337+
</details>
191338

192339
## よくある質問と回答
193340

194341
- 何をプッシュしても実行に失敗し、ログに 401 エラーとある
195-
API キーが誤っている可能性があります。
342+
API キーが誤っている可能性があります。
196343

197344
- プロジェクトキーと課題キーが正しいのに実行に失敗し、ログに 404 エラーとある
198-
該当 API キーのユーザーがプロジェクトに参加していない可能性があります。
345+
該当 API キーのユーザーがプロジェクトに参加していない可能性があります。
199346

200347
## 貢献
201348

action.yml

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,42 @@ inputs:
3737
default: |-
3838
<%= commits[0].author.name %>さんが[<%= ref.name %>](<%= ref.url %>)にプッシュしました
3939
<% commits.forEach(commit=>{ %>
40-
+ <%= commit.comment %> ([<% print(commit.id.slice(0, 7)) %>](<%= commit.url %>))<% }); %>
40+
+ [<%= commit.comment %>](<%= commit.url %>) (<% print(commit.id.slice(0, 7)) %>)<% }); %>
41+
pr_opened_comment_template:
42+
description: The template for backlog issue comment on opened a pull request
43+
required: false
44+
default: |-
45+
<%= sender.login %>さんがプルリクエストを作成しました
46+
47+
+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)
48+
pr_reopened_comment_template:
49+
description: The template for backlog issue comment on reopened a pull request
50+
required: false
51+
default: |-
52+
<%= sender.login %>さんがプルリクエストを作成しました
53+
54+
+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)
55+
pr_ready_for_review_comment_template:
56+
description: The template for backlog issue comment on ready to review a pull request
57+
required: false
58+
default: |-
59+
<%= sender.login %>さんがプルリクエストを作成しました
60+
61+
+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)
62+
pr_closed_comment_template:
63+
description: The template for backlog issue comment on closed a pull request
64+
required: false
65+
default: |-
66+
<%= sender.login %>さんがプルリクエストをクローズしました
67+
68+
+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)
69+
pr_merged_comment_template:
70+
description: The template for backlog issue comment on merged a pull request
71+
required: false
72+
default: |-
73+
<%= sender.login %>さんがプルリクエストをマージしました
74+
75+
+ [<%= title %>](<%= pr.html_url %>) (#<%= pr.number %>)
4176
commit_message_reg_template:
4277
description: The template for regular expressions to parse commit messages
4378
required: false
@@ -48,6 +83,16 @@ inputs:
4883
(<% print(fixKeywords.join('|')) %>|<% print(closeKeywords.join('|')) %>)?\
4984
$\
5085
"
86+
pr_title_reg_template:
87+
description: The template for regular expressions to parse pull request title
88+
required: false
89+
default: "\
90+
^\
91+
(<%= projectKey %>\\-\\d+)\\s?\
92+
(.*?)?\\s?\
93+
(<% print(fixKeywords.join('|')) %>|<% print(closeKeywords.join('|')) %>)?\
94+
$\
95+
"
5196
fix_status_id:
5297
description: Status ID to mark as fixed
5398
required: false

0 commit comments

Comments
 (0)