Skip to content

Commit 06fd426

Browse files
committed
20260130114916
1 parent e7f849b commit 06fd426

File tree

2 files changed

+41
-24
lines changed

2 files changed

+41
-24
lines changed

aws/lambda/pytorch-auto-revert/pytorch_auto_revert/tests/test_autorevert_circuit_breaker.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def test_circuit_breaker_disabled_when_no_issues(self, mock_factory):
3535
@patch("pytorch_auto_revert.autorevert_circuit_breaker.GHClientFactory")
3636
def test_circuit_breaker_enabled_when_issue_exists(self, mock_factory):
3737
"""Circuit breaker should be active when an open issue with label exists."""
38-
mock_issue = create_mock_issue(number=12345, user_login="test-user", is_pr=False)
38+
mock_issue = create_mock_issue(
39+
number=12345, user_login="test-user", is_pr=False
40+
)
3941
mock_repo = MagicMock()
4042
mock_repo.get_issues.return_value = [mock_issue]
4143
mock_factory.return_value.client.get_repo.return_value = mock_repo
@@ -64,7 +66,9 @@ def test_circuit_breaker_ignores_pull_requests(self, mock_factory):
6466
def test_circuit_breaker_with_mixed_issues_and_prs(self, mock_factory):
6567
"""Circuit breaker should activate on issue but skip PR when both exist."""
6668
mock_pr = create_mock_issue(number=100, user_login="pr-author", is_pr=True)
67-
mock_issue = create_mock_issue(number=200, user_login="issue-author", is_pr=False)
69+
mock_issue = create_mock_issue(
70+
number=200, user_login="issue-author", is_pr=False
71+
)
6872
mock_repo = MagicMock()
6973
mock_repo.get_issues.return_value = [mock_pr, mock_issue]
7074
mock_factory.return_value.client.get_repo.return_value = mock_repo
@@ -105,7 +109,9 @@ def test_circuit_breaker_uses_custom_repo(self, mock_factory):
105109
@patch("pytorch_auto_revert.autorevert_circuit_breaker.GHClientFactory")
106110
def test_circuit_breaker_allows_approved_user(self, mock_factory):
107111
"""Circuit breaker should activate when issue is created by approved user."""
108-
mock_issue = create_mock_issue(number=12345, user_login="approved-user", is_pr=False)
112+
mock_issue = create_mock_issue(
113+
number=12345, user_login="approved-user", is_pr=False
114+
)
109115
mock_repo = MagicMock()
110116
mock_repo.get_issues.return_value = [mock_issue]
111117
mock_factory.return_value.client.get_repo.return_value = mock_repo
@@ -118,7 +124,9 @@ def test_circuit_breaker_allows_approved_user(self, mock_factory):
118124
@patch("pytorch_auto_revert.autorevert_circuit_breaker.GHClientFactory")
119125
def test_circuit_breaker_blocks_unapproved_user(self, mock_factory):
120126
"""Circuit breaker should not activate when issue is created by unapproved user."""
121-
mock_issue = create_mock_issue(number=12345, user_login="unauthorized-user", is_pr=False)
127+
mock_issue = create_mock_issue(
128+
number=12345, user_login="unauthorized-user", is_pr=False
129+
)
122130
mock_repo = MagicMock()
123131
mock_repo.get_issues.return_value = [mock_issue]
124132
mock_factory.return_value.client.get_repo.return_value = mock_repo
@@ -131,7 +139,9 @@ def test_circuit_breaker_blocks_unapproved_user(self, mock_factory):
131139
self.assertFalse(result)
132140
log_output = "\n".join(log_ctx.output)
133141
self.assertIn("Ignoring issue #12345", log_output)
134-
self.assertIn("User 'unauthorized-user' is not in the approved users list", log_output)
142+
self.assertIn(
143+
"User 'unauthorized-user' is not in the approved users list", log_output
144+
)
135145

136146
@patch("pytorch_auto_revert.autorevert_circuit_breaker.GHClientFactory")
137147
def test_circuit_breaker_no_approval_check_when_empty_set(self, mock_factory):
@@ -162,8 +172,12 @@ def test_circuit_breaker_no_approval_check_when_none(self, mock_factory):
162172
@patch("pytorch_auto_revert.autorevert_circuit_breaker.GHClientFactory")
163173
def test_circuit_breaker_with_mixed_approved_and_unapproved(self, mock_factory):
164174
"""Circuit breaker should activate if any issue is from approved user."""
165-
mock_unapproved = create_mock_issue(number=100, user_login="unauthorized", is_pr=False)
166-
mock_approved = create_mock_issue(number=200, user_login="approved-user", is_pr=False)
175+
mock_unapproved = create_mock_issue(
176+
number=100, user_login="unauthorized", is_pr=False
177+
)
178+
mock_approved = create_mock_issue(
179+
number=200, user_login="approved-user", is_pr=False
180+
)
167181
mock_repo = MagicMock()
168182
mock_repo.get_issues.return_value = [mock_unapproved, mock_approved]
169183
mock_factory.return_value.client.get_repo.return_value = mock_repo

torchci/lib/bot/autoLabelBot.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,14 @@ async function handleDisableAutorevertLabel(
388388
labelName: string
389389
): Promise<void> {
390390
// Check if we already posted a warning
391-
const comments = await context.octokit.issues.listComments(
392-
context.repo({
393-
issue_number: prNumber,
394-
})
395-
);
391+
const owner = context.payload.repository.owner.login;
392+
const repo = context.payload.repository.name;
393+
394+
const comments = await context.octokit.issues.listComments({
395+
owner,
396+
repo,
397+
issue_number: prNumber,
398+
});
396399

397400
const hasExistingWarning = comments.data.some((comment) =>
398401
comment.body?.includes(DISABLE_AUTOREVERT_WARNING_MARKER)
@@ -402,31 +405,31 @@ async function handleDisableAutorevertLabel(
402405
context.log(
403406
`Removing incorrect label "${labelName}" from PR ${prNumber}`
404407
);
405-
await context.octokit.issues.removeLabel(
406-
context.repo({
407-
issue_number: prNumber,
408-
name: labelName,
409-
})
410-
);
408+
await context.octokit.issues.removeLabel({
409+
owner,
410+
repo,
411+
issue_number: prNumber,
412+
name: labelName,
413+
});
411414

412415
// Only post a comment if we haven't already warned about this
413416
if (!hasExistingWarning) {
414417
context.log(
415418
`Posting warning comment about incorrect label "${labelName}" on PR ${prNumber}`
416419
);
417-
await context.octokit.issues.createComment(
418-
context.repo({
419-
issue_number: prNumber,
420-
body: `${DISABLE_AUTOREVERT_WARNING_MARKER}
420+
await context.octokit.issues.createComment({
421+
owner,
422+
repo,
423+
issue_number: prNumber,
424+
body: `${DISABLE_AUTOREVERT_WARNING_MARKER}
421425
The label \`${labelName}\` is incorrect for pull requests.
422426
423427
This label is used to disable the **entire autorevert system** and should only be added to **issues**, not PRs.
424428
425429
If you want to prevent autorevert from reverting **this specific PR**, please use the label \`autorevert: disable\` instead.
426430
427431
The incorrect label has been removed.`,
428-
})
429-
);
432+
});
430433
} else {
431434
context.log(
432435
`Skipping duplicate warning comment for "${labelName}" on PR ${prNumber} - warning already exists`

0 commit comments

Comments
 (0)