Skip to content

Commit b03da5a

Browse files
authored
Merge pull request #33 from VectorInstitute/fix_github_case_bug
Fix bug with case sensitivity tied to github handles
2 parents 39aff40 + b769ed9 commit b03da5a

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

services/token-service/main.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def get_github_handle_from_workspace_sa(service_account_email: str) -> str | Non
119119
Returns
120120
-------
121121
str | None
122-
GitHub handle if found, None otherwise.
122+
GitHub handle (normalized to lowercase) if found, None otherwise.
123123
"""
124124
# For now, require github_handle to be passed in request body
125125
# In production, you could map this via metadata or workspace labels
@@ -129,16 +129,22 @@ def get_github_handle_from_workspace_sa(service_account_email: str) -> str | Non
129129
logger.warning("github_handle not provided in request")
130130
return None
131131

132+
# Normalize GitHub handle to lowercase for case-insensitive matching
133+
# GitHub handles are case-insensitive but case-preserving
134+
github_handle_normalized = github_handle.lower()
135+
132136
# Verify this participant exists in Firestore
133137
try:
134-
doc_ref = db.collection("participants").document(github_handle)
138+
doc_ref = db.collection("participants").document(github_handle_normalized)
135139
doc = doc_ref.get()
136140

137141
if not doc.exists:
138-
logger.warning(f"Participant {github_handle} not found in Firestore")
142+
logger.warning(
143+
f"Participant {github_handle_normalized} not found in Firestore"
144+
)
139145
return None
140146

141-
return github_handle
147+
return github_handle_normalized
142148

143149
except Exception as e:
144150
logger.error(f"Failed to verify participant: {e}")

src/aieng_platform_onboard/utils.py

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ def get_console() -> Console:
3838
return console
3939

4040

41+
def normalize_github_handle(github_handle: str) -> str:
42+
"""
43+
Normalize GitHub handle to lowercase for case-insensitive matching.
44+
45+
GitHub handles are case-insensitive but case-preserving. This function
46+
ensures consistent lookups in Firestore by normalizing to lowercase.
47+
48+
Parameters
49+
----------
50+
github_handle : str
51+
GitHub handle in any case.
52+
53+
Returns
54+
-------
55+
str
56+
Normalized (lowercase) GitHub handle.
57+
"""
58+
return github_handle.lower()
59+
60+
4161
def get_github_user() -> str | None:
4262
"""
4363
Get GitHub username from environment variable.
@@ -145,7 +165,8 @@ def fetch_token_from_service( # noqa: PLR0911
145165
"Authorization": f"Bearer {id_token}",
146166
"Content-Type": "application/json",
147167
}
148-
payload = {"github_handle": github_handle}
168+
# Normalize GitHub handle for case-insensitive matching
169+
payload = {"github_handle": normalize_github_handle(github_handle)}
149170

150171
response = requests.post(url, json=payload, headers=headers, timeout=30)
151172

@@ -292,7 +313,9 @@ def get_participant_data(
292313
Participant data or None if not found.
293314
"""
294315
try:
295-
doc_ref = db.collection("participants").document(github_handle)
316+
# Normalize GitHub handle for case-insensitive matching
317+
github_handle_normalized = normalize_github_handle(github_handle)
318+
doc_ref = db.collection("participants").document(github_handle_normalized)
296319
doc = doc_ref.get()
297320

298321
if not doc.exists:
@@ -548,7 +571,9 @@ def check_onboarded_status(
548571
Tuple of (success, is_onboarded).
549572
"""
550573
try:
551-
doc_ref = db.collection("participants").document(github_handle)
574+
# Normalize GitHub handle for case-insensitive matching
575+
github_handle_normalized = normalize_github_handle(github_handle)
576+
doc_ref = db.collection("participants").document(github_handle_normalized)
552577
doc = doc_ref.get()
553578

554579
if not doc.exists:
@@ -633,7 +658,9 @@ def update_onboarded_status(
633658
Tuple of (success, error_message).
634659
"""
635660
try:
636-
doc_ref = db.collection("participants").document(github_handle)
661+
# Normalize GitHub handle for case-insensitive matching
662+
github_handle_normalized = normalize_github_handle(github_handle)
663+
doc_ref = db.collection("participants").document(github_handle_normalized)
637664
doc_ref.update(
638665
{
639666
"onboarded": True,

0 commit comments

Comments
 (0)