import requests import datetime as dt import json import os key = os.environ.get('KKEXKEY') 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 def get_discussion_gql(): #testing url = "https://api.github.com/graphql" x = {"query" : "query { repository(owner: 'beekeeper-studio', name: 'beekeeper-studio') { discussions(first: 10) {totalCount}}"} data = json.dumps(x) headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8', 'Authorization': 'bearer ' + key} r = requests.post(url=url, data=data, headers=headers) print(r.content) print(r.json()) if __name__ == "__main__": get_discussion_gql() ''' #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 '''