Skip to content

Commit 935f7d4

Browse files
feat: auto-close PRs that only needed license updates
After the bot pushes license fixes, check if the PR now only contains license file changes. If so, close it automatically with a comment explaining that the license updates are complete. This prevents stale PRs from accumulating when someone creates a PR just to fix licenses, or when all other changes were already merged to the base branch.
1 parent 58f49f5 commit 935f7d4

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

.github/workflows/license-check.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,61 @@ I noticed the third-party license files were out of date and pushed a fix to thi
8585
Please pull the latest changes before pushing again.`
8686
})
8787

88+
# After pushing the fix, check if PR now has no functional changes (just license updates)
89+
# This handles the case where the PR only needed license updates and nothing else
90+
- name: Check if PR is now empty
91+
if: steps.changes.outputs.changed == 'true'
92+
id: empty_check
93+
uses: actions/github-script@v7
94+
with:
95+
script: |
96+
const { data: pr } = await github.rest.pulls.get({
97+
owner: context.repo.owner,
98+
repo: context.repo.repo,
99+
pull_number: context.issue.number
100+
});
101+
102+
const { data: files } = await github.rest.pulls.listFiles({
103+
owner: context.repo.owner,
104+
repo: context.repo.repo,
105+
pull_number: context.issue.number
106+
});
107+
108+
// Check if ALL changes are just license files
109+
const nonLicenseFiles = files.filter(f =>
110+
!f.filename.startsWith('third-party-licenses.') &&
111+
!f.filename.startsWith('third-party/')
112+
);
113+
114+
const isEmpty = nonLicenseFiles.length === 0;
115+
core.setOutput('is_empty', isEmpty);
116+
117+
if (isEmpty) {
118+
core.info('PR only contains license file changes - will close as stale');
119+
} else {
120+
core.info(`PR has ${nonLicenseFiles.length} non-license file changes - keeping open`);
121+
}
122+
123+
- name: Close stale license-only PR
124+
if: steps.changes.outputs.changed == 'true' && steps.empty_check.outputs.is_empty == 'true'
125+
uses: actions/github-script@v7
126+
with:
127+
script: |
128+
await github.rest.issues.createComment({
129+
owner: context.repo.owner,
130+
repo: context.repo.repo,
131+
issue_number: context.issue.number,
132+
body: `## 🤖 Auto-closing stale PR
133+
134+
This PR now only contains license file updates with no other functional changes. The license updates have been applied, so closing this PR as complete.
135+
136+
If this PR should have had other changes, please reopen it and add the intended changes.`
137+
});
138+
139+
await github.rest.pulls.update({
140+
owner: context.repo.owner,
141+
repo: context.repo.repo,
142+
pull_number: context.issue.number,
143+
state: 'closed'
144+
});
145+

0 commit comments

Comments
 (0)