|
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. |
2 | 2 |
|
3 | 3 | // dryRun env var: any case-insensitive 'true' value will enable dry-run |
4 | 4 | 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); |
6 | 8 | const requireAuthorAssigned = (process.env.REQUIRE_AUTHOR_ASSIGNED || 'true').toLowerCase() === 'true'; |
7 | 9 |
|
8 | 10 | const getHoursOpen = (pr) => |
@@ -88,6 +90,14 @@ async function closePR(github, pr, owner, repo, reason) { |
88 | 90 | owner, repo, issue_number: pr.number, |
89 | 91 | body: messages[reason] |
90 | 92 | }); |
| 93 | + |
| 94 | + if (immediateCheck) { |
| 95 | + console.log( |
| 96 | + `✓ Commented on PR #${pr.number} (${reason}) link: ${pr.html_url}` |
| 97 | + ); |
| 98 | + return; |
| 99 | + } |
| 100 | + |
91 | 101 | await github.rest.pulls.update({ |
92 | 102 | owner, repo, pull_number: pr.number, state: 'closed' |
93 | 103 | }); |
@@ -119,8 +129,10 @@ module.exports = async ({ github, context }) => { |
119 | 129 | } |
120 | 130 |
|
121 | 131 | 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 | + ); |
124 | 136 | continue; |
125 | 137 | } |
126 | 138 |
|
|
0 commit comments