-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_status.py
34 lines (28 loc) · 1.16 KB
/
create_status.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
33
34
import os
import requests
from pprint import pprint
access_token = os.environ['GITHUB_ACCESS_TOKEN']
# TODO: needs tests
def create_status(access_token, repo_name, pull_request_sha, state):
"""
Create a new status associated with a Github pull requests
Full API documentation https://developer.github.com/v3/repos/statuses/
"""
# TODO: validation for state in ('pending', 'success', 'failure')
base_url = 'https://api.github.com'
headers = {'Authorization': 'token {}'.format(access_token)}
url = '{}/repos/{}/statuses/{}'.format(
base_url, repo_name, pull_request_sha)
# TODO: pass better info about what's happened
return requests.post(url, headers=headers, json={'state': state})
def get_commit_messages(access_token, repo_name, pull_request_id):
# Call the API to get the commit messages https://api.github.com/repos/pxg/Spoon-Knife/pulls/1/commits
# Just return commit messages
pass
response = create_status(
access_token=access_token,
repo_name='pxg/Spoon-Knife',
pull_request_sha='6ce3b87cf95900f71a3cb7742a8de25719b5de10',
state='success')
pprint(response.status_code)
pprint(response.json())