Skip to content

Commit be4c6e1

Browse files
authored
Upgraded pygithub to use checksuites (#47)
1 parent c7c88ba commit be4c6e1

File tree

5 files changed

+437
-25
lines changed

5 files changed

+437
-25
lines changed

pydocteur/github_api.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
import logging
22

33
import requests
4-
from requests.auth import HTTPBasicAuth
54
from github import Github
65

76
from pydocteur.settings import GH_TOKEN
8-
from pydocteur.settings import GH_USERNAME
97
from pydocteur.settings import REPOSITORY_NAME
108

119
logger = logging.getLogger("pydocteur")
1210
gh = Github(GH_TOKEN if GH_TOKEN else None)
1311

1412

15-
def get_rest_api(url: str) -> requests.Response:
16-
resp = requests.get(url, auth=HTTPBasicAuth(GH_USERNAME, GH_TOKEN))
17-
return resp
18-
19-
2013
def get_graphql_api(query: str) -> requests.Response:
2114
headers = {"Authorization": "Bearer {}".format(GH_TOKEN)}
2215
resp = requests.post("https://api.github.com/graphql", json={"query": query}, headers=headers)

pydocteur/pr_status.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,18 @@
1-
from itertools import groupby
21
import logging
32
import os
3+
from itertools import groupby
44

55
from pydocteur.github_api import get_graphql_api
6-
from pydocteur.github_api import get_rest_api
7-
from pydocteur.settings import REPOSITORY_NAME
86

97
logger = logging.getLogger("pydocteur")
108

119

12-
def get_checks_statuses_conclusions(pr):
10+
def is_pr_tests_passed(pr):
1311
logger.info(f"Checking PR #{pr.number} CI results")
14-
commits_sha = [commit.sha for commit in pr.get_commits()]
15-
last_sha = commits_sha[-1]
16-
logger.debug(f"PR #{pr.number} last sha is {last_sha}")
17-
logger.info(f"Getting runs for PR #{pr.number}")
18-
resp = get_rest_api(f"https://api.github.com/repos/{REPOSITORY_NAME}/commits/{last_sha}/check-runs")
19-
runs = resp.json()["check_runs"]
20-
if not runs:
21-
logger.info(f"No runs for PR #{pr.number}.")
22-
return False
23-
statuses = [run["status"] for run in runs]
24-
conclusions = [run["conclusion"] for run in runs]
12+
last_commit = [commit for commit in pr.get_commits()][-1]
13+
check_suites = last_commit.get_check_suites()
14+
statuses = [suite.status for suite in check_suites]
15+
conclusions = [suite.conclusion for suite in check_suites]
2516
are_all_checks_done = all(status == "completed" for status in statuses)
2617
if are_all_checks_done:
2718
logger.info(f"PR #{pr.number} checks are done, checking conclusions")
@@ -109,6 +100,6 @@ def get_pr_state(pr) -> str:
109100
return state_name(
110101
automerge=is_label_set(pr, "🤖 automerge"),
111102
approved=is_pr_approved(pr),
112-
testok=get_checks_statuses_conclusions(pr),
103+
testok=is_pr_tests_passed(pr),
113104
donotmerge=is_label_set(pr, "DO NOT MERGE"),
114105
)

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
flask==1.1.2
2-
pygithub==1.53
2+
pygithub==1.54
33
python-dotenv==0.15.0
4-
requests==2.25.0
4+
requests==2.24.0
55
pyyaml==5.3.1

0 commit comments

Comments
 (0)