|
1 | | -from itertools import groupby |
2 | 1 | import logging |
3 | 2 | import os |
| 3 | +from itertools import groupby |
4 | 4 |
|
5 | 5 | from pydocteur.github_api import get_graphql_api |
6 | | -from pydocteur.github_api import get_rest_api |
7 | | -from pydocteur.settings import REPOSITORY_NAME |
8 | 6 |
|
9 | 7 | logger = logging.getLogger("pydocteur") |
10 | 8 |
|
11 | 9 |
|
12 | | -def get_checks_statuses_conclusions(pr): |
| 10 | +def is_pr_tests_passed(pr): |
13 | 11 | 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] |
25 | 16 | are_all_checks_done = all(status == "completed" for status in statuses) |
26 | 17 | if are_all_checks_done: |
27 | 18 | logger.info(f"PR #{pr.number} checks are done, checking conclusions") |
@@ -109,6 +100,6 @@ def get_pr_state(pr) -> str: |
109 | 100 | return state_name( |
110 | 101 | automerge=is_label_set(pr, "🤖 automerge"), |
111 | 102 | approved=is_pr_approved(pr), |
112 | | - testok=get_checks_statuses_conclusions(pr), |
| 103 | + testok=is_pr_tests_passed(pr), |
113 | 104 | donotmerge=is_label_set(pr, "DO NOT MERGE"), |
114 | 105 | ) |
0 commit comments