@@ -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 {
@@ -603,16 +605,20 @@ func (c *DefaultController) initSubpoolData(sp *subpool) error {
603605// should be deleted.
604606func filterSubpool (spc scmProviderClient , sp * subpool ) * subpool {
605607 var toKeep []PullRequest
608+ var conflicting []int
606609 for _ , pr := range sp .prs {
607610 p := pr
608611 if ! filterPR (spc , sp , & p ) {
609612 toKeep = append (toKeep , pr )
613+ } else if pr .Mergeable == githubql .MergeableStateConflicting && ! hasLabel (& pr , labels .HasConflicts ) {
614+ conflicting = append (conflicting , int (pr .Number ))
610615 }
611616 }
612617 if len (toKeep ) == 0 {
613618 return nil
614619 }
615620 sp .prs = toKeep
621+ sp .conflictingPRs = conflicting
616622 return sp
617623}
618624
@@ -841,7 +847,7 @@ func accumulate(presubmits map[int][]job.Presubmit, prs []PullRequest, pjs []v1a
841847 missingTests = map [int ][]job.Presubmit {}
842848 for _ , pr := range prs {
843849 // Accumulate the best result for each job (Passing > Pending > Failing/Unknown)
844- // We can ignore the baseSHA here because the subPool only contains PipelineActivitys with the correct baseSHA
850+ // We can ignore the baseSHA here because the subPool only contains LighthouseJobs with the correct baseSHA
845851 psStates := make (map [string ]simpleState )
846852 for _ , pj := range pjs {
847853 if pj .Spec .Type != job .PresubmitJob {
@@ -957,6 +963,11 @@ func (c *DefaultController) pickBatch(sp subpool, cc contextChecker) ([]PullRequ
957963 }
958964 }
959965 }
966+ for _ , prNumber := range sp .conflictingPRs {
967+ if err := c .spc .AddLabel (sp .org , sp .repo , prNumber , labels .HasConflicts , true ); err != nil {
968+ sp .log .Warnf ("error while adding Label %q: %v" , labels .HasConflicts , err )
969+ }
970+ }
960971 return res , nil
961972}
962973
@@ -1486,13 +1497,13 @@ func prMeta(prs ...PullRequest) []v1alpha1.Pull {
14861497
14871498func sortPools (pools []Pool ) {
14881499 sort .Slice (pools , func (i , j int ) bool {
1489- if string ( pools [i ].Org ) != string ( pools [j ].Org ) {
1490- return string ( pools [i ].Org ) < string ( pools [j ].Org )
1500+ if pools [i ].Org != pools [j ].Org {
1501+ return pools [i ].Org < pools [j ].Org
14911502 }
1492- if string ( pools [i ].Repo ) != string ( pools [j ].Repo ) {
1493- return string ( pools [i ].Repo ) < string ( pools [j ].Repo )
1503+ if pools [i ].Repo != pools [j ].Repo {
1504+ return pools [i ].Repo < pools [j ].Repo
14941505 }
1495- return string ( pools [i ].Branch ) < string ( pools [j ].Branch )
1506+ return pools [i ].Branch < pools [j ].Branch
14961507 })
14971508
14981509 sortPRs := func (prs []PullRequest ) {
@@ -1517,8 +1528,9 @@ type subpool struct {
15171528
15181529 // ljs contains all LighthouseJobs of type Presubmit or Batch
15191530 // that have the same baseSHA as the subpool
1520- ljs []v1alpha1.LighthouseJob
1521- prs []PullRequest
1531+ ljs []v1alpha1.LighthouseJob
1532+ prs []PullRequest
1533+ conflictingPRs []int
15221534
15231535 cc contextChecker
15241536 // presubmit contains all required presubmits for each PR
@@ -1907,13 +1919,13 @@ func scmPRToGraphQLPR(scmPR *scm.PullRequest, scmRepo *scm.Repository) *PullRequ
19071919 mergeable = githubql .MergeableStateConflicting
19081920 }
19091921
1910- labels := struct {
1922+ qlLabels := struct {
19111923 Nodes []struct {
19121924 Name githubql.String
19131925 }
19141926 }{}
19151927 for _ , l := range scmPR .Labels {
1916- labels .Nodes = append (labels .Nodes , struct { Name githubql.String }{Name : githubql .String (l .Name )})
1928+ qlLabels .Nodes = append (qlLabels .Nodes , struct { Name githubql.String }{Name : githubql .String (l .Name )})
19171929 }
19181930
19191931 return & PullRequest {
@@ -1924,7 +1936,7 @@ func scmPRToGraphQLPR(scmPR *scm.PullRequest, scmRepo *scm.Repository) *PullRequ
19241936 HeadRefOID : githubql .String (scmPR .Head .Sha ),
19251937 Mergeable : mergeable ,
19261938 Repository : scmRepoToGraphQLRepo (scmRepo ),
1927- Labels : labels ,
1939+ Labels : qlLabels ,
19281940 Body : githubql .String (scmPR .Body ),
19291941 Title : githubql .String (scmPR .Title ),
19301942 UpdatedAt : githubql.DateTime {Time : scmPR .Updated },
0 commit comments