Skip to content

Instantly share code, notes, and snippets.

@max-arnold
Last active September 20, 2019 06:54
Show Gist options
  • Save max-arnold/d42bd4c239bca1735239381ff5d5bff7 to your computer and use it in GitHub Desktop.
Save max-arnold/d42bd4c239bca1735239381ff5d5bff7 to your computer and use it in GitHub Desktop.
Export Salt Cloud issues to XLSX
#!/usr/bin/env python3
import argparse
import json
import os
import re
import urllib.parse
import urllib.request
import xlsxwriter
BASE_URL = 'https://api.github.com/repos/saltstack/salt/issues'
ISSUE_FILTERS = [
{'state': 'open', 'labels': 'team-cloud', 'per_page': '100'},
{'state': 'open', 'labels': 'Salt-Cloud', 'per_page': '100'},
{'state': 'closed', 'labels': 'team-cloud,stale', 'per_page': '100'},
{'state': 'closed', 'labels': 'Salt-Cloud,stale', 'per_page': '100'},
]
def get_next_page_url(resp):
links = resp.headers.get('Link')
if not links:
return None
next = re.search('<([^>]+)>; rel="next"', links)
if next:
return next.group(1)
else:
return None
def fetch_issues(filters):
issues = []
url = BASE_URL + '?' + urllib.parse.urlencode(filters)
while url:
print(url)
req = urllib.request.Request(url)
with urllib.request.urlopen(req) as resp:
body = resp.read().decode('utf-8')
issues.extend(json.loads(body))
url = get_next_page_url(resp)
return issues
def fetch_issue_lists():
def sortkey(issue):
return (issue[1], int(os.path.basename(issue[0])))
issues = []
for filters in ISSUE_FILTERS:
issues.extend(fetch_issues(filters))
unique_issues = sorted(list(set([
(
i['html_url'],
i['state'],
i['title'],
'/'.join(sorted([l['name'] for l in i['labels']]))
)
for i in issues
])), key=sortkey, reverse=True)
return unique_issues
if __name__ == '__main__':
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
'--out',
type=str,
default='salt-cloud-issues.xlsx',
help='Name of the resulting xlsx file',
)
options = parser.parse_args()
issues = fetch_issue_lists()
workbook = xlsxwriter.Workbook(options.out)
worksheet = workbook.add_worksheet()
worksheet.write(0, 0, 'Issue')
worksheet.write(0, 1, 'Status')
worksheet.write(0, 2, 'Triage status')
worksheet.write(0, 3, 'Title')
worksheet.write(0, 4, 'Labels')
for i, issue in enumerate(issues):
worksheet.write(i + 1, 0, issue[0])
worksheet.write(i + 1, 1, issue[1])
worksheet.write(i + 1, 3, issue[2])
worksheet.write(i + 1, 4, issue[3])
workbook.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment