Skip to content

Commit 27585d5

Browse files
committed
1 parent 9020677 commit 27585d5

File tree

2 files changed

+51
-11
lines changed

2 files changed

+51
-11
lines changed

bot/github.py

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,28 @@ def issues(self, update, _):
7878
# Issue opened, edited, closed, reopened, assigned, unassigned, labeled,
7979
# unlabeled, milestoned, or demilestoned.
8080
# TODO: Possibly support editing, closing, reopening, etc. of issues
81-
if update.payload['action'] == 'opened':
81+
if update.payload['action'] in ('opened', 'closed', 'reopened'):
8282
issue = update.payload['issue']
8383
author = issue['user']
8484
repo = update.payload['repository']
8585

86-
text = render_github_markdown(issue['body'], repo['full_name'])
86+
if update.payload['action'] == 'opened':
87+
desc = '🐛 New issue'
88+
if issue['body']:
89+
text = "\n\n" + render_github_markdown(issue['body'], repo['full_name'])
90+
else:
91+
text = "\n\nNo description provided."
92+
elif update.payload['action'] == 'closed':
93+
desc = '✅ Issue closed'
94+
text = ""
95+
elif update.payload['action'] == 'reopened':
96+
desc = '🔄 Issue reopened'
97+
text = ""
8798

8899
issue_link = link(issue['html_url'], f'{repo["full_name"]}#{issue["number"]} {issue["title"]}')
89100
author_link = link(author['html_url'], '@' + author['login'])
90101
data_link = encode_data_link(('issue', repo['full_name'], issue['number'], author['login']))
91-
text = f'{data_link}🐛 New issue {issue_link}\nby {author_link}\n\n{text}'
102+
text = f'{data_link}{desc} {issue_link}\nby {author_link}{text}'
92103

93104
self._send(repo, text, lambda r: r.issues)
94105

@@ -112,6 +123,23 @@ def issue_comment(self, update, context):
112123

113124
self._send(repo, text, lambda r: r.pull_comments if is_pull_request else r.issue_comments)
114125

126+
def discussion(self, update, _):
127+
# Discussion created, edited, deleted, pinned, unpinned, locked, unlocked, transferred,
128+
# category_changed, answered, unanswered, labeled, or unlabeled
129+
if update.payload['action'] == 'created':
130+
discussion = update.payload['discussion']
131+
author = discussion['user']
132+
repo = update.payload['repository']
133+
134+
text = render_github_markdown(discussion['body'], repo['full_name'])
135+
136+
issue_link = link(discussion['html_url'], f'{repo["full_name"]}#{discussion["number"]} {discussion["title"]}')
137+
author_link = link(author['html_url'], '@' + author['login'])
138+
data_link = encode_data_link(('discussion', repo['full_name'], discussion['number'], author['login']))
139+
text = f'{data_link}⁉️ New discussion {issue_link}\nby {author_link}\n\n{text}'
140+
141+
self._send(repo, text, lambda r: r.issues, suffix="")
142+
115143
def pull_request(self, update, context):
116144
# Pull request opened, closed, reopened, edited, assigned, unassigned, review requested,
117145
# review request removed, labeled, unlabeled, or synchronized.
@@ -121,7 +149,10 @@ def pull_request(self, update, context):
121149
author = pull_request['user']
122150
repo = update.payload['repository']
123151

124-
text = render_github_markdown(pull_request['body'], repo['full_name'])
152+
if pull_request['body']:
153+
text = render_github_markdown(pull_request['body'], repo['full_name'])
154+
else:
155+
text = "No description provided"
125156

126157
pull_request_link = link(pull_request['html_url'],
127158
f'{repo["full_name"]}#{pull_request["number"]} {pull_request["title"]}')
@@ -140,28 +171,28 @@ def pull_request_review(self, update, context):
140171
author = review['user']
141172
repo = update.payload['repository']
142173

143-
if not review['body']:
144-
return
145-
146-
text = render_github_markdown(review['body'], repo['full_name'])
174+
if review['body']:
175+
text = "\n\n" + render_github_markdown(review['body'], repo['full_name'])
176+
else:
177+
text = ""
147178

148179
review_link = link(review['html_url'],
149180
f'{repo["full_name"]}#{pull_request["number"]} {pull_request["title"]}')
150181
author_link = link(author['html_url'], '@' + author['login'])
151182
data_link = encode_data_link(('pull request', repo['full_name'], pull_request['number'], author['login']))
152183

153-
if review['state'] in ('commented', 'approved', 'request_changes'):
184+
if review['state'] in ('commented', 'approved', 'request_changes', 'changes_requested'):
154185
if review['state'] == 'commented':
155186
state = 'Commented'
156187
emoji = '💬'
157188
elif review['state'] == 'approved':
158189
state = 'Approved'
159190
emoji = '✅'
160-
elif review['state'] == 'request_changes':
191+
elif review['state'] in ('request_changes', 'changes_requested'):
161192
state = 'Changes requested'
162193
emoji = '‼️'
163194

164-
text = f'{data_link}{emoji} New pull request review {review_link}\n{state} by {author_link}\n\n{text}'
195+
text = f'{data_link}{emoji} New pull request review {review_link}\n{state} by {author_link}{text}'
165196
self._send(repo, text, lambda r: r.pull_reviews)
166197

167198
def pull_request_review_comment(self, update, context):

main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ def reply_handler(update: Update, context: CallbackContext):
124124
context.job_queue.run_once(delete_job, 30, sent_msg)
125125
return
126126

127+
if comment_type == 'discussion':
128+
sent_msg = msg.reply_text(f'Cannot reply discussions.\n\n'
129+
f'<i>This message will self destruct in 30 sec.</i>',
130+
parse_mode=ParseMode.HTML,
131+
disable_notification=True)
132+
context.job_queue.run_once(delete_job, 30, sent_msg)
133+
return
134+
135+
127136
if comment_type in ('issue', 'pull request'):
128137
repo, number, author = data
129138
text = f'@{author} {msg.text_html}'

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