@@ -1220,6 +1220,82 @@ func GetCommitAuthorsSignedStatuses(
12201220 return signed , unsigned
12211221}
12221222
1223+ func GetPullRequestCommitAuthorsREST (ctx context.Context , usersService users.Service , installationID int64 , pullRequestID int , owner , repo string , withCoAuthors bool ) ([]* UserCommitSummary , bool , error ) {
1224+ f := logrus.Fields {
1225+ "functionName" : "github.github_repository.GetPullRequestCommitAuthorsREST" ,
1226+ "pullRequestID" : pullRequestID ,
1227+ "withCoAuthors" : withCoAuthors ,
1228+ }
1229+ var userCommitSummary []* UserCommitSummary
1230+ var mu sync.Mutex
1231+
1232+ client , err := NewGithubAppClient (installationID )
1233+ if err != nil {
1234+ log .WithFields (f ).WithError (err ).Warn ("unable to create Github client" )
1235+ return nil , false , err
1236+ }
1237+
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 )
1250+ 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 {}
1267+ }
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
1272+ }
1273+ }
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
1278+ }
1279+ }
1280+ }
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+ }
1293+ }
1294+ }
1295+
1296+ return userCommitSummary , anyMissing , nil
1297+ }
1298+
12231299func GetPullRequestCommitAuthors (
12241300 ctx context.Context ,
12251301 usersService users.Service ,
@@ -1302,7 +1378,7 @@ query($owner:String!, $name:String!, $number:Int!, $pageSize:Int!, $cursor:Strin
13021378 var page prCommitsPage
13031379 if _ , err := doGraphQL (ctx , client , query , vars , & page ); err != nil {
13041380 log .WithFields (f ).WithError (err ).Warnf ("problem listing commits via GraphQL for %s/%s PR #%d" , owner , repo , pullRequestID )
1305- return nil , false , err
1381+ return GetPullRequestCommitAuthorsREST ( ctx , usersService , installationID , pullRequestID , owner , repo , withCoAuthors )
13061382 }
13071383
13081384 c := page .Repository .PullRequest .Commits
0 commit comments