diff --git a/get-pdfs-of-issues.py b/get-pdfs-of-issues.py index 93de548..e2da7dd 100755 --- a/get-pdfs-of-issues.py +++ b/get-pdfs-of-issues.py @@ -17,6 +17,7 @@ import subprocess import sys import tempfile +import urllib from github import standard_headers, get_issues @@ -91,7 +92,10 @@ def replace_images(md): return re.sub(r'\!\[(.*?)\]\((.*?)\)', replace_image, md) -def main(repo): +def main(repo, milestone, label, no_comments): + milestone_url = "" + if milestone: + milestone_url = 'https://github.com/{0}/milestones/{1}'.format(repo, urllib.quote(milestone)) for number, title, body, issue in get_issues(repo): @@ -106,6 +110,19 @@ def main(repo): if 'pull_request' in issue and issue['pull_request']['html_url']: continue + if milestone_url: + if not issue['milestone'] or issue['milestone']['html_url'] != milestone_url: + continue + + if label: + found = False + for assigned_label in issue['labels']: + if assigned_label['name'] == label: + found = True + break + if not found: + continue + print "Doing issue", number, title with open(md_filename, 'w') as f: @@ -117,7 +134,7 @@ def main(repo): body = body.encode('utf-8') f.write(body) f.write("\n\n") - if issue['comments'] > 0: + if not no_comments and issue['comments'] > 0: comments_request = requests.get(issue['comments_url'], headers=standard_headers) for comment in comments_request.json(): @@ -148,6 +165,15 @@ def main(repo): parser.add_option("-t", "--test", action="store_true", dest="test", default=False, help="Run doctests") +parser.add_option("-m", "--milestone", + metavar="MILESTONE", dest="milestone", default="", + help="Only issues with this milestone") +parser.add_option("-l", "--label", + metavar="LABEL", dest="label", default="", + help="Only issues with this label") +parser.add_option("-n", "--no-comments", + action="store_true", dest="no_comments", default=False, + help="Exclude comments from output") (options, args) = parser.parse_args() @@ -157,4 +183,4 @@ def main(repo): if len(args) != 1: parser.print_help() else: - main(args[0]) + main(args[0], options.milestone, options.label, options.no_comments)