-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathstatus.py
More file actions
116 lines (98 loc) · 4.1 KB
/
status.py
File metadata and controls
116 lines (98 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""Get release status of a repository"""
from constants import (
BLOCKER_LABELS,
DEPLOYED_TO_PROD,
LIBRARY_TYPE,
LIBRARY_PR_WAITING_FOR_MERGE,
RELEASE_LABELS,
STATUS_EMOJIS,
WAITING_FOR_CHECKBOXES,
)
from github import get_labels
from lib import (
get_default_branch,
init_working_dir,
)
from release import any_commits_between_branches
from version import get_project_version
async def status_for_repo_last_pr(*, github_access_token, repo_info, release_pr):
"""
Calculate release status for the most recent PR
The return value will be one of:
ALL_CHECKBOXES_CHECKED - All checkboxes are checked off and the release is ready to merge
DEPLOYED_TO_PROD - The release has been successfully deployed to production
DEPLOYING_TO_PROD - The release is in the process of being deployed to production
DEPLOYING_TO_RC - The pull request is in the middle of deploying to RC
FREEZE_RELEASE - The release is frozen, so it should be ignored until that github label is removed
LIBRARY_WAITING_FOR_RELEASE - There is a release PR for a library, waiting on the release manager to merge
WAITING_FOR_CHECKBOXES - The bot is polling regularly to check if all checkboxes are checked off
Or None if there is no previous release, or something unexpected happened.
Args:
github_access_token (str): The github access token
repo_info (RepoInfo): Repository info
release_pr (ReleasePR): The info for the release PR
Returns:
str or None: A status string
"""
if release_pr:
if repo_info.project_type == LIBRARY_TYPE:
if release_pr.open:
return LIBRARY_PR_WAITING_FOR_MERGE
else:
labels = {
label.lower()
for label in await get_labels(
github_access_token=github_access_token,
repo_url=repo_info.repo_url,
pr_number=release_pr.number,
)
}
for label in BLOCKER_LABELS:
if label.lower() in labels:
return label.lower() if release_pr.open else None
if not release_pr.open and WAITING_FOR_CHECKBOXES.lower() in labels:
# If a PR is closed and the label is 'waiting for checkboxes', just ignore it
# Maybe a user closed the PR, or the label was incorrectly updated
return None
for label in RELEASE_LABELS:
if label.lower() in labels:
return label.lower()
return None
async def status_for_repo_new_commits(*, github_access_token, repo_info, release_pr):
"""
Check if there are new commits to be part of a release
Args:
github_access_token (str): The github access token
repo_info (RepoInfo): Repository info
release_pr (ReleasePR): The info for the release PR
Returns:
bool:
Whether or not there are new commits
"""
async with init_working_dir(github_access_token, repo_info.repo_url) as working_dir:
last_version = await get_project_version(
repo_info=repo_info, working_dir=working_dir
)
default_branch = await get_default_branch(working_dir)
return await any_commits_between_branches(
branch1=(
"origin/release-candidate"
if release_pr and release_pr.open
else f"v{last_version}"
),
branch2=default_branch,
root=working_dir,
)
def format_status_for_repo(*, current_status, has_new_commits):
"""
Adds formatting to render a status
Args:
current_status (str): The status of the most recent PR for the repo
has_new_commits (bool): Whether there are new commits to release
"""
new_status_string = "*new commits*" if has_new_commits else ""
current_status_string = (
current_status if current_status and current_status != DEPLOYED_TO_PROD else ""
)
emoji = STATUS_EMOJIS.get(current_status, "")
return f"{current_status_string}{emoji} {new_status_string}".strip()