Skip to content

Instantly share code, notes, and snippets.

@s1monw
Created April 25, 2014 21:11
Show Gist options
  • Save s1monw/11303406 to your computer and use it in GitHub Desktop.
Save s1monw/11303406 to your computer and use it in GitHub Desktop.
github_issues.py
# Licensed to Elasticsearch under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on
# an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import re
import tempfile
import shutil
import os
import datetime
import json
import time
import sys
import argparse
import hmac
import urllib
import fnmatch
import socket
import urllib.request
from http.client import HTTPConnection
from http.client import HTTPSConnection
def run_api_call(api):
conn = HTTPSConnection('api.github.com')
try:
conn.request('GET', '/repos/elasticsearch/elasticsearch/%s' % api, headers= {'User-Agent' : 'Elasticsearch tools'})
res = conn.getresponse()
if res.status == 200:
return json.loads(res.read().decode("utf-8"))
else:
raise RuntimeError('Failed call github [%s]' % res.read().decode("utf-8"))
except socket.error as e:
raise RuntimeError("Failed call github Exception: [%s]" % e)
#that is ok it might not be there yet
finally:
conn.close()
def tabelize_open_issues(lables, size):
issues = run_api_call('issues?state=open&labels=%s&per_page=%d' % (','.join(lables), size))
print('{0:5s} {2:10s} {1:53s} {3:20}'.format('id', 'title', 'assignee', 'labels'))
for issue in issues:
assignee = 'unassigned'
if issue['assignee']:
assignee = issue['assignee']['login']
lables = ','.join([x['name'] for x in issue['labels'] if not x['name'].startswith('v')])
if not lables:
lables = 'unlabled'
print('{0:4d} {2:10s} {1:53s} {3:20}'.format(issue['number'], prefix(issue['title'], 50), assignee, lables))
def prefix(string, chars):
if len(string) > chars:
chars = string[:chars].rfind(' ')
return string[:chars] + '...'
return string
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='')
parser.add_argument('--filter', '-f', nargs='+', dest='filter', help='')
parser.add_argument('--size', '-s', metavar='100', default=100,
help='The number of results to display, Default is [100]')
parser.set_defaults(filter=[])
args = parser.parse_args()
filter = args.filter
tabelize_open_issues(filter, args.size)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment