@@ -171,12 +171,31 @@ def fetch_user_details(token, id)
171
171
172
172
log ( "user_json:\n #{ user_json . to_yaml } " )
173
173
174
+ # Fetch email separately
175
+ email_json_url = "https://api.github.com/user/emails"
176
+ email_json_response = connection . run_request ( :get , email_json_url , nil , headers )
177
+
178
+ log <<-LOG
179
+ email_json request: GET #{ email_json_url }
180
+
181
+ request headers: #{ headers }
182
+
183
+ response status: #{ email_json_response . status }
184
+
185
+ response body:
186
+ #{ email_json_response . body }
187
+ LOG
188
+
189
+ if email_json_response . status == 200
190
+ email_json = JSON . parse ( email_json_response . body )
191
+ primary_email = email_json . find { |e | e [ "primary" ] } &.dig ( "email" )
192
+ end
174
193
result = { }
175
194
if user_json . present?
176
195
json_walk ( result , user_json , :user_id )
177
196
json_walk ( result , user_json , :username )
178
197
json_walk ( result , user_json , :name )
179
- json_walk ( result , user_json , :email )
198
+ result [ :email ] = primary_email if primary_email . present?
180
199
json_walk ( result , user_json , :email_verified )
181
200
json_walk ( result , user_json , :avatar )
182
201
0 commit comments