24_deb_pkg_gov/github_api_req.py
2023-10-23 20:11:51 -05:00

54 lines
2.1 KiB
Python

import requests
import datetime as dt
def main(vcs, begin_date):
repo_uri=vcs[0]
gha_info = {}
#this is the entire list of Github 'milestones' grabbed from the API
gha_info['milestones'] = get_milestone_information(repo_uri)
#this is the count of milestones that occur after the cutoff date
gha_info['milestone_count'] = parse_milestones(gha_info['milestones'], begin_date)
#split_actors(repo_uri, actors_list)
return gha_info
#this simple API call has been working for now but may need to be updated as more information is desired
def get_milestone_information(repo_uri):
repo_uri_list = repo_uri.split('/')
print(repo_uri_list)
api_url = "https://api.github.com/repos/" + repo_uri_list[-2] + "/" + repo_uri_list[-1] + "/milestones"
response = requests.get(api_url)
response_dict = response.json()
return response_dict
def parse_milestones(milestones, earliest_date):
count_of_milestones = 0
for entry in milestones:
#if entry date is more recent than the earliest date we're looking at
# TODO: decide whether to use created_at or updated_at or closed_at
if dt.datetime.fromisoformat(entry['updated_at'][:-1]) > earliest_date:
count_of_milestones += 1
return count_of_milestones
'''
#using the github API to identify who is a collaborator on the project and who is just a contributor
def split_actors(repo_uri, actors_list):
call_sheet = {'collaborator' : [], 'contributor' : []}
repo_uri_list = repo_uri.split('/')
api_url = "https://api.github.com/repos/" + repo_uri_list[-2] + "/" + repo_uri_list[-1] + "/collaborators/"
for actor in actors_list[:2]:
actor_email = actor.split('<')[1][:-1]
print(actor_email)
actor_user = get_gh_un(actor_email)
response_dict = response.json()
print(response_dict)
#this function grabs the Github username from an associated email
def get_gh_un(email):
api_url = 'https://api.github.com/search/users?q=' + email
response = requests.get(api_url)
response_dict = response.json()
gh_username = response_dict['items'][0]['login']
return gh_username
'''