Get all email addresses associated with the github profile. Args: oauth_token (str): The Github OAuth2 token to use for authentication. Returns: list of str: All of the user's associated email from github.
(oauth_token, username)
| 297 | |
| 298 | |
| 299 | def get_github_event_emails(oauth_token, username): |
| 300 | """Get all email addresses associated with the github profile. |
| 301 | |
| 302 | Args: |
| 303 | oauth_token (str): The Github OAuth2 token to use for authentication. |
| 304 | |
| 305 | Returns: |
| 306 | list of str: All of the user's associated email from github. |
| 307 | |
| 308 | """ |
| 309 | emails = [] |
| 310 | headers = JSON_HEADER |
| 311 | if oauth_token: |
| 312 | headers = dict({'Authorization': f'token {oauth_token}'}, **JSON_HEADER) |
| 313 | response = requests.get(f'https://api.github.com/users/{username}/events/public', headers=headers) |
| 314 | |
| 315 | userinfo = get_user(username) |
| 316 | user_name = userinfo.get('name', '') |
| 317 | print(user_name) |
| 318 | |
| 319 | if response.status_code == 200: |
| 320 | events = response.json() |
| 321 | for event in events: |
| 322 | payload = event.get('payload', {}) |
| 323 | for commit in payload.get('commits', []): |
| 324 | author = commit.get('author', {}) |
| 325 | email = author.get('email', {}) |
| 326 | name = author.get('name', {}) |
| 327 | if name and username and user_name: |
| 328 | append_email = name.lower() == username.lower() or name.lower() == user_name.lower() \ |
| 329 | and email and 'noreply.github.com' not in email |
| 330 | if append_email: |
| 331 | emails.append(email) |
| 332 | |
| 333 | return set(emails) |
| 334 | |
| 335 | |
| 336 | def get_github_emails(oauth_token): |
no test coverage detected