24_deb_pkg_gov/github_api_req.py

41 lines
1.5 KiB
Python
Raw Normal View History

2023-10-23 20:40:24 +00:00
import requests
import datetime as dt
2023-10-26 04:38:14 +00:00
import json
import os
key = os.environ.get('KKEXKEY')
2023-10-23 20:40:24 +00:00
def main(vcs, begin_date):
2023-10-24 01:11:51 +00:00
repo_uri=vcs[0]
2023-10-23 20:40:24 +00:00
gha_info = {}
#this is the entire list of Github 'milestones' grabbed from the API
2023-10-24 01:11:51 +00:00
gha_info['milestones'] = get_milestone_information(repo_uri)
2023-10-23 20:40:24 +00:00
#this is the count of milestones that occur after the cutoff date
gha_info['milestone_count'] = parse_milestones(gha_info['milestones'], begin_date)
2023-10-24 01:11:51 +00:00
#split_actors(repo_uri, actors_list)
2023-10-23 20:40:24 +00:00
return gha_info
2023-10-24 01:11:51 +00:00
2023-10-23 20:40:24 +00:00
#this simple API call has been working for now but may need to be updated as more information is desired
2023-10-24 01:11:51 +00:00
def get_milestone_information(repo_uri):
2023-10-23 20:40:24 +00:00
repo_uri_list = repo_uri.split('/')
2023-10-24 01:11:51 +00:00
print(repo_uri_list)
2023-10-23 20:40:24 +00:00
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
2023-10-24 01:11:51 +00:00
# TODO: decide whether to use created_at or updated_at or closed_at
2023-10-31 20:53:17 +00:00
# problem is that no one closes their milestones?! hardly seems representative?!
# making this a note here, as both Tamburri and van Meijel use 'closed_at'
if entry['updated_at'] != None:
if dt.datetime.fromisoformat(entry['updated_at'][:-1]) > earliest_date:
count_of_milestones += 1
2023-10-23 20:40:24 +00:00
return count_of_milestones
2023-10-26 04:38:14 +00:00