|
6 | 6 | from bot.githubapi import github_api
|
7 | 7 | from bot.githubupdates import GithubAuthUpdate, GithubUpdate
|
8 | 8 | from bot.menu import edit_menu_by_id
|
9 |
| -from bot.utils import github_cleaner |
| 9 | +from bot.utils import github_cleaner, link, truncate, encode_data_link |
10 | 10 |
|
11 |
| -GITHUB_API_ACCEPT = {'Accept': 'application/vnd.github.machine-man-preview+json'} |
| 11 | +TRUNCATED_MESSAGE = '\n<b>[Truncated message, open on GitHub to read more]</b>' |
| 12 | +REPLY_MESSAGE = '\n\n<i>Reply to this message to post a comment on GitHub.</i>' |
12 | 13 |
|
13 | 14 |
|
14 | 15 | def render_github_markdown(markdown, context: str):
|
15 | 16 | html = github_api.markdown(markdown, context)
|
16 |
| - return github_cleaner.clean(html) |
| 17 | + return github_cleaner.clean(html).strip('\n') |
17 | 18 |
|
18 | 19 |
|
19 | 20 | class GithubHandler:
|
@@ -58,13 +59,23 @@ def issues(self, update, _):
|
58 | 59 | # Issue opened, edited, closed, reopened, assigned, unassigned, labeled,
|
59 | 60 | # unlabeled, milestoned, or demilestoned.
|
60 | 61 | # TODO: Possibly support editing, closing, reopening, etc. of issues
|
61 |
| - issue = update.payload['issue'] |
62 |
| - repo = update.payload['repository'] |
| 62 | + if update.payload['action'] == 'opened': |
| 63 | + issue = update.payload['issue'] |
| 64 | + author = issue['user'] |
| 65 | + repo = update.payload['repository'] |
63 | 66 |
|
64 |
| - text = render_github_markdown(issue['body'], repo['full_name']) |
| 67 | + text = render_github_markdown(issue['body'], repo['full_name']) |
65 | 68 |
|
66 |
| - for chat_id in self._iter_chat_ids(repo): |
67 |
| - self.dispatcher.bot.send_message(chat_id=chat_id, text=text, parse_mode=ParseMode.HTML) |
| 69 | + issue_link = link(issue['html_url'], f'{repo["full_name"]}#{issue["number"]} {issue["title"]}') |
| 70 | + author_link = link(author['html_url'], '@' + author['login']) |
| 71 | + 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) |
| 75 | + |
| 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) |
68 | 79 |
|
69 | 80 | def issue_comment(self, update, context):
|
70 | 81 | # Any time a comment on an issue is created, edited, or deleted.
|
|
0 commit comments