Last active
March 2, 2017 18:11
-
-
Save djosephsen/23d55c1ca9a1285d03d8ff573d7d3e03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __get_gh_repos(teamname): | |
''' | |
looks up team ID from the organization then returns a list of repos | |
for which that team are collaborators | |
''' | |
params = '' | |
base_url = 'https://api.github.com/' | |
headers = { 'Accept' :'application/vnd.github.v3+json', "Content-type" : "application/json", \ | |
'User-Agent' : '[email protected]', 'Authorization': 'token ' + app.config['GH_API_TOKEN'] } | |
req = requests.get(base_url + 'orgs/librato/teams', auth=(app.config['GH_API_TOKEN'], 'x-oauth-basic')).text | |
teams = json.loads(req) | |
teamid = '' | |
for team in teams: | |
if team['name'] == teamname: | |
teamid = team['id'] | |
req = __gh_request('get', 'teams/{}/repos'.format(teamid), params) | |
req = requests.get(base_url + 'teams/{}/repos', auth=(app.config['GH_API_TOKEN'], 'x-oauth-basic')).text | |
repos = json.loads(req) | |
team_repos = [] | |
for repo in repos: | |
team_repos.append(repo['name']) | |
return team_repos | |
def get_gh_PRs(repo): | |
# TODO move 'librato' to config param | |
params = { 'state': 'open', 'sort': 'created', 'direction': 'asc' } | |
base_url = 'https://api.github.com/' | |
headers = { 'Accept' :'application/vnd.github.v3+json', "Content-type" : "application/json", \ | |
'User-Agent' : '[email protected]', 'Authorization': 'token ' + app.config['GH_API_TOKEN'] } | |
req = requests.get(base_url + 'repos/librato/{}/pulls'.format(repo)', auth=(app.config['GH_API_TOKEN'], 'x-oauth-basic')).text | |
repodict = {} | |
repolist = [] | |
if len(req) > 2: | |
pull_reqs = json.loads(req) | |
for pr in pull_reqs: | |
# the url returned is actually for the API, fragile but convert to web so it's clickable | |
# might be a way to do this in api | |
url = re.sub('api\.','', pr['url']) | |
url = re.sub('repos/','', url) | |
url = re.sub('pulls','pull', url) | |
repodata = " {} - {} - {}".format(pr['created_at'].split('T')[0], pr['title'].encode('utf-8'), url) | |
repolist.append(repodata) | |
repodict[repo] = repolist | |
return repodict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment