Skip to content

Commit

Permalink
[communitybridge#3884] Feature/PR Co-authors
Browse files Browse the repository at this point in the history
- Handled use case for getting co-author info in a given commit

Signed-off-by: Harold Wanyama <hwanyama@contractor.linuxfoundation.org>
  • Loading branch information
nickmango committed Apr 12, 2023
1 parent 3cd1c38 commit f4fbcf7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cla-backend/cla/models/github_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,20 @@ def get_pull_request_commit_authors(pull_request) -> List[UserCommitSummary]:
)
cla.log.debug(f'{fn} - PR: {pull_request.number}, {commit_author_summary}')
commit_authors.append(commit_author_summary)
# check for co-author details in the commit message:
# issue # 3884
co_authors = cla.utils.get_co_authors_from_commit(commit)
for co_author in co_authors:
co_author_summary = UserCommitSummary(
commit.sha,
None,
None,
co_author.name,
co_author.email,
False, False # default not authorized - will be evaluated and updated later
)
cla.log.debug(f'{fn} - PR: {pull_request.number}, {co_author_summary}')
commit_authors.append(co_author_summary)
except (GithubException, IncompletableObject) as ex:
cla.log.debug(f'Commit sha: {commit.sha} exception: {ex}')
try:
Expand Down
14 changes: 14 additions & 0 deletions cla-backend/cla/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import inspect
import json
import os
import re
import urllib.parse
import urllib.parse as urlparse
from datetime import datetime
Expand Down Expand Up @@ -1825,3 +1826,16 @@ def get_public_email(user):
"""
if len(user.get_all_user_emails()) > 0:
return next((email for email in user.get_all_user_emails() if "noreply.github.com" not in email), None)

def get_co_authors_from_commit(commit):
"""
Helper function to return co-authors from commit
"""
fn = "get_co_authors_from_commit"
co_authors = []
if commit.get("commit"):
commit_message = commit.get("commit").get("message")
cla.log.debug(f'{fn} - commit message: {commit_message}')
if commit_message:
co_authors = re.findall(r"Co-authored-by: (.*) <(.*)>", commit_message)
return co_authors

0 comments on commit f4fbcf7

Please sign in to comment.