Skip to content

Commit f30ab44

Browse files
committed
Admin: Add label when notifying users
1 parent e919d63 commit f30ab44

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

backend/github_bot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def notify_user(pr_number: str, notification_text: str) -> None:
2121
access_token = GithubBot.get_access_token(installation_id, jwt_token)
2222
# use REST api to make comment
2323
QueryGithub.create_comment(access_token, pr_number, notification_text)
24+
# Set label
25+
QueryGithub.add_label(access_token, pr_number, "payment-approved")
2426

2527
@staticmethod
2628
def get_jwt_token(private_key, app_id):

backend/query_github.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ def create_comment(cls, access_token: str, pr_number: str, notification_text) ->
141141
)
142142
print(resp.__dict__)
143143

144+
@classmethod
145+
def add_label(cls, access_token: str, pr_number: str, label_name: str) -> None:
146+
resp = http.request(
147+
"POST",
148+
f"https://api.github.com/repos/{repo_owner_name}/issues/{pr_number}/labels",
149+
body=json.dumps({"labels": [label_name]}),
150+
headers={"Authorization": f"Bearer {access_token}"}
151+
)
152+
print(resp.__dict__)
153+
144154
@classmethod
145155
def get_access_token(cls, installation_id, jwt_token) -> str:
146156
resp = http.request(

integration_tests/test_admin_area.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ def test_get_contributor(self):
182182
'state': 'MERGED',
183183
'title': 'Title of PR 1',
184184
'updatedAt': '2023-07-04T16:59:28Z'}],
185-
"payments": []}
185+
"payments": [],
186+
"oc_name": None}
186187

187188
def test_create_payment(self):
188189
with patch("github_bot.GithubBot.notify_user", return_value=Mock()) as github_notifier:
@@ -305,8 +306,8 @@ def test_approve_payment(self):
305306

306307
db_item = self.ddb.scan(TableName="Payments")["Items"][0]
307308
print(db_item)
308-
assert "order" in db_item["processed"]
309-
assert "approved_by" in db_item["processed"]
309+
assert "order" in db_item["processed"]["M"]
310+
assert "approved_by" in db_item["processed"]["M"]
310311

311312
def test_unknown_caller(self):
312313
resp = admin_area.lambda_handler(event={}, context=None)

tests/test_github_bot.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,9 @@ def test_invite_user(self):
6969
assert comment_url == ("POST", "https://api.github.com/repos/owner/repo/issues/42/comments")
7070
assert comment_details == {'body': '{"body": "some text"}', 'headers': {'Authorization': 'Bearer some access token'}}
7171

72+
comment_url, comment_details = github_http.call_args_list[2]
73+
assert comment_url == ("POST", "https://api.github.com/repos/owner/repo/issues/42/labels")
74+
assert comment_details == {'body': '{"labels": ["payment-approved"]}', 'headers': {'Authorization': 'Bearer some access token'}}
75+
7276
def test_get_bot_details(self):
7377
assert self.bot.get_bot_details() == (self.app_id, self.installation_id, self.private_key_bytes)

website/details.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
document.getElementById("details").value = "Development of ...";
104104
document.getElementById("amount").value = "";
105105
document.getElementById("pr_notification").value = "";
106+
document.getElementById("pr_text").value = pr_text;
106107
document.getElementById("submitbutton").removeAttribute("aria-busy");
107108
// Scroll to the top, so the user can see the latest updates
108109
window.scrollTo(0, 0);

0 commit comments

Comments
 (0)