@@ -81,35 +81,100 @@ def issues(self, update, _):
8181 self ._send (repo , text )
8282
8383 def issue_comment (self , update , context ):
84- # Any time a comment on an issue is created, edited, or deleted.
84+ # Any time a comment on an issue or pull request is created, edited, or deleted.
8585 # TODO: Possibly support editing and closing of comments?
8686 if update .payload ['action' ] == 'created' :
8787 issue = update .payload ['issue' ]
8888 comment = update .payload ['comment' ]
8989 author = comment ['user' ]
9090 repo = update .payload ['repository' ]
91+ is_pull_request = 'pull_request' in issue
9192
9293 text = render_github_markdown (comment ['body' ], repo ['full_name' ])
9394
9495 issue_link = link (issue ['html_url' ], f'{ repo ["full_name" ]} #{ issue ["number" ]} { issue ["title" ]} ' )
9596 author_link = link (author ['html_url' ], '@' + author ['login' ])
96- data_link = encode_data_link (('issue' , repo ['full_name' ], issue ['number' ], author ['login' ]))
97+ data_link = encode_data_link (('pull request' if is_pull_request else 'issue' ,
98+ repo ['full_name' ], issue ['number' ], author ['login' ]))
9799 text = f'{ data_link } 💬 New comment on { issue_link } \n by { author_link } \n \n { text } '
98100
99101 self ._send (repo , text )
100102
101103 def pull_request (self , update , context ):
102104 # Pull request opened, closed, reopened, edited, assigned, unassigned, review requested,
103105 # review request removed, labeled, unlabeled, or synchronized.
104- pass
106+ # TODO: Possibly support closed, reopened, edited, assigned etc.
107+ if update .payload ['action' ] == 'opened' :
108+ pull_request = update .payload ['pull_request' ]
109+ author = pull_request ['user' ]
110+ repo = update .payload ['repository' ]
111+
112+ text = render_github_markdown (pull_request ['body' ], repo ['full_name' ])
113+
114+ pull_request_link = link (pull_request ['html_url' ],
115+ f'{ repo ["full_name" ]} #{ pull_request ["number" ]} { pull_request ["title" ]} ' )
116+ author_link = link (author ['html_url' ], '@' + author ['login' ])
117+ data_link = encode_data_link (('pull request' , repo ['full_name' ], pull_request ['number' ], author ['login' ]))
118+ text = f'{ data_link } 🔌 New pull request { pull_request_link } \n by { author_link } \n \n { text } '
119+
120+ self ._send (repo , text )
105121
106122 def pull_request_review (self , update , context ):
107123 # Pull request review submitted, edited, or dismissed.
108- pass
124+ # TODO: Possibly support edited and dismissed?
125+ if update .payload ['action' ] == 'submitted' :
126+ review = update .payload ['review' ]
127+ pull_request = update .payload ['pull_request' ]
128+ author = review ['user' ]
129+ repo = update .payload ['repository' ]
130+
131+ if not review ['body' ]:
132+ return
133+
134+ text = render_github_markdown (review ['body' ], repo ['full_name' ])
135+
136+ review_link = link (review ['html_url' ],
137+ f'{ repo ["full_name" ]} #{ pull_request ["number" ]} { pull_request ["title" ]} ' )
138+ author_link = link (author ['html_url' ], '@' + author ['login' ])
139+ data_link = encode_data_link (('pull request' , repo ['full_name' ], pull_request ['number' ], author ['login' ]))
140+
141+ if review ['state' ] in ('commented' , 'approved' , 'request_changes' ):
142+ if review ['state' ] == 'commented' :
143+ state = 'Commented'
144+ emoji = '💬'
145+ elif review ['state' ] == 'approved' :
146+ state = 'Approved'
147+ emoji = '✅'
148+ elif review ['state' ] == 'request_changes' :
149+ state = 'Changes requested'
150+ emoji = '‼️'
151+
152+ text = f'{ data_link } { emoji } New pull request review { review_link } \n { state } by { author_link } \n \n { text } '
153+ self ._send (repo , text )
109154
110155 def pull_request_review_comment (self , update , context ):
111156 # Pull request diff comment created, edited, or deleted.
112- pass
157+ if update .payload ['action' ] == 'created' :
158+ pull_request = update .payload ['pull_request' ]
159+ comment = update .payload ['comment' ]
160+ author = comment ['user' ]
161+ repo = update .payload ['repository' ]
162+
163+ diff_hunk = f'<pre>{ comment ["path" ]} \n { comment ["diff_hunk" ]} </pre>'
164+
165+ text = render_github_markdown (comment ['body' ], repo ['full_name' ])
166+
167+ issue_link = link (comment ['html_url' ],
168+ f'{ repo ["full_name" ]} #{ pull_request ["number" ]} { pull_request ["title" ]} ' )
169+ author_link = link (author ['html_url' ], '@' + author ['login' ])
170+ data_link = encode_data_link (('pull request review comment' ,
171+ repo ['full_name' ],
172+ pull_request ['number' ],
173+ comment ['in_reply_to_id' ] if 'in_reply_to_id' in comment else comment ['id' ],
174+ author ['login' ],))
175+ text = f'{ data_link } 💬 New pull request review comment { issue_link } \n by { author_link } \n { diff_hunk } \n \n { text } '
176+
177+ self ._send (repo , text )
113178
114179 # def integration_installation_repositories(self, update, context):
115180 # new_repos = [{'id': repo['id'], 'full_name': repo['full_name']} for repo in
0 commit comments