Skip to content

Commit f40f439

Browse files
committed
Avoid self-reset
1 parent 4c6a3d5 commit f40f439

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

.github/workflows/close-stale-prs.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,22 @@ jobs:
5555
const daysSinceUpdate = Math.floor((now - updatedAt) / (1000 * 60 * 60 * 24));
5656
console.log(` Days since update: ${daysSinceUpdate}`);
5757
58-
// If PR was updated and has stale label, remove it
59-
if (labels.includes(staleLabel) && daysSinceUpdate < daysUntilStale) {
58+
// Check if the last activity was setting the stale label
59+
const events = await github.rest.issues.listEvents({
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
issue_number: pr.number,
63+
per_page: 10
64+
});
65+
66+
const lastEvent = events.data.length > 0 ? events.data[events.data.length - 1] : null;
67+
const isStaleLastActivity = lastEvent &&
68+
lastEvent.event === 'labeled' &&
69+
lastEvent.label &&
70+
lastEvent.label.name === staleLabel;
71+
72+
// If PR was updated and has stale label, remove it (unless the last activity was setting the stale label)
73+
if (labels.includes(staleLabel) && daysSinceUpdate < daysUntilStale && !isStaleLastActivity) {
6074
console.log(` Removing stale label (PR was updated)`);
6175
try {
6276
await github.rest.issues.removeLabel({

0 commit comments

Comments
 (0)