Skip to content

Commit

Permalink
src/webhooks.py: Add issue titles to issue comment webhooks, include …
Browse files Browse the repository at this point in the history
…links to comments in comment created webhooks
  • Loading branch information
cbrxyz committed Sep 20, 2024
1 parent d369ad1 commit 2027024
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async def push(self, payload: ClientPayload):
)
else:
formatted_commits = [
f"* [`{commit['id'][:7]}`]({self.url(commit)}): \"{commit['message'][:100]}\""
f"* [`{commit['id'][:7]}`]({self.url(commit)}): \"{self.natural_wrap(commit['message'])[:100]}\""
for commit in gh["commits"]
]
formatted_commits_str = "\n".join(formatted_commits)
Expand Down Expand Up @@ -326,9 +326,10 @@ async def commit_comment(self, payload: ClientPayload):
commit = f"[`{gh['comment']['commit_id'][:7]}`]({self.url(gh['comment'], html=True)})"
repo = f"[{gh['repository']['full_name']}]({self.url(gh['repository'], html=True)})"
comment = f"\"{self.natural_wrap(gh['comment']['body'])}\""
commented = f"[commented]({self.url(gh['comment'], html=True)})"
updates_channel = self.updates_channel(gh["repository"])
await updates_channel.send(
f"{name} commented on commit {commit} in {repo}: {comment}",
f"{name} {commented} on commit {commit} in {repo}: {comment}",
)

@Server.route()
Expand All @@ -340,9 +341,10 @@ async def issues_comment_created(self, payload: ClientPayload):
issue = f"[#{gh['issue']['number']}]({self.url(gh['issue'], html=True)})"
repo = f"[{gh['repository']['full_name']}]({self.url(gh['repository'], html=True)})"
comment = f"\"{self.natural_wrap(gh['comment']['body'])}\""
commented = f"[commented]({self.url(gh['comment'], html=True)})"
updates_channel = self.updates_channel(gh["repository"])
await updates_channel.send(
f"{name} commented on issue {issue} in {repo}: {comment}",
f"{name} {commented} on issue {issue} in {repo}: {comment}",
)

@Server.route()
Expand All @@ -355,11 +357,12 @@ async def issues_assigned(self, payload: ClientPayload):
issue = f"[#{gh['issue']['number']}]({self.url(gh['issue'], html=True)})"
repo = f"[{gh['repository']['full_name']}]({self.url(gh['repository'], html=True)})"
updates_channel = self.updates_channel(gh["repository"])
issue_title = f"\"{gh['issue']['title']}\""
# If the issue has a *-notify label, send a message to the relevant channel
message = (
f"{name} self-assigned issue {issue} in {repo}"
f"{name} self-assigned issue {issue} in {repo}: {issue_title}"
if gh["assignee"]["login"] == gh["sender"]["login"]
else f"{name} assigned {assigned} to issue {issue} in {repo}"
else f"{name} assigned {assigned} to issue {issue} in {repo}: {issue_title}"
)
await updates_channel.send(message)

Expand All @@ -373,10 +376,11 @@ async def issues_unassigned(self, payload: ClientPayload):
issue = f"[#{gh['issue']['number']}]({self.url(gh['issue'], html=True)})"
repo = f"[{gh['repository']['full_name']}]({self.url(gh['repository'], html=True)})"
updates_channel = self.updates_channel(gh["repository"])
issue_title = f"\"{gh['issue']['title']}\""
message = (
f"{name} unassigned themself from issue {issue} in {repo}"
f"{name} unassigned themself from issue {issue} in {repo}: {issue_title}"
if gh["assignee"]["login"] == gh["sender"]["login"]
else f"{name} unassigned {unassigned} from issue {issue} in {repo}"
else f"{name} unassigned {unassigned} from issue {issue} in {repo}: {issue_title}"
)
await updates_channel.send(message)

Expand Down Expand Up @@ -481,7 +485,7 @@ async def repository_unarchived(self, payload: ClientPayload):
async def issue_comment_created(self, payload: ClientPayload):
gh = payload.github_data
# Send a message to github-updates in the form of:
# [User A](link) commented on issue [#XXX](link) in [repo_name](link): "comment"
# [User A](link) commented on issue [#XXX](link) ("title") in [repo_name](link): "comment"

# Ignore uf-mil-bot comments (which are automated and not useful to notify on)
if gh["sender"]["login"] == "uf-mil-bot":
Expand All @@ -491,9 +495,11 @@ async def issue_comment_created(self, payload: ClientPayload):
issue = f"[#{gh['issue']['number']}]({self.url(gh['issue'], html=True)})"
repo = f"[{gh['repository']['full_name']}]({self.url(gh['repository'], html=True)})"
comment = f"\"{self.natural_wrap(gh['comment']['body'])}\""
commented = f"[commented]({self.url(gh['comment'], html=True)})"
updates_channel = self.updates_channel(gh["repository"])
issue_title = f"\"{gh['issue']['title']}\""
await updates_channel.send(
f"{name} commented on issue {issue} in {repo}: {comment}",
f"{name} {commented} on issue {issue} ({issue_title}) in {repo}: {comment}",
)

@Server.route()
Expand Down

0 comments on commit 2027024

Please sign in to comment.