Skip to content

Commit 0118f50

Browse files
authored
Consider age of project when leaving update reminders (#2354)
1 parent 70e2957 commit 0118f50

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

automations/js/src/project_thread_updates.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// @ts-check
22

3+
// The number of days a project must be updated within
4+
const DAYS_UPDATED_WITHIN = 14
5+
36
const activeDevelopmentStatuses = [
47
'In Kickoff',
58
'In RFC',
@@ -23,6 +26,7 @@ const GET_PROJECT_CARDS = `
2326
__typename
2427
... on Issue {
2528
id
29+
createdAt
2630
url
2731
state
2832
assignees(first: 10) {
@@ -61,10 +65,10 @@ module.exports = async ({ github, core }) => {
6165
const isDryRun = process.env.DRY_RUN === 'true' ?? false
6266

6367
const currentDate = new Date()
64-
const fourteenDaysAgo = new Date(
65-
currentDate.getFullYear(),
66-
currentDate.getMonth(),
67-
currentDate.getDate() - 14
68+
// Create a date by subtracting DAYS_UPDATED_WITHIN days
69+
// (converted to milliseconds) from the current date in milliseconds.
70+
const requiredUpdatedByDate = new Date(
71+
currentDate.getTime() - DAYS_UPDATED_WITHIN * 24 * 60 * 60 * 1000
6872
)
6973

7074
// Fetch project cards with their associated issue data
@@ -77,8 +81,13 @@ module.exports = async ({ github, core }) => {
7781

7882
for (const node of result.repository.projectV2.items.nodes) {
7983
const issue = node.content
80-
// If we're not looking at an open issue, move along
81-
if (issue.__typename !== 'Issue' || issue.state !== 'OPEN') continue
84+
// If we're not looking at an open issue older than the required update date, move along
85+
if (
86+
issue.__typename !== 'Issue' ||
87+
issue.state !== 'OPEN' ||
88+
new Date(issue.createdAt) > requiredUpdatedByDate
89+
)
90+
continue
8291

8392
// Check the status of the card to make sure the project is in active development
8493
const status = node.fieldValueByName.name
@@ -89,7 +98,7 @@ module.exports = async ({ github, core }) => {
8998
if (
9099
// Check if the issue has been commented on in the last 14 days
91100
!comments.some(
92-
(comment) => new Date(comment.createdAt) > fourteenDaysAgo
101+
(comment) => new Date(comment.createdAt) > requiredUpdatedByDate
93102
)
94103
) {
95104
// If not, leave a reminder comment on the issue

0 commit comments

Comments
 (0)