@@ -1220,6 +1220,7 @@ func GetCommitAuthorsSignedStatuses(
12201220 return signed , unsigned
12211221}
12221222
1223+ //nolint:gocyclo // complexity is acceptable for now
12231224func GetPullRequestCommitAuthorsREST (ctx context.Context , usersService users.Service , installationID int64 , pullRequestID int , owner , repo string , withCoAuthors bool ) ([]* UserCommitSummary , bool , error ) {
12241225 f := logrus.Fields {
12251226 "functionName" : "github.github_repository.GetPullRequestCommitAuthorsREST" ,
@@ -1235,62 +1236,69 @@ func GetPullRequestCommitAuthorsREST(ctx context.Context, usersService users.Ser
12351236 return nil , false , err
12361237 }
12371238
1238- commits , resp , comErr := client .PullRequests .ListCommits (ctx , owner , repo , pullRequestID , & github.ListOptions {})
1239- if comErr != nil {
1240- log .WithFields (f ).WithError (comErr ).Warnf ("problem listing commits for repo: %s/%s pull request: %d" , owner , repo , pullRequestID )
1241- return nil , false , comErr
1242- }
1243- if resp .StatusCode != http .StatusOK {
1244- msg := fmt .Sprintf ("unexpected status code: %d - expected: %d" , resp .StatusCode , http .StatusOK )
1245- log .WithFields (f ).Warn (msg )
1246- return nil , false , errors .New (msg )
1247- }
1248-
1249- log .WithFields (f ).Debugf ("found %d commits for pull request: %d" , len (commits ), pullRequestID )
12501239 anyMissing := false
1251- for _ , commit := range commits {
1252- log .WithFields (f ).Debugf ("loaded commit: %+v" , commit )
1253- commitAuthor := ""
1254- if commit != nil && commit .Commit != nil && commit .Commit .Author != nil && commit .Commit .Author .Login != nil {
1255- log .WithFields (f ).Debugf ("commit.Commit.Author.Login: %s" , utils .StringValue (commit .Commit .Author .Login ))
1256- commitAuthor = utils .StringValue (commit .Commit .Author .Login )
1257- } else if commit != nil && commit .Author != nil && commit .Author .Login != nil {
1258- log .WithFields (f ).Debugf ("commit.Author.Login: %s" , utils .StringValue (commit .Author .Login ))
1259- commitAuthor = utils .StringValue (commit .Author .Login )
1260- }
1261- name , email := "" , ""
1262- if commit != nil && commit .Commit != nil && commit .Commit .Author != nil {
1263- name = strings .TrimSpace (utils .StringValue (commit .Commit .Author .Name ))
1264- email = strings .TrimSpace (utils .StringValue (commit .Commit .Author .Email ))
1265- if (name != "" || email != "" ) && commit .Author == nil {
1266- commit .Author = & github.User {}
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 )
12671263 }
1268- if name != "" && commit .Author != nil {
1269- if commit .Author .Name == nil || strings .TrimSpace (utils .StringValue (commit .Author .Name )) == "" {
1270- n := name
1271- commit .Author .Name = & n
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+ }
12721282 }
12731283 }
1274- if email != "" && commit .Author != nil {
1275- if commit .Author .Email == nil || strings .TrimSpace (utils .StringValue (commit .Author .Email )) == "" {
1276- e := email
1277- commit .Author .Email = & e
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
12781295 }
12791296 }
12801297 }
1281- log .WithFields (f ).Debugf ("commitAuthor: %s, name: %s, email: %s" , commitAuthor , name , email )
1282- userCommitSummary = append (userCommitSummary , & UserCommitSummary {
1283- SHA : utils .StringValue (commit .SHA ),
1284- CommitAuthor : commit .Author ,
1285- Affiliated : false ,
1286- Authorized : false ,
1287- })
1288- if withCoAuthors {
1289- missing := ExpandWithCoAuthors (ctx , client , usersService , commit , pullRequestID , installationID , & userCommitSummary , & mu )
1290- if ! anyMissing && missing {
1291- anyMissing = true
1292- }
1298+ if resp .NextPage == 0 {
1299+ break
12931300 }
1301+ opts .Page = resp .NextPage
12941302 }
12951303
12961304 return userCommitSummary , anyMissing , nil
0 commit comments