Skip to content

Commit 55e8b90

Browse files
authored
Handle check_run completed webhook events (#383)
* Handle check_run completed webhook events * πŸπŸŒšπŸ€– Formatted using `black`. * Improve test coverage * πŸπŸŒšπŸ€– Formatted using `black`.
1 parent d9ba7af commit 55e8b90

File tree

4 files changed

+632
-11
lines changed

4 files changed

+632
-11
lines changed

β€Žmiss_islington/__main__.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
import aiohttp
21
import asyncio
32
import os
43
import sys
54
import traceback
6-
import cachetools
75

6+
import aiohttp
7+
import cachetools
8+
import sentry_sdk
89
from aiohttp import web
9-
1010
from gidgethub import aiohttp as gh_aiohttp
11-
from gidgethub import routing
12-
from gidgethub import sansio
11+
from gidgethub import routing, sansio
1312

13+
from . import backport_pr, check_run, delete_branch, status_change
1414

15-
from . import backport_pr
16-
from . import delete_branch
17-
from . import status_change
18-
19-
router = routing.Router(backport_pr.router, delete_branch.router, status_change.router)
15+
router = routing.Router(
16+
backport_pr.router, delete_branch.router, status_change.router, check_run.router
17+
)
2018

2119
cache = cachetools.LRUCache(maxsize=500)
2220

23-
import sentry_sdk
2421

2522
sentry_sdk.init(os.environ.get("SENTRY_DSN"))
2623

β€Žmiss_islington/check_run.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import re
2+
3+
from gidgethub import routing
4+
5+
from . import util
6+
from .status_change import check_ci_status_and_approval
7+
8+
router = routing.Router()
9+
10+
TITLE_RE = re.compile(r"\[(?P<branch>\d+\.\d+)\].+?(?P<pr>\d+)\)")
11+
AUTOMERGE_TRAILER = "Automerge-Triggered-By"
12+
13+
14+
@router.register("check_run", action="completed")
15+
async def check_run_completed(event, gh, *args, **kwargs):
16+
"""
17+
A check run is completed event handler.
18+
"""
19+
sha = event.data["check_run"]["head_sha"]
20+
21+
if event.data["sender"]["login"] == "miss-islington":
22+
await check_ci_status_and_approval(gh, sha, leave_comment=True)
23+
else:
24+
pr_for_commit = await util.get_pr_for_commit(gh, sha)
25+
if pr_for_commit:
26+
pr_labels = pr_for_commit["labels"]
27+
print("is auomer")
28+
print(util.pr_is_automerge(pr_labels))
29+
print(util.pr_is_awaiting_merge(pr_labels))
30+
print("pr label")
31+
print(pr_labels)
32+
if util.pr_is_automerge(pr_labels) and util.pr_is_awaiting_merge(pr_labels):
33+
await check_ci_status_and_approval(
34+
gh,
35+
sha,
36+
pr_for_commit=pr_for_commit,
37+
leave_comment=True,
38+
is_automerge=True,
39+
)

β€Žmiss_islington/status_change.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ async def check_ci_status_and_approval(
135135
emoji = "βœ…"
136136
else:
137137
emoji = "❌"
138+
print("leaving a comment")
138139
await util.leave_comment(
139140
gh,
140141
pr_number=pr_number,

0 commit comments

Comments
Β (0)