Skip to content

Commit 5c71d69

Browse files
authored
feat: Fix Linked Issue Enforcer (#2379)
Signed-off-by: aceppaluni <aceppaluni@gmail.com>
1 parent aae89fa commit 5c71d69

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

.github/scripts/cron-enforcer-pr-linked-issue.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// A script to closes pull requests without a linked issue after 24 hours automatically.
1+
// A script to closes pull requests without a linked issue after 2 hours automatically.
22

33
// dryRun env var: any case-insensitive 'true' value will enable dry-run
44
const dryRun = (process.env.DRY_RUN || 'false').toString().toLowerCase() === 'true';
5-
const hoursBeforeClose = parseInt(process.env.HOURS_BEFORE_CLOSE || '24', 10);
5+
const immediateCheck =
6+
(process.env.IMMEDIATE_CHECK || 'false').toLowerCase() === 'true';
7+
const hoursBeforeClose = parseInt(process.env.HOURS_BEFORE_CLOSE || '2', 10);
68
const requireAuthorAssigned = (process.env.REQUIRE_AUTHOR_ASSIGNED || 'true').toLowerCase() === 'true';
79

810
const getHoursOpen = (pr) =>
@@ -88,6 +90,14 @@ async function closePR(github, pr, owner, repo, reason) {
8890
owner, repo, issue_number: pr.number,
8991
body: messages[reason]
9092
});
93+
94+
if (immediateCheck) {
95+
console.log(
96+
`✓ Commented on PR #${pr.number} (${reason}) link: ${pr.html_url}`
97+
);
98+
return;
99+
}
100+
91101
await github.rest.pulls.update({
92102
owner, repo, pull_number: pr.number, state: 'closed'
93103
});
@@ -119,8 +129,10 @@ module.exports = async ({ github, context }) => {
119129
}
120130

121131
const hours = getHoursOpen(pr);
122-
if (hours < hoursBeforeClose) {
123-
console.log(`PR #${pr.number} link: ${pr.html_url} is only ${hours} hours old. Skipping.`);
132+
if (!immediateCheck && hours < hoursBeforeClose) {
133+
console.log(
134+
`PR #${pr.number} link: ${pr.html_url} is only ${hours} hours old. Skipping.`
135+
);
124136
continue;
125137
}
126138

.github/workflows/archive/bot-pr-missing-linked-issue.yml renamed to .github/workflows/bot-pr-missing-linked-issue.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ jobs:
4040
- name: Checkout repository
4141
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
4242
with:
43-
ref: main
43+
ref: ${{ github.event.pull_request.base.sha || github.sha }}
4444

4545
- name: Check PR for missing linked issue
4646
env:
4747
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4848
DRY_RUN: ${{ github.event.inputs.dry_run || 'false' }}
4949
PR_NUMBER: ${{ github.event.pull_request.number || github.event.inputs.pr_number }}
50+
IMMEDIATE_CHECK: "true"
5051
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
5152
with:
5253
script: |

.github/workflows/cron-enforcer-pr-linked-issue.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
env:
3434
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3535
DRY_RUN: ${{ env.DRY_RUN }}
36-
HOURS_BEFORE_CLOSE: "24"
36+
HOURS_BEFORE_CLOSE: "2"
3737
REQUIRE_AUTHOR_ASSIGNED: "true"
3838
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
3939
with:

0 commit comments

Comments
 (0)