almost done w gsql implementation
This commit is contained in:
		
							parent
							
								
									7d0a0866c7
								
							
						
					
					
						commit
						acdf656552
					
				
							
								
								
									
										77
									
								
								gh_gsql_req.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										77
									
								
								gh_gsql_req.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,77 @@ | |||||||
|  | import requests | ||||||
|  | import datetime as dt | ||||||
|  | import json | ||||||
|  | import os | ||||||
|  | 
 | ||||||
|  | key = os.environ.get('KKEXKEY') | ||||||
|  | 
 | ||||||
|  | def main(vcs): | ||||||
|  |     vcs_list = vcs[0].split('/') | ||||||
|  |     repo_name = '"' + vcs_list[-1] + '"' | ||||||
|  |     repo_owner = '"' + vcs_list[-2] + '"' | ||||||
|  |     returned_content = get_discussion_gql(repo_owner, repo_name) | ||||||
|  |     return returned_content | ||||||
|  | 
 | ||||||
|  | def get_discussion_gql(repo_owner, repo_name): | ||||||
|  |     url = "https://api.github.com/graphql" | ||||||
|  |     data_string = (""" | ||||||
|  |     query { | ||||||
|  |         repository(owner: """ + repo_owner + """, name: """ + repo_name + """) { | ||||||
|  |         discussions(first: 3) { | ||||||
|  |             # type: DiscussionConnection | ||||||
|  |             totalCount # Int! | ||||||
|  |      | ||||||
|  |             edges { | ||||||
|  |             # type: DiscussionEdge | ||||||
|  |             cursor | ||||||
|  |             node { | ||||||
|  |                 # type: Discussion | ||||||
|  |                 id | ||||||
|  |                 title # String! | ||||||
|  |                 bodyText # String!  | ||||||
|  |                 createdViaEmail # Boolean! | ||||||
|  |                 createdAt # DateTime! | ||||||
|  |                 answer { | ||||||
|  |                     #type: DiscussionComment | ||||||
|  |                     bodyText # String! | ||||||
|  |                 }  | ||||||
|  |                 comments(first: 10){ | ||||||
|  |                     # type: DiscussionCommentConnection | ||||||
|  |                     totalCount # Int! | ||||||
|  |                     edges { | ||||||
|  |                         # type: DiscussionCommentEdge | ||||||
|  |                         node { | ||||||
|  |                             # type: DiscussionComment | ||||||
|  |                             id | ||||||
|  |                             bodyText # String!  | ||||||
|  |                         } | ||||||
|  |                      | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     """) | ||||||
|  |     data =  {"query" : data_string} | ||||||
|  |     data_json = json.dumps(data) | ||||||
|  |     headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8', 'Authorization': 'bearer ' + key} | ||||||
|  |     r = requests.post(url=url, data=data_json, headers=headers) | ||||||
|  |     print(r.content) | ||||||
|  |     return r | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | if __name__ == "__main__": | ||||||
|  |     get_discussion_gql() | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | # stashed info about page cursors  | ||||||
|  | '''            pageInfo { | ||||||
|  |             # type: PageInfo (from the public schema) | ||||||
|  |             startCursor | ||||||
|  |             endCursor | ||||||
|  |             hasNextPage | ||||||
|  |             hasPreviousPage | ||||||
|  |             } | ||||||
|  | ''' | ||||||
| @ -35,36 +35,3 @@ def parse_milestones(milestones, earliest_date): | |||||||
|     return count_of_milestones |     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 |  | ||||||
| ''' |  | ||||||
|  | |||||||
							
								
								
									
										8
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								main.py
									
									
									
									
									
								
							| @ -1,9 +1,11 @@ | |||||||
| import perceval | import perceval | ||||||
| import os | import os | ||||||
| import yaml | import yaml | ||||||
|  | import datetime as dt | ||||||
|  | 
 | ||||||
| import perceval_tasks as pt | import perceval_tasks as pt | ||||||
| import github_api_req as gha | import github_api_req as gha | ||||||
| import datetime as dt | import gh_gsql_req as ghs | ||||||
| 
 | 
 | ||||||
| def main(): | def main(): | ||||||
|     # we should discuss whether we're using the 93 day window that seems to be widely used or if we want a longer window |     # we should discuss whether we're using the 93 day window that seems to be widely used or if we want a longer window | ||||||
| @ -32,6 +34,10 @@ def main(): | |||||||
|             #new mmt formality score |             #new mmt formality score | ||||||
|             new_formality = compute_formality_score(new_mmt, gha_obj['milestone_count'], perceval_obj['age_of_project']) |             new_formality = compute_formality_score(new_mmt, gha_obj['milestone_count'], perceval_obj['age_of_project']) | ||||||
|             print(new_formality) |             print(new_formality) | ||||||
|  |             # testing out beneath: | ||||||
|  |             # TODO: incorporate early cutoff to this, probably in a cleaning function | ||||||
|  |             ghs_obj = ghs.main(vcs_path) | ||||||
|  |             print(ghs_obj) | ||||||
|         except yaml.YAMLOError as err: |         except yaml.YAMLOError as err: | ||||||
|             print(err) |             print(err) | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user