implemented timecheck for gsql

This commit is contained in:
mjgaughan 2023-10-27 12:25:33 -05:00
parent acdf656552
commit a0e533f249
2 changed files with 18 additions and 7 deletions

View File

@ -5,12 +5,14 @@ import os
key = os.environ.get('KKEXKEY') key = os.environ.get('KKEXKEY')
def main(vcs): def main(vcs, early_cutoff):
gsql_dict = {}
vcs_list = vcs[0].split('/') vcs_list = vcs[0].split('/')
repo_name = '"' + vcs_list[-1] + '"' repo_name = '"' + vcs_list[-1] + '"'
repo_owner = '"' + vcs_list[-2] + '"' repo_owner = '"' + vcs_list[-2] + '"'
returned_content = get_discussion_gql(repo_owner, repo_name) gsql_dict["original_returned_content"] = get_discussion_gql(repo_owner, repo_name)
return returned_content gsql_dict["time_cleaned_comm"] = within_time(gsql_dict["original_returned_content"].content, early_cutoff)
return gsql_dict
def get_discussion_gql(repo_owner, repo_name): def get_discussion_gql(repo_owner, repo_name):
url = "https://api.github.com/graphql" url = "https://api.github.com/graphql"
@ -61,6 +63,16 @@ def get_discussion_gql(repo_owner, repo_name):
print(r.content) print(r.content)
return r return r
def within_time(comment_content, early_cutoff):
list_of_comments = json.loads(comment_content)["data"]["repository"]["discussions"]["edges"]
valid_comments = []
for comment in list_of_comments:
if dt.datetime.fromisoformat(comment['node']['createdAt'][:-1]) < early_cutoff:
break
else:
valid_comments.append(comment)
return valid_comments
if __name__ == "__main__": if __name__ == "__main__":
get_discussion_gql() get_discussion_gql()

View File

@ -9,7 +9,7 @@ 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
early_cutoff = dt.datetime(2023,6, 17) early_cutoff = dt.datetime(2023,10, 11)
print("Earliest date examined: " + str(early_cutoff)) print("Earliest date examined: " + str(early_cutoff))
#placeholder for now #placeholder for now
manifest = '../kaylea_dissertation/lifecycle/package_metadata/jupyter-notebook_manifest.yaml' manifest = '../kaylea_dissertation/lifecycle/package_metadata/jupyter-notebook_manifest.yaml'
@ -35,9 +35,8 @@ def main():
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: # testing out beneath:
# TODO: incorporate early cutoff to this, probably in a cleaning function ghs_obj = ghs.main(vcs_path, early_cutoff)
ghs_obj = ghs.main(vcs_path) print(ghs_obj["time_cleaned_comm"])
print(ghs_obj)
except yaml.YAMLOError as err: except yaml.YAMLOError as err:
print(err) print(err)