@@ -101,8 +101,8 @@ def clear_caches():
101101 cla .log .info (f"{ fn } - cleared github_user_cache" )
102102 return {"status" : "OK" }
103103 except Exception as e :
104- cla .log .error (f"{ fn } - error clearing caches: { e } " )
105- return {"status" : f "Error clearing caches: { e } " }
104+ cla .log .error (f"{ fn } - error clearing caches" , exc_info = True )
105+ return {"status" : "Error clearing caches" }
106106
107107@dataclass
108108class CommitLite :
@@ -213,11 +213,11 @@ def user_from_session(self, request, get_redirect_url):
213213 fn = "github_models.user_from_session"
214214 cla .log .debug (f"{ fn } - loading session from request" )
215215 session = self ._get_request_session (request )
216- cla .log .debug (f"{ fn } - session loaded (keys= { list ( session . keys ()) } ) " )
216+ cla .log .debug (f"{ fn } - session loaded" )
217217
218218 # We can already have token in the session
219219 if "github_oauth2_token" in session :
220- cla .log .debug (f"{ fn } - using existing session GitHub OAuth2 token " )
220+ cla .log .debug (f"{ fn } - using existing session GitHub OAuth2 authentication " )
221221 user = self .get_or_create_user (request )
222222 if user is None :
223223 cla .log .debug (f"{ fn } - cannot find user, returning HTTP 404 status" )
@@ -226,7 +226,7 @@ def user_from_session(self, request, get_redirect_url):
226226 return user
227227
228228 authorization_url , csrf_token = self .get_authorization_url_and_state (None , None , None , ["user:email" ], state = 'user-from-session' )
229- cla .log .debug (f"{ fn } - obtained GitHub OAuth2 state from authorization - storing CSRF token in the session... " )
229+ cla .log .debug (f"{ fn } - obtained GitHub OAuth2 state from authorization - storing state in the session" )
230230 session ["github_oauth2_state" ] = csrf_token
231231 cla .log .debug (f"{ fn } - redirecting user to GitHub OAuth2 authorization URL" )
232232 # We must redirect to GitHub OAuth app for authentication, it will return you to /v2/github/installation which will handle returning user data
@@ -252,7 +252,7 @@ def sign_request(self, installation_id, github_repository_id, change_request_id,
252252 # Not sure if we need a different token for each installation ID...
253253 cla .log .debug (f"{ fn } - Loading session from request" )
254254 session = self ._get_request_session (request )
255- cla .log .debug (f"{ fn } - Adding github details to session: { list ( session . keys ()) } which is type: { type ( session ) } ... " )
255+ cla .log .debug (f"{ fn } - Adding github details to session" )
256256 session ["github_installation_id" ] = installation_id
257257 session ["github_repository_id" ] = github_repository_id
258258 session ["github_change_request_id" ] = change_request_id
@@ -264,14 +264,14 @@ def sign_request(self, installation_id, github_repository_id, change_request_id,
264264 cla .log .debug (f'{ fn } - stored origin url in session' )
265265
266266 if "github_oauth2_token" in session :
267- cla .log .debug (f"{ fn } - Using existing session GitHub OAuth2 token " )
267+ cla .log .debug (f"{ fn } - Using existing session GitHub OAuth2 authentication " )
268268 return self .redirect_to_console (installation_id , github_repository_id , change_request_id , origin_url , request )
269269 else :
270270 cla .log .debug (f"{ fn } - No existing GitHub OAuth2 token - building authorization url and state" )
271271 authorization_url , state = self .get_authorization_url_and_state (
272272 installation_id , github_repository_id , int (change_request_id ), ["user:email" ]
273273 )
274- cla .log .debug (f"{ fn } - Obtained GitHub OAuth2 state from authorization - storing state in the session... " )
274+ cla .log .debug (f"{ fn } - Obtained GitHub OAuth2 state from authorization - storing state in the session" )
275275 session ["github_oauth2_state" ] = state
276276 cla .log .debug (f"{ fn } - redirecting user to GitHub OAuth2 authorization URL" )
277277 raise falcon .HTTPFound (authorization_url )
@@ -307,7 +307,7 @@ def _get_request_session(self, request) -> dict: # pylint: disable=no-self-use
307307 session = {}
308308 request .context ["session" ] = session
309309
310- cla .log .debug (f"{ fn } - loaded session (keys= { list ( session . keys ()) } ) " )
310+ cla .log .debug (f"{ fn } - loaded session" )
311311
312312 return session
313313
@@ -375,7 +375,7 @@ def oauth2_redirect(self, state, code, request): # pylint: disable=too-many-arg
375375 padded_state = state + "=" * (- len (state ) % 4 )
376376 state_data = json .loads (base64 .urlsafe_b64decode (padded_state .encode ()).decode ())
377377 except (ValueError , json .JSONDecodeError , binascii .Error ) as err :
378- cla .log .warning (f"{ fn } - failed to decode state, error: { err } " )
378+ cla .log .warning (f"{ fn } - failed to decode state, error occurred " )
379379 raise falcon .HTTPBadRequest ("Invalid OAuth2 state" , "Invalid OAuth2 state" )
380380
381381 state_token = state_data .get ("csrf" )
@@ -398,9 +398,9 @@ def oauth2_redirect(self, state, code, request): # pylint: disable=too-many-arg
398398 try :
399399 token = self ._fetch_token (client_id , state , token_url , client_secret , code )
400400 except Exception as err :
401- cla .log .warning (f"{ fn } - GitHub OAuth2 error: { err } . Likely bad or expired code, returning HTTP 404 state ." )
402- raise falcon .HTTPBadRequest ("OAuth2 code is invalid or expired" )
403- cla .log .debug (f"{ fn } - oauth2 token received - storing token in session" )
401+ cla .log .warning (f"{ fn } - GitHub OAuth2 error. Likely bad or expired code, returning HTTP 400 status ." )
402+ raise falcon .HTTPBadRequest ("OAuth2 code is invalid or expired" , "OAuth2 code is invalid or expired" )
403+ cla .log .debug (f"{ fn } - oauth2 authentication received - storing in session" )
404404 session ["github_oauth2_token" ] = token
405405 user = self .get_or_create_user (request )
406406 if user is None :
@@ -421,7 +421,7 @@ def oauth2_redirect(self, state, code, request): # pylint: disable=too-many-arg
421421 client_secret = os .environ ["GH_OAUTH_SECRET" ]
422422 cla .log .debug (f"{ fn } - fetching oauth2 token from configured GitHub endpoint" )
423423 token = self ._fetch_token (client_id , state , token_url , client_secret , code )
424- cla .log .debug (f"{ fn } - oauth2 token received - storing token in session" )
424+ cla .log .debug (f"{ fn } - oauth2 authentication received - storing in session" )
425425 session ["github_oauth2_token" ] = token
426426 cla .log .debug (f"{ fn } - redirecting the user back to the contributor console" )
427427 return self .redirect_to_console (installation_id , github_repository_id , change_request_id , origin_url , request )
@@ -1049,7 +1049,7 @@ def update_change_request(self, installation_id, github_repository_id, change_re
10491049 pull_request_id = str (change_request_id ),
10501050 )
10511051 except Exception as e :
1052- cla .log .error (f"{ fn } - problem saving PR metadata for PR: { pull_request .number } , error: { e } " )
1052+ cla .log .error (f"{ fn } - problem saving PR metadata for PR: { pull_request .number } " )
10531053
10541054 # Find users who have signed and who have not signed.
10551055 signed = []
@@ -1073,7 +1073,7 @@ def update_change_request(self, installation_id, github_repository_id, change_re
10731073 try :
10741074 future .result ()
10751075 except Exception as e :
1076- cla .log .error (f"{ fn } - Exception in commit author thread for PR: { pull_request .number } , error: { e } " )
1076+ cla .log .error (f"{ fn } - Exception in commit author thread for PR: { pull_request .number } " )
10771077
10781078 # Skip allowlisted bots per org/repo GitHub login/email regexps
10791079 missing , allowlisted = self .skip_allowlisted_bots (github_org , repository .get_repository_name (), missing )
@@ -1431,9 +1431,9 @@ def get_or_create_user(self, request):
14311431 # Could not get GitHub user data - maybe user revoked CLA app permissions?
14321432 session = self ._get_request_session (request )
14331433
1434- del session [ "github_oauth2_state" ]
1435- del session [ "github_oauth2_token" ]
1436- cla .log .warning (f"{ fn } - Deleted OAuth2 session data - retrying token exchange next time" )
1434+ session . pop ( "github_oauth2_state" , None )
1435+ session . pop ( "github_oauth2_token" , None )
1436+ cla .log .warning (f"{ fn } - Deleted OAuth2 session data - retrying authentication exchange next time" )
14371437 raise falcon .HTTPError (
14381438 "400 Bad Request" , "github_oauth2_token" , "Token permissions have been rejected, please try again"
14391439 )
@@ -1520,16 +1520,16 @@ def get_user_data(self, session, client_id): # pylint: disable=no-self-use
15201520 fn = "cla.models.github_models.get_user_data"
15211521 token = session .get ("github_oauth2_token" )
15221522 if token is None :
1523- cla .log .error (f"{ fn } - unable to load github_oauth2_token from session (keys= { list ( session . keys ()) } ) " )
1523+ cla .log .error (f"{ fn } - unable to load github_oauth2_token from session" )
15241524 return {"error" : "could not get user data from session" }
15251525
15261526 oauth2 = OAuth2Session (client_id , token = token )
15271527 request = oauth2 .get ("https://api.github.com/user" )
15281528 github_user = request .json ()
15291529 cla .log .debug (f"{ fn } - GitHub user data: %s" , github_user )
15301530 if "message" in github_user :
1531- cla .log .error (f'{ fn } - Could not get user data with OAuth2 token: { github_user [ "message" ] } ' )
1532- return {"error" : "Could not get user data: %s" % github_user [ "message" ] }
1531+ cla .log .error (f'{ fn } - Could not get user data with OAuth2 authentication ' )
1532+ return {"error" : "Could not get user data" }
15331533 return github_user
15341534
15351535 def get_user_emails (self , session : dict , client_id : str ) -> Union [List [str ], dict ]: # pylint: disable=no-self-use
@@ -1589,13 +1589,14 @@ def _fetch_github_emails(self, session: dict, client_id: str) -> Union[List[dict
15891589 # as expected
15901590 token = session .get ("github_oauth2_token" )
15911591 if token is None :
1592- cla .log .warning (f"{ fn } - unable to load github_oauth2_token from the session - session is empty" )
1592+ cla .log .warning (f"{ fn } - unable to load authentication token from the session - session is empty" )
1593+ return {"error" : "Could not get user emails" }
15931594 oauth2 = OAuth2Session (client_id , token = token )
15941595 request = oauth2 .get ("https://api.github.com/user/emails" )
15951596 resp = request .json ()
15961597 if "message" in resp :
1597- cla .log .warning (f'{ fn } - could not get user emails with OAuth2 token: { resp [ "message" ] } ' )
1598- return {"error" : "Could not get user emails: %s" % resp [ "message" ] }
1598+ cla .log .warning (f'{ fn } - could not get user emails with OAuth2 authentication ' )
1599+ return {"error" : "Could not get user emails" }
15991600 return resp
16001601
16011602 def process_reopened_pull_request (self , data ):
@@ -2187,7 +2188,7 @@ def pygithub_graphql(g, query: str, variables: dict | None = None):
21872188 errs = data ["errors" ]
21882189 paths = [e .get ("path" ) for e in errs ]
21892190 msgs = [e .get ("message" ) for e in errs ]
2190- cla .log .error (f"GraphQL errors: { msgs } (paths= { paths } , all= { errs !r } ) " )
2191+ cla .log .error (f"GraphQL errors occurred " )
21912192 return None
21922193 return data .get ("data" )
21932194 except Exception as exc :
@@ -2535,7 +2536,7 @@ def get_co_author_commits(co_author, commit_sha, pr, installation_id) -> Tuple[U
25352536 cla .log .debug (f"{ fn } - Detected noreply GitHub email with ID: { id_str } , login: { login_str } " )
25362537 user = github .get_github_user_by_id (github_id , installation_id )
25372538 except Exception as ex :
2538- cla .log .warning (f"{ fn } - Error fetching user by ID { id_str } : { ex } " )
2539+ cla .log .warning (f"{ fn } - Error fetching user by ID { id_str } " )
25392540 user = None
25402541
25412542 # 2. Check for "username@users.noreply.github.com"
@@ -2547,7 +2548,7 @@ def get_co_author_commits(co_author, commit_sha, pr, installation_id) -> Tuple[U
25472548 cla .log .debug (f"{ fn } - Detected noreply GitHub email with login: { login_str } " )
25482549 user = github .get_github_user_by_login (login_str , installation_id )
25492550 except Exception as ex :
2550- cla .log .warning (f"{ fn } - Error fetching user by login { login_str } : { ex } " )
2551+ cla .log .warning (f"{ fn } - Error fetching user by login { login_str } " )
25512552 user = None
25522553
25532554 # 3. Try to find user by email via GitHub APIs
@@ -2584,7 +2585,7 @@ def get_co_author_commits(co_author, commit_sha, pr, installation_id) -> Tuple[U
25842585 try :
25852586 user = github .get_github_user_by_id (github_id , installation_id )
25862587 except Exception as ex :
2587- cla .log .warning (f"{ fn } - Error fetching user by ID { github_id } : { ex } " )
2588+ cla .log .warning (f"{ fn } - Error fetching user by ID { github_id } " )
25882589 user = None
25892590 except Exception as ex :
25902591 # user not found
0 commit comments