Skip to content

Instantly share code, notes, and snippets.

@gabrielgrant
Created December 17, 2019 12:31

Revisions

  1. gabrielgrant created this gist Dec 17, 2019.
    53 changes: 53 additions & 0 deletions submit_gh_issues.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    #!/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