Skip to content

Commit 299ebe3

Browse files
committed
[fix] Address review feedback on stale-PR bot fix
1 parent 6ae57a0 commit 299ebe3

3 files changed

Lines changed: 43 additions & 11 deletions

File tree

.github/actions/bot-autoassign/stale_pr_bot.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,9 @@ def mark_pr_stale(self, pr, days_inactive):
296296
),
297297
"",
298298
(
299-
"As a result, **the linked issue(s)"
300-
" have been unassigned** from you"
301-
" to allow other contributors"
302-
" to work on it."
299+
"As a result, **any linked issues are being"
300+
" unassigned** from you so other contributors"
301+
" can pick them up."
303302
),
304303
"",
305304
(
@@ -325,7 +324,7 @@ def mark_pr_stale(self, pr, days_inactive):
325324
except Exception as e:
326325
print(f"Could not add stale label: {e}")
327326
print(
328-
f"Marked PR #{pr.number} as stale after {days_inactive} days,"
327+
f"Marked PR #{pr.number} stale at {days_inactive} days,"
329328
f" unassigned {unassigned_count} issues"
330329
)
331330
return True
@@ -398,6 +397,9 @@ def process_stale_prs(self):
398397
pr, all_reviews
399398
)
400399
if not last_changes_requested:
400+
# No active block — unwind any prior stale state.
401+
if self._clear_stale_label(pr):
402+
self._reassign_unassigned_linked_issues(pr)
401403
continue
402404
issue_comments = list(pr.get_issue_comments())
403405
review_comments = list(pr.get_review_comments())
@@ -411,8 +413,7 @@ def process_stale_prs(self):
411413
review_comments,
412414
)
413415
print(
414-
f"PR #{pr.number}: {days_inactive} days since"
415-
" contributor activity"
416+
f"PR #{pr.number}: {days_inactive} days since contributor activity"
416417
)
417418
if self.is_waiting_for_maintainer(
418419
pr,
@@ -427,8 +428,7 @@ def process_stale_prs(self):
427428
if self._clear_stale_label(pr):
428429
self._reassign_unassigned_linked_issues(pr)
429430
print(
430-
f"PR #{pr.number}: waiting for maintainer review,"
431-
" skipping"
431+
f"PR #{pr.number}: waiting for maintainer review, skipping"
432432
)
433433
continue
434434
stages = (

.github/actions/bot-autoassign/tests/test_stale_pr_bot.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,37 @@ def test_clears_stale_label_when_contributor_responds(self, mock_datetime, bot_e
749749
mock_issue.add_to_assignees.assert_called_once_with("contributor")
750750
mock_pr.create_issue_comment.assert_not_called()
751751

752+
@patch("stale_pr_bot.datetime")
753+
def test_clears_stale_label_when_no_active_block(self, mock_datetime, bot_env):
754+
mock_datetime.now.return_value = datetime(2024, 2, 1, tzinfo=timezone.utc)
755+
mock_datetime.side_effect = lambda *a, **kw: datetime(*a, **kw)
756+
bot = StalePRBot()
757+
mock_pr = Mock()
758+
mock_pr.body = "Fixes #42"
759+
mock_pr.number = 1
760+
mock_pr.user.login = "contributor"
761+
# Reviewer approved after their CR → no active CHANGES_REQUESTED.
762+
approve = Mock()
763+
approve.state = "APPROVED"
764+
approve.submitted_at = datetime(2024, 1, 20, tzinfo=timezone.utc)
765+
approve.user.login = "maintainer"
766+
approve.user.type = "User"
767+
mock_pr.get_reviews.return_value = [approve]
768+
stale_label = Mock()
769+
stale_label.name = "stale"
770+
mock_pr.get_labels.return_value = [stale_label]
771+
mock_issue = Mock()
772+
mock_issue.number = 42
773+
mock_issue.pull_request = None
774+
mock_issue.assignees = []
775+
mock_issue.repository.full_name = "openwisp/openwisp-utils"
776+
bot_env["repo"].get_issue.return_value = mock_issue
777+
bot_env["repo"].get_pulls.return_value = [mock_pr]
778+
bot.process_stale_prs()
779+
mock_pr.remove_from_labels.assert_called_once_with("stale")
780+
mock_issue.add_to_assignees.assert_called_once_with("contributor")
781+
mock_pr.create_issue_comment.assert_not_called()
782+
752783

753784
class TestRun:
754785
def test_no_github_client(self, bot_env):

docs/developer/reusable-github-utils.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ The Stale PR job runs daily. For each open PR:
9696

9797
- **7–13 days:** posts a stale-warning comment.
9898
- **≥ 14 days:** adds the ``stale`` label and unassigns the contributor
99-
from linked issues. An author comment on the PR clears the label and
100-
reassigns the issues; a push alone only resets the inactivity timer.
99+
from linked issues. Any subsequent author activity (push or comment)
100+
unwinds the label and reassigns linked issues on the next daily run;
101+
an author comment also triggers the immediate recovery bot.
101102
- **≥ 60 days:** posts a final follow-up comment asking whether the
102103
contributor is still working on it. The PR is not auto-closed;
103104
maintainers may close manually if needed.

0 commit comments

Comments
 (0)