-
Notifications
You must be signed in to change notification settings - Fork 11
/
issues.py
79 lines (59 loc) · 2.17 KB
/
issues.py
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
from django.conf import settings
from furl import furl
from jobserver.utils import strip_whitespace
from .slack import post_slack_update
def get_issue_title(workspace_name, release_request_id):
return f"{workspace_name} {release_request_id}"
def create_output_checking_issue(
workspace, release_request_id, request_author, org, repo, github_api
):
is_internal = request_author.orgs.filter(pk=settings.BENNETT_ORG_PK).exists()
base_url = furl(settings.BASE_URL)
requester_url = base_url / request_author.get_staff_url()
workspace_url = base_url / workspace.get_absolute_url()
body = f"""
Requested by: [{request_author.name}]({requester_url})
Release request ID: {release_request_id}
GitHub repo: [{workspace.repo.name}]({workspace.repo.url})
Workspace: [{workspace.name}]({workspace_url})
**When you start a review please react to this message with :eyes:. When you have completed your review add a :thumbsup:.**
"""
body = strip_whitespace(body)
data = github_api.create_issue(
org=org,
repo=repo,
title=get_issue_title(workspace.name, release_request_id),
body=body,
labels=["internal" if is_internal else "external"],
)
return data["html_url"]
def close_output_checking_issue(
release_request_id, user, reason, org, repo, github_api
):
data = github_api.close_issue(
org=org,
repo=repo,
title_text=release_request_id,
comment=f"Issue closed: {reason} by {user.username}",
)
return data["html_url"]
def update_output_checking_issue(
release_request_id, workspace_name, updates, org, repo, github_api, notify_slack
):
updates_string = "\n".join([f"- {update}" for update in updates])
body = f"Release request updated:\n{updates_string}"
data = github_api.create_issue_comment(
org=org,
repo=repo,
title_text=release_request_id,
body=body,
)
comment_url = data["html_url"]
if notify_slack:
post_slack_update(
org,
comment_url,
get_issue_title(workspace_name, release_request_id),
updates_string,
)
return comment_url