forked from gh-training/gh-app-starter-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebhook_handlers.py
32 lines (23 loc) · 931 Bytes
/
webhook_handlers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import logging
from gh_utils import make_github_rest_api_call
"""
SPECIALIZED WEBHOOK HANDLERS
=======================
Becaue we may receive many webhooks for many different reasons, it's a good idea
to "hand off" control from `process_message()` to a dedicated function ASAP.
This is a good place for these specialized handlers
"""
log = logging.getLogger(__name__)
def add_pr_comment(webhook):
log.info('New Pull Request opened. Adding comment.')
# Gather the requried information from the payload to send a successful request to GitHub REST API.
repo_full_name = str(webhook.repository.full_name)
pr_number = str(webhook.pull_request.number)
comments_url = f'repos/{repo_full_name}/issues/{pr_number}/comments'
# Make the API call.
make_github_rest_api_call(
comments_url,
'POST', {
'body': "Hello there, thanks for creating a new Pull Request!"
}
)