|
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 daysBeforeClose = parseInt(process.env.DAYS_BEFORE_CLOSE || '3', 10); |
| 5 | +// const daysBeforeClose = parseInt(process.env.DAYS_BEFORE_CLOSE || '3', 10); |
| 6 | +const daysBeforeClose = Number(process.env.DAYS_BEFORE_CLOSE || '0.0035'); |
| 7 | + |
6 | 8 | const requireAuthorAssigned = (process.env.REQUIRE_AUTHOR_ASSIGNED || 'true').toLowerCase() === 'true'; |
7 | 9 |
|
| 10 | +// const getDaysOpen = (pr) => |
| 11 | +// Math.floor((Date.now() - new Date(pr.created_at)) / (24 * 60 * 60 * 1000)); |
| 12 | + |
8 | 13 | const getDaysOpen = (pr) => |
9 | | - Math.floor((Date.now() - new Date(pr.created_at)) / (24 * 60 * 60 * 1000)); |
| 14 | + (Date.now() - new Date(pr.created_at)) / (24 * 60 * 60 * 1000); |
10 | 15 |
|
11 | 16 | // Check if the PR author is assigned to the issue |
12 | 17 | const isAuthorAssigned = (issue, login) => { |
@@ -97,27 +102,26 @@ async function closePR(github, pr, owner, repo, reason) { |
97 | 102 | module.exports = async ({ github, context }) => { |
98 | 103 | try { |
99 | 104 | const { owner, repo } = context.repo; |
100 | | - const prs = await github.paginate(github.rest.pulls.list, { |
101 | | - owner, repo, state: 'open', per_page: 100 |
102 | | - }); |
103 | | - |
104 | | - console.log(`Evaluating ${prs.length} open PRs\n`); |
105 | | - |
106 | | - for (const pr of prs) { |
107 | | - const days = getDaysOpen(pr); |
108 | | - if (days < daysBeforeClose) |
109 | | - { |
110 | | - console.log(`PR #${pr.number} link: ${pr.html_url} is only ${days} days old. Skipping.`); |
111 | | - continue; |
112 | | - } |
| 105 | + const prs = await github.paginate(github.rest.pulls.list, { |
| 106 | + owner, repo, state: 'open', per_page: 100 |
| 107 | + }); |
| 108 | + |
| 109 | + console.log(`Evaluating ${prs.length} open PRs\n`); |
113 | 110 |
|
114 | | - const { valid, reason } = await validatePR(github, pr, owner, repo); |
115 | | - if (valid) { |
116 | | - console.log(`PR #${pr.number} link: ${pr.html_url} is Valid ✓.`); |
117 | | - } else { |
118 | | - await closePR(github, pr, owner, repo, reason); |
| 111 | + for (const pr of prs) { |
| 112 | + const days = getDaysOpen(pr); |
| 113 | + if (days < daysBeforeClose) { |
| 114 | + console.log(`PR #${pr.number} link: ${pr.html_url} is only ${days} days old. Skipping.`); |
| 115 | + continue; |
| 116 | + } |
| 117 | + |
| 118 | + const { valid, reason } = await validatePR(github, pr, owner, repo); |
| 119 | + if (valid) { |
| 120 | + console.log(`PR #${pr.number} link: ${pr.html_url} is Valid ✓.`); |
| 121 | + } else { |
| 122 | + await closePR(github, pr, owner, repo, reason); |
| 123 | + } |
119 | 124 | } |
120 | | - } |
121 | 125 | } catch (err) { |
122 | 126 | console.error('Unexpected error:', err.message); |
123 | 127 | } |
|
0 commit comments