Skip to content

Issue filtering for get-pdfs-of-issues.py #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions get-pdfs-of-issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import subprocess
import sys
import tempfile
import urllib

from github import standard_headers, get_issues

Expand Down Expand Up @@ -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):

Expand All @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be reduced to:

            if not any(l['name'] == label for l in issue['labels']):
                continue

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:
Expand All @@ -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():
Expand Down Expand Up @@ -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()

Expand All @@ -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)