@@ -62,7 +62,6 @@ Please update your commit message(s) by doing |git commit --amend| and then |git
6262`
6363
6464const (
65- help = "https://help.github.com/en/github/committing-changes-to-your-project/why-are-my-commits-linked-to-the-wrong-user"
6665 unknown = "Unknown"
6766 failureState = "failure"
6867 successState = "success"
@@ -475,7 +474,7 @@ func (u UserCommitSummary) getUserInfo(tagUser bool) string {
475474 }
476475 }
477476
478- return strings .Replace (sb .String (), "/ $" , "" , - 1 )
477+ return strings .TrimSuffix (sb .String (), " / " )
479478}
480479
481480// SearchGithubUserByEmail searches for a GitHub user by email using the GitHub search API.
@@ -1599,14 +1598,17 @@ func assembleCLAComment(ctx context.Context, installationID, pullRequestID int,
15991598 return fmt .Sprintf ("%s<br >%s" , badge , commentBody )
16001599}
16011600
1601+ // getCommentBody mirrors the Python get_comment_body behavior.
1602+ //
1603+ //nolint:gocyclo // complexity is acceptable for now
16021604func getCommentBody (repositoryType , signURL string , signed , missing []* UserCommitSummary , anyMissing bool ) string {
16031605 f := logrus.Fields {
16041606 "functionName" : "github.github_repository.getCommentBody" ,
16051607 "repositoryType" : repositoryType ,
16061608 "signURL" : signURL ,
16071609 }
16081610 failed := ":x:"
1609- _success := ":white_check_mark:" // avoid shadowing success var elsewhere
1611+ success := ":white_check_mark:"
16101612
16111613 var committersComment strings.Builder
16121614 text := ""
@@ -1619,39 +1621,76 @@ func getCommentBody(repositoryType, signURL string, signed, missing []*UserCommi
16191621 committersComment .WriteString ("<ul>" )
16201622 }
16211623
1622- // --- Signed section (group by author label; list SHAs) ---
1624+ // ---------- Signed section (group by author) ------- ---
16231625 if numSigned > 0 {
1624- // Group commits by author label (no tagging for signed)
1625- committers := getAuthorInfoCommits (signed , false ) // map[string][]*UserCommitSummary
1626+ committers := make (map [string ][]* UserCommitSummary , numSigned )
1627+ for _ , ucs := range signed {
1628+ var authorInfo string
1629+ if ucs != nil && ucs .IsValid () {
1630+ authorInfo = ucs .getUserInfo (false )
1631+ } else {
1632+ authorInfo = unknown
1633+ }
1634+ committers [authorInfo ] = append (committers [authorInfo ], ucs )
1635+ }
1636+
1637+ // sort keys for stable output
1638+ keys := make ([]string , 0 , len (committers ))
1639+ for k := range committers {
1640+ keys = append (keys , k )
1641+ }
1642+ sort .Strings (keys )
16261643
1627- for authorInfo , summaries := range committers {
1628- // Build list of SHAs
1644+ for _ , authorInfo := range keys {
1645+ summaries := committers [ authorInfo ]
16291646 shas := make ([]string , 0 , len (summaries ))
16301647 for _ , s := range summaries {
1631- shas = append (shas , s .SHA )
1648+ if s != nil {
1649+ shas = append (shas , s .SHA )
1650+ }
16321651 }
1633- log .WithFields (f ).Infof ("SHAs for signed users: %v" , shas )
1652+ log .WithFields (f ).Debugf ("SHAs for signed users: %v" , shas )
16341653 committersComment .WriteString (
1635- fmt .Sprintf ("<li>%s %s (%s)</li>" , _success , authorInfo , strings .Join (shas , ", " )),
1654+ fmt .Sprintf ("<li>%s %s (%s)</li>" , success , authorInfo , strings .Join (shas , ", " )),
16361655 )
16371656 }
16381657 }
16391658
1640- // --- Missing section (group by author label; list SHAs; guidance) ---
1659+ // ---------- Missing section (group by author) ------- ---
16411660 if numMissing > 0 {
16421661 supportURL := "https://jira.linuxfoundation.org/servicedesk/customer/portal/4"
16431662 missingIDHelpURL := "https://linuxfoundation.atlassian.net/wiki/spaces/LP/pages/160923756/Missing+ID+on+Commit+but+I+have+an+agreement+on+file"
16441663 githubHelpURL := "https://help.github.com/en/github/committing-changes-to-your-project/why-are-my-commits-linked-to-the-wrong-user"
16451664
1646- // Tag users for missing (mentions)
1647- committers := getAuthorInfoCommits (missing , true ) // map[string][]*UserCommitSummary
1665+ committers := make (map [string ][]* UserCommitSummary , numMissing )
1666+ for _ , ucs := range missing {
1667+ var authorInfo string
1668+ if ucs != nil && ucs .IsValid () {
1669+ authorInfo = ucs .getUserInfo (true )
1670+ if strings .TrimSpace (authorInfo ) == "" {
1671+ authorInfo = unknown
1672+ }
1673+ } else {
1674+ authorInfo = unknown
1675+ }
1676+ committers [authorInfo ] = append (committers [authorInfo ], ucs )
1677+ }
1678+
1679+ // sort keys for stable output
1680+ keys := make ([]string , 0 , len (committers ))
1681+ for k := range committers {
1682+ keys = append (keys , k )
1683+ }
1684+ sort .Strings (keys )
16481685
1649- for authorInfo , summaries := range committers {
1650- // Unknown author branch
1686+ for _ , authorInfo := range keys {
1687+ summaries := committers [ authorInfo ]
16511688 if authorInfo == unknown {
16521689 shas := make ([]string , 0 , len (summaries ))
16531690 for _ , s := range summaries {
1654- shas = append (shas , s .SHA )
1691+ if s != nil {
1692+ shas = append (shas , s .SHA )
1693+ }
16551694 }
16561695 committersComment .WriteString (fmt .Sprintf (
16571696 "<li> %s The email address for the commit (%s) is not linked to the GitHub account, preventing the EasyCLA check. " +
@@ -1665,39 +1704,41 @@ func getCommentBody(repositoryType, signURL string, signed, missing []*UserCommi
16651704 continue
16661705 }
16671706
1668- // Check for users who are authorized but missing affiliation
16691707 missingAffiliations := make ([]* UserCommitSummary , 0 , len (summaries ))
16701708 for _ , s := range summaries {
1671- if ! s .Affiliated && s .Authorized {
1709+ if s != nil && ! s .Affiliated && s .Authorized {
16721710 missingAffiliations = append (missingAffiliations , s )
16731711 }
16741712 }
1675-
16761713 if len (missingAffiliations ) > 0 {
1677- // SHAs only for those missing affiliation
16781714 shas := make ([]string , 0 , len (missingAffiliations ))
16791715 for _ , s := range missingAffiliations {
1680- shas = append (shas , s .SHA )
1716+ if s != nil {
1717+ shas = append (shas , s .SHA )
1718+ }
16811719 }
1682- log .WithFields (f ).Infof ("SHAs for users with missing company affiliations: %v" , shas )
1720+ log .WithFields (f ).Debugf ("SHAs for users with missing company affiliations: %v" , shas )
16831721 committersComment .WriteString (fmt .Sprintf (
16841722 `<li>%s %s (%s). This user is authorized, but they must confirm their affiliation with their company. ` +
16851723 `Start the authorization process <a href='%s' target='_blank'> by clicking here</a>, ` +
16861724 `click "Corporate", select the appropriate company from the list, then confirm your affiliation on the page that appears. ` +
16871725 `For further assistance with EasyCLA, <a href='%s' target='_blank'>please submit a support request ticket</a>.</li>` ,
1688- failed , authorInfo , strings .Join (shas , ", " ), signURL , supportURL ,
1726+ failed , authorInfo , strings .Join (shas , ", " ),
1727+ signURL , supportURL ,
16891728 ))
16901729 } else {
1691- // Not authorized (list all SHAs)
16921730 shas := make ([]string , 0 , len (summaries ))
16931731 for _ , s := range summaries {
1694- shas = append (shas , s .SHA )
1732+ if s != nil {
1733+ shas = append (shas , s .SHA )
1734+ }
16951735 }
16961736 committersComment .WriteString (fmt .Sprintf (
16971737 `<li><a href='%s' target='_blank'>%s</a> - %s. The commit (%s) is not authorized under a signed CLA. ` +
16981738 `<a href='%s' target='_blank'>Please click here to be authorized</a>. ` +
16991739 `For further assistance with EasyCLA, <a href='%s' target='_blank'>please submit a support request ticket</a>.</li>` ,
1700- signURL , failed , authorInfo , strings .Join (shas , ", " ), signURL , supportURL ,
1740+ signURL , failed , authorInfo , strings .Join (shas , ", " ),
1741+ signURL , supportURL ,
17011742 ))
17021743 }
17031744 }
@@ -1708,8 +1749,7 @@ func getCommentBody(repositoryType, signURL string, signed, missing []*UserCommi
17081749 committersComment .WriteString ("</ul>" )
17091750 }
17101751
1711- // LG: we don't need this as this will change the comment body every time
1712- // committersComment.WriteString(fmt.Sprintf("<!-- Date Modified: %s -->", time.Now().Format(time.RFC3339)))
1752+ // Python has a Date Modified footer, but that causes churn; intentionally omitted.
17131753
17141754 // Success note if everyone is signed
17151755 if numSigned > 0 && numMissing == 0 {
@@ -1758,25 +1798,6 @@ func getFullSignURL(repositoryType, installationID, githubRepositoryID, pullRequ
17581798 return fmt .Sprintf ("%s/v2/repository-provider/%s/sign/%s/%s/%s/#/?version=2" , apiBaseURL , repositoryType , installationID , githubRepositoryID , pullRequestID )
17591799}
17601800
1761- func getAuthorInfoCommits (userSummary []* UserCommitSummary , tagUser bool ) map [string ][]* UserCommitSummary {
1762- f := logrus.Fields {
1763- "functioName" : "github.github_repository.getAuthorInfoCommits" ,
1764- }
1765- result := make (map [string ][]* UserCommitSummary )
1766- for _ , author := range userSummary {
1767- log .WithFields (f ).WithFields (f ).Debugf ("checking user summary for : %s" , author .getUserInfo (tagUser ))
1768- if _ , ok := result [author .getUserInfo (tagUser )]; ! ok {
1769-
1770- result [author .getUserInfo (tagUser )] = []* UserCommitSummary {
1771- author ,
1772- }
1773- } else {
1774- result [author .getUserInfo (tagUser )] = append (result [author .getUserInfo (tagUser )], author )
1775- }
1776- }
1777- return result
1778- }
1779-
17801801// GetRepositoryByExternalID finds github repository by github repository id
17811802func GetRepositoryByExternalID (ctx context.Context , installationID , id int64 ) (* github.Repository , error ) {
17821803 client , err := NewGithubAppClient (installationID )
0 commit comments