Skip to content

Commit 028e44d

Browse files
元のPRを閉じた際にPRを閉じるようにする (#105)
* README修正 * 元のPRを閉じた際にPRを閉じるようにする * PR close時もset_org_nameを実行する * PR close時もset_org_nameを実行する * action.ymlを元にREADMEを生成する * token周り修正 * 条件修正 * inputsの順番変更 * README修正 (#108) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * テンプレート修正 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent b386760 commit 028e44d

5 files changed

Lines changed: 25 additions & 45 deletions

File tree

.github/workflows/close-pr.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/update-package.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ name: update-package
33

44
on:
55
pull_request:
6+
types:
7+
- opened
8+
- synchronize
9+
- reopened
10+
- closed
611
push:
712
branches:
813
- main

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
PRのブランチに対して、フォーマッタを実行した結果をPRにするGitHub Actionsです。
44

5-
本Actionsを使わずにフォーマットを修正した場合、自動的にPRを閉じます。
6-
7-
## 注意点
8-
9-
元のPRを閉じた場合、本Actionsが立てたPRは残ります。
10-
このような場合、 <https://github.com/dev-hato/actions-close-pr> を併用することで自動的にPRを閉じることができます。
5+
本Actionsを使わずにフォーマットを修正した場合や元のPRを閉じた場合、自動的にPRを閉じます。
116

127
## 使い方
138

149
```yaml
1510
on:
1611
pull_request:
12+
types:
13+
- opened
14+
- synchronize
15+
- reopened
16+
- closed
1717

1818
jobs:
1919
diff-pr-management:

README.template.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
${DESCRIPTION}
44

5-
本Actionsを使わずにフォーマットを修正した場合、自動的にPRを閉じます。
6-
7-
## 注意点
8-
9-
元のPRを閉じた場合、本Actionsが立てたPRは残ります。
10-
このような場合、 <https://github.com/dev-hato/actions-close-pr> を併用することで自動的にPRを閉じることができます。
5+
本Actionsを使わずにフォーマットを修正した場合や元のPRを閉じた場合、自動的にPRを閉じます。
116

127
## 使い方
138

149
```yaml
1510
on:
1611
pull_request:
12+
types:
13+
- opened
14+
- synchronize
15+
- reopened
16+
- closed
1717

1818
jobs:
1919
diff-pr-management:

action.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ runs:
2727
- name: Show diff
2828
id: diff
2929
shell: bash
30+
if: github.event_name != 'pull_request' || github.event.action != 'closed'
3031
run: |
3132
result=$(git diff)
3233
echo "::set-output name=result::$result"
@@ -36,7 +37,7 @@ runs:
3637
HEAD_REF: ${{github.event.pull_request.head.ref}}
3738
if: inputs.repo-name == github.repository
3839
&& steps.diff.outputs.result != ''
39-
&& (github.event_name == 'pull_request' || github.event_name == 'schedule')
40+
&& ((github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'schedule')
4041
run: |
4142
git config user.name "github-actions[bot]"
4243
EMAIL="41898282+github-actions[bot]@users.noreply.github.com"
@@ -68,7 +69,7 @@ runs:
6869
HEAD_REF: ${{github.event.pull_request.head.ref}}
6970
if: inputs.repo-name == github.repository
7071
&& steps.diff.outputs.result != ''
71-
&& (github.event_name == 'pull_request' || github.event_name == 'schedule')
72+
&& ((github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'schedule')
7273
id: get_pull_requests
7374
with:
7475
github-token: ${{inputs.github-token}}
@@ -99,7 +100,7 @@ runs:
99100
if: inputs.repo-name == github.repository
100101
&& steps.diff.outputs.result != ''
101102
&& steps.get_pull_requests.outputs.result == 0
102-
&& (github.event_name == 'pull_request' || github.event_name == 'schedule')
103+
&& ((github.event_name == 'pull_request' && github.event.action != 'closed') || github.event_name == 'schedule')
103104
id: create_pull_request
104105
with:
105106
github-token: ${{inputs.github-token}}
@@ -139,6 +140,7 @@ runs:
139140
&& steps.diff.outputs.result != ''
140141
&& steps.get_pull_requests.outputs.result == 0
141142
&& github.event_name == 'pull_request'
143+
&& github.event.action != 'closed'
142144
&& github.event.pull_request.user.login != 'dependabot[bot]'
143145
&& github.event.pull_request.user.login != 'renovate[bot]'
144146
with:
@@ -159,8 +161,8 @@ runs:
159161
env:
160162
HEAD_REF: ${{github.event.pull_request.head.ref}}
161163
if: inputs.repo-name == github.repository
162-
&& steps.diff.outputs.result == ''
163-
&& (github.event_name == 'pull_request' || github.event_name == 'schedule')
164+
&& ((github.event_name == 'pull_request' && (github.event.action == 'closed' || steps.diff.outputs.result == ''))
165+
|| (github.event_name == 'schedule' && steps.diff.outputs.result == ''))
164166
with:
165167
github-token: ${{inputs.github-token}}
166168
script: |
@@ -201,6 +203,6 @@ runs:
201203
await github.rest.git.deleteRef(git_deleteRef_params)
202204
}
203205
- name: Exit
204-
if: steps.diff.outputs.result != ''
206+
if: (github.event_name != 'pull_request' || github.event.action != 'closed') && steps.diff.outputs.result != ''
205207
run: exit 1
206208
shell: bash

0 commit comments

Comments
 (0)