@@ -57,8 +57,8 @@ def _iter_repos(self, repository):
57
57
if repo .id == repo_id :
58
58
yield chat_id , repo
59
59
60
- def _send (self , repo , text , check_repo : Callable [[Repo ], bool ]):
61
- text = truncate (text , TRUNCATED_MESSAGE , REPLY_MESSAGE )
60
+ def _send (self , repo , text , check_repo : Callable [[Repo ], bool ], suffix = REPLY_MESSAGE ):
61
+ text = truncate (text , TRUNCATED_MESSAGE , suffix )
62
62
63
63
for chat_id , repo in self ._iter_repos (repo ):
64
64
if check_repo (repo ):
@@ -179,6 +179,62 @@ def pull_request_review_comment(self, update, context):
179
179
180
180
self ._send (repo , text , lambda r : r .pull_review_comments )
181
181
182
+ def push (self , update , context ):
183
+ # Triggered on a push to a repository branch.
184
+ # Branch pushes and repository tag pushes also trigger webhook push events.
185
+ commits = update .payload ['commits' ]
186
+ ref = update .payload ['ref' ]
187
+
188
+ if commits and ref .startswith ('refs/heads/' ):
189
+ branch = ref [len ('refs/heads/' ):]
190
+ repo = update .payload ['repository' ]
191
+ compare = update .payload ['compare' ]
192
+
193
+ text = f'🔨 <a href="{ compare } ">{ len (commits )} new commits</a> to { repo ["full_name" ]} :{ branch } \n \n '
194
+
195
+ for commit in commits :
196
+ text += f'<a href="{ commit ["url" ]} ">{ commit ["id" ][:7 ]} </a>: { commit ["message" ]} by { commit ["author" ]["name" ]} '
197
+
198
+ self ._send (repo , text , lambda r : (r .push_main or r .push ) if branch == repo ["default_branch" ] else r .push ,
199
+ suffix = '' )
200
+
201
+ def gollum (self , update , context ):
202
+ # Wiki page is created or updated.
203
+ pages = update .payload ['pages' ]
204
+ repo = update .payload ['repository' ]
205
+ sender = update .payload ['sender' ]
206
+
207
+ text = f'🔨 { len (pages )} { repo ["full_name" ]} wiki page{ "s" if len (pages ) > 1 else "" } were updated '
208
+ sender_link = link (sender ['html_url' ], '@' + sender ['login' ])
209
+ text += f'by { sender_link } \n \n '
210
+
211
+ for page in pages :
212
+ text += f'<a href="{ page ["html_url" ]} ">{ page ["title" ]} </a>'
213
+
214
+ self ._send (repo , text , lambda r : r .wiki_pages , suffix = '' )
215
+
216
+ def commit_comment (self , update , context ):
217
+ if update .payload ['action' ] == 'created' :
218
+ repo = update .payload ['repository' ]
219
+ comment = update .payload ['comment' ]
220
+ author = comment ['user' ]
221
+
222
+ author_link = link (author ['html_url' ], '@' + author ['login' ])
223
+ text = f'💬 <a href="{ comment ["html_url" ]} ">New comment</a> on commit { comment ["commit_id" ][:7 ]} by { author_link } '
224
+ position , line , path = comment ['position' ], comment ['line' ], comment ['path' ]
225
+ if path :
226
+ text += f'\n Path: { path } '
227
+ if line :
228
+ text += f'\n Line: { line } '
229
+ if position == 1 :
230
+ text += ' (before)'
231
+ elif position == 2 :
232
+ text += ' (after)'
233
+
234
+ text += f'\n \n { comment ["body" ]} '
235
+
236
+ self ._send (repo , text , lambda r : r .commit_comments , suffix = '' )
237
+
182
238
# def integration_installation_repositories(self, update, context):
183
239
# new_repos = [{'id': repo['id'], 'full_name': repo['full_name']} for repo in
184
240
# update.payload['repositories_added']]
0 commit comments