From 18fff929c42141da1de62566a54b58e10a333318 Mon Sep 17 00:00:00 2001 From: Greg V Date: Mon, 16 Sep 2024 19:42:29 -0700 Subject: [PATCH] [Profile] Github stats update --- common/utils/firebase.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/common/utils/firebase.py b/common/utils/firebase.py index 006e5fb..2490252 100644 --- a/common/utils/firebase.py +++ b/common/utils/firebase.py @@ -92,17 +92,27 @@ def get_github_contributions_for_user(login): logger.info(f"Getting github contributions for user {login}") db = get_db() # this connects to our Firestore database - docs = db.collection('github_contributors').where("login", "==", login).stream() - - logger.info(f"Found {docs} contributions for user {login}") + + # Use a collection group query to search across all contributor subcollections + contributors_ref = db.collection_group('github_contributors').where("login", "==", login) + + docs = contributors_ref.stream() github_history = [] for doc in docs: - adict = doc.to_dict() - adict["id"] = doc.id - github_history.append(adict) - - return github_history + contribution = doc.to_dict() + # Add document ID + contribution["id"] = doc.id + # Add organization and repository information + repo_ref = doc.reference.parent.parent + org_ref = repo_ref.parent.parent + contribution["repo_name"] = repo_ref.id + contribution["org_name"] = org_ref.id + github_history.append(contribution) + + logger.info(f"Found {len(github_history)} contributions for user {login}") + + return github_history