@@ -24,6 +24,7 @@ import (
2424 "context"
2525 "encoding/json"
2626 "fmt"
27+ "github.com/jenkins-x/lighthouse/pkg/labels"
2728 "net/http"
2829 "os"
2930 "sort"
@@ -79,6 +80,7 @@ type scmProviderClient interface {
7980 GetFile (string , string , string , string ) ([]byte , error )
8081 ListFiles (string , string , string , string ) ([]* scm.FileEntry , error )
8182 GetIssueLabels (string , string , int , bool ) ([]* scm.Label , error )
83+ AddLabel (string , string , int , string , bool ) error
8284}
8385
8486type contextChecker interface {
@@ -596,16 +598,20 @@ func (c *DefaultController) initSubpoolData(sp *subpool) error {
596598// should be deleted.
597599func filterSubpool (spc scmProviderClient , sp * subpool ) * subpool {
598600 var toKeep []PullRequest
601+ var conflicting []int
599602 for _ , pr := range sp .prs {
600603 p := pr
601604 if ! filterPR (spc , sp , & p ) {
602605 toKeep = append (toKeep , pr )
606+ } else if pr .Mergeable == githubql .MergeableStateConflicting && ! hasLabel (& pr , labels .HasConflicts ) {
607+ conflicting = append (conflicting , int (pr .Number ))
603608 }
604609 }
605610 if len (toKeep ) == 0 {
606611 return nil
607612 }
608613 sp .prs = toKeep
614+ sp .conflictingPRs = conflicting
609615 return sp
610616}
611617
@@ -834,7 +840,7 @@ func accumulate(presubmits map[int][]job.Presubmit, prs []PullRequest, pjs []v1a
834840 missingTests = map [int ][]job.Presubmit {}
835841 for _ , pr := range prs {
836842 // Accumulate the best result for each job (Passing > Pending > Failing/Unknown)
837- // We can ignore the baseSHA here because the subPool only contains PipelineActivitys with the correct baseSHA
843+ // We can ignore the baseSHA here because the subPool only contains LighthouseJobs with the correct baseSHA
838844 psStates := make (map [string ]simpleState )
839845 for _ , pj := range pjs {
840846 if pj .Spec .Type != job .PresubmitJob {
@@ -950,6 +956,11 @@ func (c *DefaultController) pickBatch(sp subpool, cc contextChecker) ([]PullRequ
950956 }
951957 }
952958 }
959+ for _ , prNumber := range sp .conflictingPRs {
960+ if err := c .spc .AddLabel (sp .org , sp .repo , prNumber , labels .HasConflicts , true ); err != nil {
961+ sp .log .Warnf ("error while adding Label %q: %v" , labels .HasConflicts , err )
962+ }
963+ }
953964 return res , nil
954965}
955966
@@ -1479,13 +1490,13 @@ func prMeta(prs ...PullRequest) []v1alpha1.Pull {
14791490
14801491func sortPools (pools []Pool ) {
14811492 sort .Slice (pools , func (i , j int ) bool {
1482- if string ( pools [i ].Org ) != string ( pools [j ].Org ) {
1483- return string ( pools [i ].Org ) < string ( pools [j ].Org )
1493+ if pools [i ].Org != pools [j ].Org {
1494+ return pools [i ].Org < pools [j ].Org
14841495 }
1485- if string ( pools [i ].Repo ) != string ( pools [j ].Repo ) {
1486- return string ( pools [i ].Repo ) < string ( pools [j ].Repo )
1496+ if pools [i ].Repo != pools [j ].Repo {
1497+ return pools [i ].Repo < pools [j ].Repo
14871498 }
1488- return string ( pools [i ].Branch ) < string ( pools [j ].Branch )
1499+ return pools [i ].Branch < pools [j ].Branch
14891500 })
14901501
14911502 sortPRs := func (prs []PullRequest ) {
@@ -1510,8 +1521,9 @@ type subpool struct {
15101521
15111522 // ljs contains all LighthouseJobs of type Presubmit or Batch
15121523 // that have the same baseSHA as the subpool
1513- ljs []v1alpha1.LighthouseJob
1514- prs []PullRequest
1524+ ljs []v1alpha1.LighthouseJob
1525+ prs []PullRequest
1526+ conflictingPRs []int
15151527
15161528 cc contextChecker
15171529 // presubmit contains all required presubmits for each PR
@@ -1900,13 +1912,13 @@ func scmPRToGraphQLPR(scmPR *scm.PullRequest, scmRepo *scm.Repository) *PullRequ
19001912 mergeable = githubql .MergeableStateConflicting
19011913 }
19021914
1903- labels := struct {
1915+ qlLabels := struct {
19041916 Nodes []struct {
19051917 Name githubql.String
19061918 }
19071919 }{}
19081920 for _ , l := range scmPR .Labels {
1909- labels .Nodes = append (labels .Nodes , struct { Name githubql.String }{Name : githubql .String (l .Name )})
1921+ qlLabels .Nodes = append (qlLabels .Nodes , struct { Name githubql.String }{Name : githubql .String (l .Name )})
19101922 }
19111923
19121924 return & PullRequest {
@@ -1917,7 +1929,7 @@ func scmPRToGraphQLPR(scmPR *scm.PullRequest, scmRepo *scm.Repository) *PullRequ
19171929 HeadRefOID : githubql .String (scmPR .Head .Sha ),
19181930 Mergeable : mergeable ,
19191931 Repository : scmRepoToGraphQLRepo (scmRepo ),
1920- Labels : labels ,
1932+ Labels : qlLabels ,
19211933 Body : githubql .String (scmPR .Body ),
19221934 Title : githubql .String (scmPR .Title ),
19231935 UpdatedAt : githubql.DateTime {Time : scmPR .Updated },
0 commit comments