Created
December 17, 2019 12:31
-
-
Save gabrielgrant/c51d7764a861e97925cf624cf48b7a2d to your computer and use it in GitHub Desktop.
Script to submit a list of issues to GH that have been collected in a single text file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Submit a list of issues to GH | |
Issues are separated by two blank lines (three newline characters) | |
The first line is used as the title | |
""" | |
# py2/3 compat | |
from __future__ import print_function | |
try: | |
input = raw_input | |
except NameError: | |
pass | |
import json | |
import requests | |
TOKEN = 'YOUR_GITHUB_TOKEN' | |
USAGE = "submit_gh_issues.py <issues.txt> <owner> <repo>" | |
URL_TMPL = 'https://api.github.com/repos/{}/{}/issues?access_token=' + TOKEN | |
def main(args): | |
if len(args) != 3: | |
print(USAGE) | |
return | |
issues_filename, owner, repo = args | |
issues = open(issues_filename).read().split('\n\n\n') | |
print('submitting {} issues to {}/{}'.format(len(issues), owner, repo)) | |
url = URL_TMPL.format(owner, repo) | |
for issue in issues: | |
print(issue) | |
sections = issue.split('\n\n', 1) | |
title = sections.pop(0) | |
try: | |
body = sections.pop() | |
except IndexError: | |
body = '' | |
payload = {'title': title, 'body': body} | |
print(payload) | |
if input('submit issue? [yN] ').lower() == 'y': | |
r = requests.post(url, data=json.dumps(payload)) | |
print(r.json()['html_url']) | |
print('\n') | |
if __name__ == '__main__': | |
import sys | |
main(sys.argv[1:]) | |
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment