Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions .github/workflows/close-stale-pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,57 @@ jobs:
}

for (const pull of pulls) {
const updatedAt = Date.parse(pull.updated_at)
let feedbackAt = 0
if (feedbackPulls.has(pull.number)) {
const [comments, reviews, reviewComments] = await Promise.all([
github.paginate(github.rest.issues.listComments, {
owner,
repo,
issue_number: pull.number,
per_page: 100,
}),
github.paginate(github.rest.pulls.listReviews, {
owner,
repo,
pull_number: pull.number,
per_page: 100,
}),
github.paginate(github.rest.pulls.listReviewComments, {
owner,
repo,
pull_number: pull.number,
per_page: 100,
}),
])

const feedbackTimes = [
...comments
.filter((comment) => comment.user?.login === process.env.REVIEWER)
.map((comment) => Date.parse(comment.updated_at)),
...reviews
.filter((review) => review.user?.login === process.env.REVIEWER && review.submitted_at)
.map((review) => Date.parse(review.submitted_at)),
...reviewComments
.filter((comment) => comment.user?.login === process.env.REVIEWER)
.map((comment) => Date.parse(comment.updated_at)),
]
feedbackAt = Math.max(0, ...feedbackTimes)
}

// Refetch after loading feedback so activity during this run cannot be missed.
const { data: currentPull } = await github.rest.pulls.get({
owner,
repo,
pull_number: pull.number,
})
const updatedAt = Date.parse(currentPull.updated_at)
const monthStale = updatedAt < monthAgo
const feedbackStale = updatedAt < weekAgo && feedbackPulls.has(pull.number)
const feedbackStale = feedbackAt > 0 && feedbackAt < weekAgo && updatedAt <= feedbackAt
if (!monthStale && !feedbackStale) continue

const reason = monthStale
? "it has not been updated in 30 days"
: `it has not been updated in 7 days after feedback from @${process.env.REVIEWER}`
: `it has not been updated since feedback from @${process.env.REVIEWER} was left 7 days ago`

await github.rest.issues.createComment({
owner,
Expand Down
Loading