From a0e533f249b3243f42d15e7c9cc46bfd16a40504 Mon Sep 17 00:00:00 2001 From: mjgaughan Date: Fri, 27 Oct 2023 12:25:33 -0500 Subject: [PATCH] implemented timecheck for gsql --- gh_gsql_req.py | 18 +++++++++++++++--- main.py | 7 +++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/gh_gsql_req.py b/gh_gsql_req.py index 1ab84f0..34aa3ca 100644 --- a/gh_gsql_req.py +++ b/gh_gsql_req.py @@ -5,12 +5,14 @@ import os key = os.environ.get('KKEXKEY') -def main(vcs): +def main(vcs, early_cutoff): + gsql_dict = {} 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 + gsql_dict["original_returned_content"] = get_discussion_gql(repo_owner, repo_name) + 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): url = "https://api.github.com/graphql" @@ -61,6 +63,16 @@ def get_discussion_gql(repo_owner, repo_name): print(r.content) 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__": get_discussion_gql() diff --git a/main.py b/main.py index 81b7547..17f08e9 100644 --- a/main.py +++ b/main.py @@ -9,7 +9,7 @@ import gh_gsql_req as ghs 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 - early_cutoff = dt.datetime(2023,6, 17) + early_cutoff = dt.datetime(2023,10, 11) print("Earliest date examined: " + str(early_cutoff)) #placeholder for now 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']) 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) + ghs_obj = ghs.main(vcs_path, early_cutoff) + print(ghs_obj["time_cleaned_comm"]) except yaml.YAMLOError as err: print(err)