@@ -1220,6 +1220,90 @@ func GetCommitAuthorsSignedStatuses(
12201220 return signed , unsigned
12211221}
12221222
1223+ //nolint:gocyclo // complexity is acceptable for now
1224+ func GetPullRequestCommitAuthorsREST (ctx context.Context , usersService users.Service , installationID int64 , pullRequestID int , owner , repo string , withCoAuthors bool ) ([]* UserCommitSummary , bool , error ) {
1225+ f := logrus.Fields {
1226+ "functionName" : "github.github_repository.GetPullRequestCommitAuthorsREST" ,
1227+ "pullRequestID" : pullRequestID ,
1228+ "withCoAuthors" : withCoAuthors ,
1229+ }
1230+ var userCommitSummary []* UserCommitSummary
1231+ var mu sync.Mutex
1232+
1233+ client , err := NewGithubAppClient (installationID )
1234+ if err != nil {
1235+ log .WithFields (f ).WithError (err ).Warn ("unable to create Github client" )
1236+ return nil , false , err
1237+ }
1238+
1239+ anyMissing := false
1240+ opts := & github.ListOptions {PerPage : 100 }
1241+ for {
1242+ commits , resp , comErr := client .PullRequests .ListCommits (ctx , owner , repo , pullRequestID , opts )
1243+ if comErr != nil {
1244+ log .WithFields (f ).WithError (comErr ).Warnf ("problem listing commits for repo: %s/%s pull request: %d" , owner , repo , pullRequestID )
1245+ return nil , false , comErr
1246+ }
1247+ if resp .StatusCode != http .StatusOK {
1248+ msg := fmt .Sprintf ("unexpected status code: %d - expected: %d" , resp .StatusCode , http .StatusOK )
1249+ log .WithFields (f ).Warn (msg )
1250+ return nil , false , errors .New (msg )
1251+ }
1252+
1253+ log .WithFields (f ).Debugf ("found %d commits for pull request: %d" , len (commits ), pullRequestID )
1254+ for _ , commit := range commits {
1255+ log .WithFields (f ).Debugf ("loaded commit: %+v" , commit )
1256+ commitAuthor := ""
1257+ if commit != nil && commit .Commit != nil && commit .Commit .Author != nil && commit .Commit .Author .Login != nil {
1258+ log .WithFields (f ).Debugf ("commit.Commit.Author.Login: %s" , utils .StringValue (commit .Commit .Author .Login ))
1259+ commitAuthor = utils .StringValue (commit .Commit .Author .Login )
1260+ } else if commit != nil && commit .Author != nil && commit .Author .Login != nil {
1261+ log .WithFields (f ).Debugf ("commit.Author.Login: %s" , utils .StringValue (commit .Author .Login ))
1262+ commitAuthor = utils .StringValue (commit .Author .Login )
1263+ }
1264+ name , email := "" , ""
1265+ if commit != nil && commit .Commit != nil && commit .Commit .Author != nil {
1266+ name = strings .TrimSpace (utils .StringValue (commit .Commit .Author .Name ))
1267+ email = strings .TrimSpace (utils .StringValue (commit .Commit .Author .Email ))
1268+ if (name != "" || email != "" ) && commit .Author == nil {
1269+ commit .Author = & github.User {}
1270+ }
1271+ if name != "" && commit .Author != nil {
1272+ if commit .Author .Name == nil || strings .TrimSpace (utils .StringValue (commit .Author .Name )) == "" {
1273+ n := name
1274+ commit .Author .Name = & n
1275+ }
1276+ }
1277+ if email != "" && commit .Author != nil {
1278+ if commit .Author .Email == nil || strings .TrimSpace (utils .StringValue (commit .Author .Email )) == "" {
1279+ e := email
1280+ commit .Author .Email = & e
1281+ }
1282+ }
1283+ }
1284+ log .WithFields (f ).Debugf ("commitAuthor: %s, name: %s, email: %s" , commitAuthor , name , email )
1285+ userCommitSummary = append (userCommitSummary , & UserCommitSummary {
1286+ SHA : utils .StringValue (commit .SHA ),
1287+ CommitAuthor : commit .Author ,
1288+ Affiliated : false ,
1289+ Authorized : false ,
1290+ })
1291+ if withCoAuthors {
1292+ missing := ExpandWithCoAuthors (ctx , client , usersService , commit , pullRequestID , installationID , & userCommitSummary , & mu )
1293+ if ! anyMissing && missing {
1294+ anyMissing = true
1295+ }
1296+ }
1297+ }
1298+ if resp .NextPage == 0 {
1299+ break
1300+ }
1301+ opts .Page = resp .NextPage
1302+ }
1303+
1304+ return userCommitSummary , anyMissing , nil
1305+ }
1306+
12231307func GetPullRequestCommitAuthors (
12241308 ctx context.Context ,
12251309 usersService users.Service ,
@@ -1302,7 +1386,7 @@ query($owner:String!, $name:String!, $number:Int!, $pageSize:Int!, $cursor:Strin
13021386 var page prCommitsPage
13031387 if _ , err := doGraphQL (ctx , client , query , vars , & page ); err != nil {
13041388 log .WithFields (f ).WithError (err ).Warnf ("problem listing commits via GraphQL for %s/%s PR #%d" , owner , repo , pullRequestID )
1305- return nil , false , err
1389+ return GetPullRequestCommitAuthorsREST ( ctx , usersService , installationID , pullRequestID , owner , repo , withCoAuthors )
13061390 }
13071391
13081392 c := page .Repository .PullRequest .Commits
0 commit comments