@@ -138,10 +138,16 @@ func (s *Service) SlackHandle(ctx context.Context, githubUsername, organization,
138138// Extracted from SlackHandle to work with singleflight pattern.
139139func (s * Service ) doLookup (ctx context.Context , githubUsername , organization , domain string ) (string , error ) {
140140 // Get emails for GitHub user with organization context
141+ slog .Info ("starting email lookup for GitHub user" ,
142+ "github_user" , githubUsername ,
143+ "organization" , organization ,
144+ "domain" , domain )
145+
141146 result , err := s .githubLookup .Lookup (ctx , githubUsername , organization )
142147 if err != nil {
143148 slog .Warn ("failed to get emails for GitHub user" ,
144149 "github_user" , githubUsername ,
150+ "organization" , organization ,
145151 "error" , err )
146152 return "" , err
147153 }
@@ -154,10 +160,17 @@ func (s *Service) doLookup(ctx context.Context, githubUsername, organization, do
154160 emails [i ] = addr .Email
155161 }
156162
157- slog .Debug ("found emails for GitHub user" ,
163+ slog .Info ("found emails for GitHub user via lookup " ,
158164 "github_user" , githubUsername ,
159165 "email_count" , len (emails ),
160- "emails" , emails )
166+ "emails" , emails ,
167+ "methods" , func () []string {
168+ methods := make ([]string , len (result .Addresses ))
169+ for i , addr := range result .Addresses {
170+ methods [i ] = addr .Methods [0 ] // Show first method
171+ }
172+ return methods
173+ }())
161174
162175 // Try finding Slack matches with all emails first
163176 matches := s .findSlackMatches (ctx , githubUsername , emails )
@@ -208,28 +221,38 @@ func (s *Service) doLookup(ctx context.Context, githubUsername, organization, do
208221 }
209222 }
210223 // Finally, try intelligent guessing
211- slog .Debug ( "trying intelligent email guessing" ,
224+ slog .Info ( "starting intelligent email guessing" ,
212225 "github_user" , githubUsername ,
213- "domain" , domain )
226+ "organization" , organization ,
227+ "domain" , domain ,
228+ "found_addresses_count" , len (result .Addresses ))
214229
215230 guessResult , err := s .githubLookup .Guess (ctx , githubUsername , organization , ghmailto.GuessOptions {
216231 Domain : domain ,
217232 })
218233 if err != nil {
219234 slog .Warn ("email guessing failed" ,
220235 "github_user" , githubUsername ,
236+ "organization" , organization ,
221237 "domain" , domain ,
222238 "error" , err )
223239 } else if len (guessResult .Guesses ) > 0 {
224240 guessedEmails := make ([]string , len (guessResult .Guesses ))
241+ confidences := make ([]int , len (guessResult .Guesses ))
242+ patterns := make ([]string , len (guessResult .Guesses ))
225243 for i , addr := range guessResult .Guesses {
226244 guessedEmails [i ] = addr .Email
245+ confidences [i ] = addr .Confidence
246+ patterns [i ] = addr .Pattern
227247 }
228248
229- slog .Debug ("generated email guesses" ,
249+ slog .Info ("generated email guesses for Slack lookup " ,
230250 "github_user" , githubUsername ,
231251 "domain" , domain ,
232- "guesses" , guessedEmails )
252+ "guess_count" , len (guessedEmails ),
253+ "guesses" , guessedEmails ,
254+ "confidences" , confidences ,
255+ "patterns" , patterns )
233256
234257 matches := s .findSlackMatches (ctx , githubUsername , guessedEmails )
235258 if len (matches ) > 0 {
@@ -243,13 +266,25 @@ func (s *Service) doLookup(ctx context.Context, githubUsername, organization, do
243266 s .cacheMapping (bestMatch )
244267 return bestMatch .SlackUserID , nil
245268 }
269+ slog .Warn ("email guesses generated but no Slack matches found" ,
270+ "github_user" , githubUsername ,
271+ "domain" , domain ,
272+ "guesses_tried" , len (guessedEmails ),
273+ "guesses" , guessedEmails )
274+ } else {
275+ slog .Warn ("email guessing completed but no guesses generated" ,
276+ "github_user" , githubUsername ,
277+ "domain" , domain )
246278 }
247279 }
248280
249281 // No matches found through any method
250- slog .Info ("no Slack mapping found for GitHub user" ,
282+ slog .Warn ("no Slack mapping found for GitHub user after exhausting all methods " ,
251283 "github_user" , githubUsername ,
284+ "organization" , organization ,
285+ "domain" , domain ,
252286 "tried_direct_emails" , len (emails ) > 0 ,
287+ "direct_emails_tried" , emails ,
253288 "tried_domain_filtering" , domain != "" ,
254289 "tried_guessing" , domain != "" )
255290
@@ -387,15 +422,31 @@ func (s *Service) cacheMapping(mapping *UserMapping) {
387422func (s * Service ) findSlackMatches (ctx context.Context , githubUsername string , emails []string ) []* UserMapping {
388423 var matches []* UserMapping
389424
425+ slog .Info ("starting Slack user lookup phase" ,
426+ "github_user" , githubUsername ,
427+ "email_count" , len (emails ),
428+ "emails" , emails )
429+
390430 // Search for each email in Slack user directory
391- for _ , email := range emails {
431+ for i , email := range emails {
392432 // Normalize email to lowercase for consistent matching
393433 normalizedEmail := strings .ToLower (email )
434+ slog .Info ("attempting Slack API lookup" ,
435+ "github_user" , githubUsername ,
436+ "attempt" , i + 1 ,
437+ "of" , len (emails ),
438+ "original_email" , email ,
439+ "normalized_email" , normalizedEmail )
440+
394441 user , err := s .slackClient .GetUserByEmailContext (ctx , normalizedEmail )
395442 if err != nil {
396- slog .Debug ("no Slack user found for email" ,
443+ // Log detailed error info to help debug Slack API issues
444+ slog .Warn ("Slack API lookup failed for email" ,
445+ "github_user" , githubUsername ,
397446 "email" , email ,
398- "error" , err )
447+ "normalized_email" , normalizedEmail ,
448+ "error_type" , fmt .Sprintf ("%T" , err ),
449+ "error_message" , err .Error ())
399450 continue
400451 }
401452
@@ -420,12 +471,20 @@ func (s *Service) findSlackMatches(ctx context.Context, githubUsername string, e
420471
421472 matches = append (matches , mapping )
422473
423- slog .Debug ("found Slack user match" ,
474+ slog .Info ("found Slack user match" ,
475+ "github_user" , githubUsername ,
424476 "email" , email ,
425- "slack_user" , user .Name ,
426- "confidence" , confidence )
477+ "slack_user_id" , user .ID ,
478+ "slack_user_name" , user .Name ,
479+ "confidence" , confidence ,
480+ "is_primary_email" , user .Profile .Email == email )
427481 }
428482
483+ slog .Info ("Slack user lookup phase complete" ,
484+ "github_user" , githubUsername ,
485+ "emails_tried" , len (emails ),
486+ "matches_found" , len (matches ))
487+
429488 return matches
430489}
431490
0 commit comments