Skip to content

Commit db0f087

Browse files
authored
Merge pull request #13105 from github/repo-sync
repo sync
2 parents 77806a4 + 29b44f8 commit db0f087

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

.github/workflows/repo-sync.yml

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ jobs:
121121
github_token: ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }}
122122

123123
- name: Create pull request
124-
id: create-pull
125124
uses: repo-sync/pull-request@65194d8015be7624d231796ddee1cd52a5023cb3
126125
env:
127126
GITHUB_TOKEN: ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }}
@@ -146,13 +145,6 @@ jobs:
146145
author: Octomerger
147146
state: open
148147

149-
- name: Approve pull request
150-
if: ${{ steps.find-pull-request.outputs.number }}
151-
uses: juliangruber/approve-pull-request-action@c530832d4d346c597332e20e03605aa94fa150a8
152-
with:
153-
github-token: ${{ secrets.GITHUB_TOKEN }}
154-
number: ${{ steps.find-pull-request.outputs.number }}
155-
156148
# Because we get far too much spam ;_;
157149
- name: Lock conversations
158150
if: ${{ github.repository == 'github/docs' && steps.find-pull-request.outputs.number }}
@@ -221,8 +213,47 @@ jobs:
221213
console.log(`Branch is already up-to-date`)
222214
}
223215
224-
- name: Enable GitHub auto-merge
216+
- name: Check pull request file count after updating
225217
if: ${{ steps.find-pull-request.outputs.number }}
218+
uses: actions/github-script@2b34a689ec86a68d8ab9478298f91d5401337b7d
219+
id: pr-files
220+
env:
221+
PR_NUMBER: ${{ steps.find-pull-request.outputs.number }}
222+
with:
223+
github-token: ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }}
224+
result-encoding: string
225+
script: |
226+
const prFiles = await github.pulls.listFiles({
227+
...context.repo,
228+
pull_number: process.env.PR_NUMBER,
229+
})
230+
core.setOutput('count', (prFiles && prFiles.length || 0).toString())
231+
232+
# Sometimes after updating the branch, there aren't any remaining files changed.
233+
# If not, we should close the PR instead of merging it and triggering deployments.
234+
- name: Close the pull request if no files remain
235+
if: ${{ steps.find-pull-request.outputs.number && steps.pr-files.outputs.count == '0' }}
236+
env:
237+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
238+
run: |
239+
gh pr close ${{ steps.find-pull-request.outputs.number }} --repo $GITHUB_REPOSITORY
240+
241+
- name: Comment on the pull request if no files remain
242+
if: ${{ steps.find-pull-request.outputs.number && steps.pr-files.outputs.count == '0' }}
243+
env:
244+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
245+
run: |
246+
gh pr comment ${{ steps.find-pull-request.outputs.number }} --repo $GITHUB_REPOSITORY --body "This pull request was closed because it no longer contained any changes."
247+
248+
- name: Approve pull request
249+
if: ${{ steps.find-pull-request.outputs.number && steps.pr-files.outputs.count != '0' }}
250+
uses: juliangruber/approve-pull-request-action@c530832d4d346c597332e20e03605aa94fa150a8
251+
with:
252+
github-token: ${{ secrets.GITHUB_TOKEN }}
253+
number: ${{ steps.find-pull-request.outputs.number }}
254+
255+
- name: Enable GitHub auto-merge
256+
if: ${{ steps.find-pull-request.outputs.number && steps.pr-files.outputs.count != '0' }}
226257
env:
227258
GITHUB_TOKEN: ${{ secrets.OCTOMERGER_PAT_WITH_REPO_AND_WORKFLOW_SCOPE }}
228259
AUTOMERGE_PR_NUMBER: ${{ steps.find-pull-request.outputs.number }}

0 commit comments

Comments
 (0)