Skip to content

Instantly share code, notes, and snippets.

@mammuth
Last active March 8, 2017 15:23
Show Gist options
  • Save mammuth/29152b78e624a66135d8dd74a1d809fa to your computer and use it in GitHub Desktop.
Save mammuth/29152b78e624a66135d8dd74a1d809fa to your computer and use it in GitHub Desktop.
Simple script that allows us to comment to pull requests with a GitHub bot
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
import json
import requests
GITHUB_API_URL = 'https://api.github.com'
TOKEN = 'YOUR_SECRET_TOKEN_HERE'
def comment_on_pull_request(pr_number, slug, token, comment):
""" Comment message on a given GitHub pull request. """
url = '{api_url}/repos/{slug}/issues/{number}/comments'.format(
api_url=GITHUB_API_URL, slug=slug, number=pr_number)
response = requests.post(url, data=json.dumps({'body': comment}),
headers={'Authorization': 'token ' + token})
print(response.text)
return response.json()
PR_NUMBER = 1
REPO_SLUG = 'mammuth/TCA-ci-test'
comment = 'Test comment'
comment_on_pull_request(PR_NUMBER, REPO_SLUG, TOKEN, comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment