Skip to content

Commit 8569d62

Browse files
JackenmenMariattaJelleZijlstra
authored
Only mention participants on backport PRs in case of errors (#481)
* Only mention participants on backport PRs in case of errors * Don't fetch participants when they're not used * Remove unused variable * Fix test coverage Co-authored-by: Mariatta Wijaya <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent fb5d71f commit 8569d62

File tree

2 files changed

+78
-10
lines changed

2 files changed

+78
-10
lines changed

miss_islington/status_change.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,24 @@ async def check_ci_status_and_approval(
105105
for elem in all_check_run_conclusions
106106
)
107107
if leave_comment:
108-
if is_automerge:
109-
participants = await util.get_gh_participants(gh, pr_number)
110-
else:
111-
original_pr_number = title_match.group("pr")
112-
participants = await util.get_gh_participants(
113-
gh, original_pr_number
114-
)
115108
if success:
116109
emoji = "✅"
117-
description = "success"
118110
else:
119111
emoji = "❌"
120-
description = "failure"
112+
message = f"Status check is done, and it's a {result['state']} {emoji} ."
113+
if not success:
114+
if is_automerge:
115+
participants = await util.get_gh_participants(gh, pr_number)
116+
else:
117+
original_pr_number = title_match.group("pr")
118+
participants = await util.get_gh_participants(
119+
gh, original_pr_number
120+
)
121+
message = f"{participants}: {message}"
121122
await util.leave_comment(
122123
gh,
123124
pr_number=pr_number,
124-
message=f"{participants}: Status check is done, and it's a {description} {emoji} .",
125+
message=message,
125126
)
126127
if success:
127128
if util.pr_is_awaiting_merge(pr_for_commit["labels"]):

tests/test_status_change.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,73 @@ async def test_ci_passed_and_check_run_failure_awaiting_merge_label_pr_is_not_me
313313
assert not hasattr(gh, "put_data") # is not merged
314314

315315

316+
async def test_automerge_with_check_run_failure():
317+
sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9"
318+
data = {"sha": sha, "commit": {"committer": {"login": "Mariatta"}}}
319+
event = sansio.Event(data, event="status", delivery_id="1")
320+
321+
getitem = {
322+
f"/repos/python/cpython/commits/{sha}/status": {
323+
"state": "success",
324+
"statuses": [
325+
{
326+
"state": "success",
327+
"description": "Issue report skipped",
328+
"context": "bedevere/issue-number",
329+
},
330+
{
331+
"state": "success",
332+
"description": "The Travis CI build passed",
333+
"target_url": "https://travis-ci.org/python/cpython/builds/340259685?utm_source=github_status&utm_medium=notification",
334+
"context": "continuous-integration/travis-ci/pr",
335+
},
336+
],
337+
},
338+
"/repos/python/cpython/pulls/5544": {
339+
"user": {"login": "miss-islington"},
340+
"merged_by": {"login": "Mariatta"},
341+
},
342+
"/repos/python/cpython/pulls/5547": {
343+
"user": {"login": "Mariatta"},
344+
"merged_by": None,
345+
"labels": [
346+
{"name": "awaiting merge"},
347+
{"name": AUTOMERGE_LABEL},
348+
],
349+
},
350+
f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": {
351+
"total_count": 1,
352+
"items": [
353+
{
354+
"number": 5547,
355+
"title": "[3.6] bpo-32720: Fixed the replacement field grammar documentation. (GH-5544)",
356+
"body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.\n(cherry picked from commit 7a561afd2c79f63a6008843b83733911d07f0119)\n\nCo-authored-by: Mariatta <[email protected]>",
357+
"labels": [
358+
{"name": "awaiting merge"},
359+
{"name": AUTOMERGE_LABEL},
360+
],
361+
}
362+
],
363+
},
364+
f"/repos/python/cpython/commits/{sha}/check-runs": {
365+
"check_runs": [
366+
{
367+
"conclusion": "failure",
368+
"name": "Travis CI - Pull Request",
369+
"status": "completed",
370+
},
371+
{"conclusion": "success", "name": "Docs", "status": "completed"},
372+
],
373+
"total_count": 1,
374+
},
375+
}
376+
377+
gh = FakeGH(getitem=getitem)
378+
await status_change.router.dispatch(event, gh)
379+
assert len(gh.post_data["body"]) is not None # leaves a comment
380+
assert not hasattr(gh, "put_data") # is not merged
381+
382+
316383
async def test_ci_passed_and_check_run_pending_awaiting_merge_label_pr_is_not_merged():
317384
sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9"
318385
data = {"sha": sha, "commit": {"committer": {"login": "miss-islington"}}}

0 commit comments

Comments
 (0)