Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/scripts/contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,11 @@ def slack_payload(github, pr, stage):
"merged": "This contribution has been merged into the SDK."}[stage]
url = f"https://github.com/{github.repository}/pull/{pr['number']}"
return {
"text": f"{title} · {github.repository} #{pr['number']}",
"text": f"{title} · {github.repository} #{pr['number']}\n{url}",
"blocks": [
{"type": "header", "text": {"type": "plain_text", "text": title}},
{"type": "section", "text": {"type": "plain_text", "text": details}},
{"type": "section", "text": {"type": "mrkdwn", "text": f"<{url}>"}},
{"type": "section", "text": {"type": "plain_text", "text": action}},
{"type": "actions", "elements": [{"type": "button",
"text": {"type": "plain_text", "text": "View merged PR" if stage == "merged" else "Review PR"},
Expand Down
18 changes: 12 additions & 6 deletions .github/scripts/tests/test_contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,18 @@ def test_bot_prs_are_included_in_team_review_notifications(self):

def test_untrusted_title_is_only_plain_text_and_cannot_override_url(self):
github = FakeGitHub(pull(title="<!channel> <@U123> <https://evil.test|review>"))
payload = app.slack_payload(github, github.pr, "opened")
self.assertNotIn("<!channel>", payload["text"])
sections = [block for block in payload["blocks"] if block["type"] == "section"]
self.assertTrue(all(block["text"]["type"] == "plain_text" for block in sections))
self.assertEqual(payload["blocks"][-1]["elements"][0]["url"],
"https://github.com/cyberwave-os/cyberwave-python/pull/42")
url = "https://github.com/cyberwave-os/cyberwave-python/pull/42"
for stage in ("draft", "opened", "merged"):
with self.subTest(stage=stage):
payload = app.slack_payload(github, github.pr, stage)
self.assertNotIn("<!channel>", payload["text"])
self.assertIn(url, payload["text"])
sections = [block for block in payload["blocks"] if block["type"] == "section"]
self.assertEqual(sections[0]["text"]["type"], "plain_text")
self.assertIn(github.pr["title"], sections[0]["text"]["text"])
self.assertEqual(sections[1]["text"], {"type": "mrkdwn", "text": f"<{url}>"})
self.assertEqual(sections[2]["text"]["type"], "plain_text")
self.assertEqual(payload["blocks"][-1]["elements"][0]["url"], url)

def test_contributor_cannot_spoof_slack_delivery_record(self):
github = FakeGitHub()
Expand Down
Loading