You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
2.0 KiB

  1. #!/usr/bin/env python
  2. # Open a PR against the develop branch. --branch required.
  3. # Optimized for CircleCI
  4. import json
  5. import os
  6. import argparse
  7. import httplib
  8. from base64 import b64encode
  9. def request(org, repo, data):
  10. user_and_pass = b64encode(b"{0}:{1}".format(os.environ['GITHUB_USERNAME'], os.environ['GITHUB_TOKEN'])).decode("ascii")
  11. headers = {
  12. 'User-Agent': 'tenderbot',
  13. 'Accept': 'application/vnd.github.v3+json',
  14. 'Authorization': 'Basic %s' % user_and_pass
  15. }
  16. conn = httplib.HTTPSConnection('api.github.com', timeout=5)
  17. conn.request('POST', '/repos/{0}/{1}/pulls'.format(org,repo), data, headers)
  18. response = conn.getresponse()
  19. if response.status < 200 or response.status > 299:
  20. print(response)
  21. conn.close()
  22. raise IOError(response.reason)
  23. responsedata = response.read()
  24. conn.close()
  25. return json.loads(responsedata)
  26. if __name__ == "__main__":
  27. parser = argparse.ArgumentParser()
  28. parser.add_argument("--org", default="tendermint", help="GitHub organization. Defaults to tendermint.")
  29. parser.add_argument("--repo", default="tendermint", help="GitHub repository. Defaults to tendermint.")
  30. parser.add_argument("--head", help="The name of the branch where your changes are implemented.", required=True)
  31. parser.add_argument("--base", help="The name of the branch you want the changes pulled into.", required=True)
  32. parser.add_argument("--title", default="Security release {0}".format(os.environ.get('CIRCLE_TAG')), help="The title of the pull request.")
  33. args = parser.parse_args()
  34. if not os.environ.has_key('GITHUB_USERNAME'):
  35. raise parser.error('GITHUB_USERNAME not set.')
  36. if not os.environ.has_key('GITHUB_TOKEN'):
  37. raise parser.error('GITHUB_TOKEN not set.')
  38. if os.environ.get('CIRCLE_TAG') is None:
  39. raise parser.error('CIRCLE_TAG not set.')
  40. result = request(args.org, args.repo, data=json.dumps({'title':"{0}".format(args.title),'head':"{0}".format(args.head),'base':"{0}".format(args.base),'body':"<Please fill in details.>"}))
  41. print(result['html_url'])