Skip to content

Commit 6416606

Browse files
committed
Add issue comment sending
1 parent 700c61d commit 6416606

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

bot/github.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ def _iter_chat_ids(self, repository):
5555
if repo == repo_id:
5656
yield chat_id
5757

58+
def _send(self, repo, text):
59+
text = truncate(text, TRUNCATED_MESSAGE, REPLY_MESSAGE)
60+
61+
for chat_id in self._iter_chat_ids(repo):
62+
self.dispatcher.bot.send_message(chat_id=chat_id, text=text,
63+
parse_mode=ParseMode.HTML, disable_web_page_preview=True)
64+
5865
def issues(self, update, _):
5966
# Issue opened, edited, closed, reopened, assigned, unassigned, labeled,
6067
# unlabeled, milestoned, or demilestoned.
@@ -69,18 +76,27 @@ def issues(self, update, _):
6976
issue_link = link(issue['html_url'], f'{repo["full_name"]}#{issue["number"]} {issue["title"]}')
7077
author_link = link(author['html_url'], '@' + author['login'])
7178
data_link = encode_data_link(('issue', repo['full_name'], issue['number'], author['login']))
72-
text = f'{data_link}🐛 New Issue {issue_link}\nby {author_link}\n\n{text}'
73-
74-
text = truncate(text, TRUNCATED_MESSAGE, REPLY_MESSAGE)
79+
text = f'{data_link}🐛 New issue {issue_link}\nby {author_link}\n\n{text}'
7580

76-
for chat_id in self._iter_chat_ids(repo):
77-
self.dispatcher.bot.send_message(chat_id=chat_id, text=text,
78-
parse_mode=ParseMode.HTML, disable_web_page_preview=True)
81+
self._send(repo, text)
7982

8083
def issue_comment(self, update, context):
8184
# Any time a comment on an issue is created, edited, or deleted.
8285
# TODO: Possibly support editing and closing of comments?
83-
pass
86+
if update.payload['action'] == 'created':
87+
issue = update.payload['issue']
88+
comment = update.payload['comment']
89+
author = comment['user']
90+
repo = update.payload['repository']
91+
92+
text = render_github_markdown(comment['body'], repo['full_name'])
93+
94+
issue_link = link(issue['html_url'], f'{repo["full_name"]}#{issue["number"]} {issue["title"]}')
95+
author_link = link(author['html_url'], '@' + author['login'])
96+
data_link = encode_data_link(('issue', repo['full_name'], issue['number'], author['login']))
97+
text = f'{data_link}💬 New comment on {issue_link}\nby {author_link}\n\n{text}'
98+
99+
self._send(repo, text)
84100

85101
def pull_request(self, update, context):
86102
# Pull request opened, closed, reopened, edited, assigned, unassigned, review requested,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy