@@ -5,7 +5,7 @@ import {Label, PullRequest, UserData} from '../api/pr';
5
5
import { ProwJob , ProwJobList , ProwJobState } from '../api/prow' ;
6
6
import { Blocker , TideData , TidePool , TideQuery as ITideQuery } from '../api/tide' ;
7
7
import { getCookieByName , tidehistory } from '../common/common' ;
8
- import { relativeURL } from "../common/urls" ;
8
+ import { parseQuery , relativeURL } from "../common/urls" ;
9
9
10
10
declare const tideData : TideData ;
11
11
declare const allBuilds : ProwJobList ;
@@ -806,11 +806,8 @@ function fillDetail(selector: string, data?: string[] | string): void {
806
806
* @param query
807
807
* @returns {HTMLElement }
808
808
*/
809
- function createQueryDetailsBtn ( query : ProcessedQuery ) : HTMLTableDataCellElement {
810
- const mergeIcon = document . createElement ( "td" ) ;
811
- mergeIcon . classList . add ( "merge-table-icon" ) ;
812
-
813
- const iconButton = createIcon ( "information" , "Clicks to see query details" , [ ] , true ) ;
809
+ function createQueryDetailsBtn ( query : ProcessedQuery ) : HTMLElement {
810
+ const iconButton = createIcon ( "information" , "Click to see query details" , [ ] , true ) ;
814
811
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
815
812
const dialog = document . querySelector ( "#query-dialog" ) ! as HTMLDialogElement ;
816
813
@@ -830,15 +827,14 @@ function createQueryDetailsBtn(query: ProcessedQuery): HTMLTableDataCellElement
830
827
} ) ) ;
831
828
dialog . showModal ( ) ;
832
829
} ) ;
833
- mergeIcon . appendChild ( iconButton ) ;
834
830
835
- return mergeIcon ;
831
+ return iconButton ;
836
832
}
837
833
838
834
/**
839
835
* Creates merge requirement table for queries.
840
836
*/
841
- function createQueriesTable ( prLabels : { Label : Label } [ ] , queries : ProcessedQuery [ ] ) : HTMLTableElement {
837
+ function createQueriesTable ( prLabels : { Label : Label } [ ] , query : ProcessedQuery ) : HTMLTableElement {
842
838
const table = document . createElement ( "table" ) ;
843
839
table . classList . add ( "merge-table" ) ;
844
840
const thead = document . createElement ( "thead" ) ;
@@ -867,13 +863,10 @@ function createQueriesTable(prLabels: {Label: Label}[], queries: ProcessedQuery[
867
863
const col3 = document . createElement ( "td" ) ;
868
864
869
865
const body = document . createElement ( "tbody" ) ;
870
- queries . forEach ( ( query ) => {
871
866
const row = document . createElement ( "tr" ) ;
872
867
row . appendChild ( createMergeLabelCell ( query . labels , true ) ) ;
873
868
row . appendChild ( createMergeLabelCell ( query . missingLabels ) ) ;
874
- row . appendChild ( createQueryDetailsBtn ( query ) ) ;
875
869
body . appendChild ( row ) ;
876
- } ) ;
877
870
878
871
tableRow . appendChild ( col1 ) ;
879
872
tableRow . appendChild ( col2 ) ;
@@ -888,13 +881,13 @@ function createQueriesTable(prLabels: {Label: Label}[], queries: ProcessedQuery[
888
881
/**
889
882
* Creates the merge label requirement status.
890
883
*/
891
- function createMergeLabelStatus ( prLabels : { Label : Label } [ ] = [ ] , queries : ProcessedQuery [ ] ) : HTMLElement {
884
+ function createMergeLabelStatus ( prLabels : { Label : Label } [ ] = [ ] , query : ProcessedQuery ) : HTMLElement {
892
885
const statusContainer = document . createElement ( "div" ) ;
893
886
statusContainer . classList . add ( "status-container" ) ;
894
887
const status = document . createElement ( "div" ) ;
895
888
statusContainer . appendChild ( status ) ;
896
- if ( queries . length > 0 ) {
897
- const labelConflict = ! hasResolvedLabels ( queries [ 0 ] ) ;
889
+ if ( query ) {
890
+ const labelConflict = ! hasResolvedLabels ( query ) ;
898
891
if ( labelConflict ) {
899
892
status . appendChild ( createIcon ( "error" , "" , [ "status-icon" , "failed" ] ) ) ;
900
893
status . appendChild ( document . createTextNode ( "Does not meet label requirements" ) ) ;
@@ -919,7 +912,7 @@ function createMergeLabelStatus(prLabels: {Label: Label}[] = [], queries: Proces
919
912
status . classList . add ( "status" , "expandable" ) ;
920
913
status . appendChild ( arrowIcon ) ;
921
914
922
- const queriesTable = createQueriesTable ( prLabels , queries ) ;
915
+ const queriesTable = createQueriesTable ( prLabels , query ) ;
923
916
if ( ! labelConflict ) {
924
917
queriesTable . classList . add ( "hidden" ) ;
925
918
arrowIcon . textContent = "expand_more" ;
@@ -1010,24 +1003,38 @@ function createGenericConflictStatus(pr: PullRequest, hasConflict: boolean, mess
1010
1003
return statusContainer ;
1011
1004
}
1012
1005
1013
- function createPRCardBody ( pr : PullRequest , builds : UnifiedContext [ ] , queries : ProcessedQuery [ ] ,
1014
- mergeable : boolean , branchConflict : boolean ,
1015
- authorConflict : boolean , milestoneConflict : boolean ) : HTMLElement {
1016
- const cardBody = document . createElement ( "div" ) ;
1006
+ function createPRCardBody ( pr : PullRequest , builds : UnifiedContext [ ] , mergeable : boolean ) : HTMLElement {
1007
+ const cardBodyHeading = document . createElement ( "div" ) ;
1017
1008
const title = document . createElement ( "h3" ) ;
1018
1009
title . textContent = pr . Title ;
1010
+ cardBodyHeading . appendChild ( title ) ;
1011
+ cardBodyHeading . appendChild ( createJobStatus ( builds ) ) ;
1012
+ cardBodyHeading . appendChild ( createMergeConflictStatus ( mergeable ) ) ;
1013
+
1014
+ return cardBodyHeading ;
1015
+ }
1019
1016
1020
- cardBody . classList . add ( "mdl-card__supporting-text" ) ;
1021
- cardBody . appendChild ( title ) ;
1022
- cardBody . appendChild ( createJobStatus ( builds ) ) ;
1017
+ function createPRCardBodyQueryInfo ( pr : PullRequest , builds : UnifiedContext [ ] , query : ProcessedQuery , branchConflict : boolean ,
1018
+ authorConflict : boolean , milestoneConflict : boolean , multipleQueries : boolean , queryNumber : number ) : HTMLElement {
1019
+ const cardBody = document . createElement ( "div" ) ;
1020
+ if ( query ) {
1021
+ const queryTitle = document . createElement ( "h6" )
1022
+ let title = "Merge Query" ;
1023
+ if ( multipleQueries ) {
1024
+ title += " " + queryNumber ;
1025
+ }
1026
+ queryTitle . textContent = title ;
1027
+ queryTitle . appendChild ( createQueryDetailsBtn ( query ) ) ;
1028
+ cardBody . appendChild ( queryTitle )
1029
+ }
1023
1030
const nodes = pr . Labels && pr . Labels . Nodes ? pr . Labels . Nodes : [ ] ;
1024
- cardBody . appendChild ( createMergeLabelStatus ( nodes , queries ) ) ;
1025
- cardBody . appendChild ( createMergeConflictStatus ( mergeable ) ) ;
1031
+ cardBody . appendChild ( createMergeLabelStatus ( nodes , query ) ) ;
1026
1032
cardBody . appendChild ( createGenericConflictStatus ( pr , branchConflict , `Merging into branch ${ pr . BaseRef . Name } is currently forbidden` ) ) ;
1027
- if ( queries . length ) {
1028
- cardBody . appendChild ( createGenericConflictStatus ( pr , authorConflict , `Only merges with author ${ queries [ 0 ] . author } are currently allowed` ) ) ;
1029
- cardBody . appendChild ( createGenericConflictStatus ( pr , milestoneConflict , `Only merges into milestone ${ queries [ 0 ] . milestone } are currently allowed` ) ) ;
1033
+ if ( query ) {
1034
+ cardBody . appendChild ( createGenericConflictStatus ( pr , authorConflict , `Only merges with author ${ query . author } are currently allowed` ) ) ;
1035
+ cardBody . appendChild ( createGenericConflictStatus ( pr , milestoneConflict , `Only merges into milestone ${ query . milestone } are currently allowed` ) ) ;
1030
1036
}
1037
+
1031
1038
return cardBody ;
1032
1039
}
1033
1040
@@ -1164,16 +1171,51 @@ function createPRCard(pr: PullRequest, builds: UnifiedContext[] = [], queries: P
1164
1171
// priority (success)
1165
1172
builds . sort ( compareJobFn ) ;
1166
1173
prCard . classList . add ( "pr-card" , "mdl-card" ) ;
1174
+
1167
1175
const hasMatchingQuery = queries . length > 0 ;
1168
1176
const mergeConflict = pr . Mergeable ? pr . Mergeable === "CONFLICTING" : false ;
1169
- const branchConflict = ! ! ( ( pr . BaseRef && pr . BaseRef . Name && hasMatchingQuery ) &&
1170
- ( ( queries [ 0 ] . excludedBranches && queries [ 0 ] . excludedBranches ! . indexOf ( pr . BaseRef . Name ) !== - 1 ) ||
1171
- ( queries [ 0 ] . includedBranches && queries [ 0 ] . includedBranches ! . indexOf ( pr . BaseRef . Name ) === - 1 ) ) ) ;
1172
- const authorConflict = hasMatchingQuery && queries [ 0 ] . author ? ( ! pr . Author || ! pr . Author . Login || normLogin ( pr . Author . Login ) !== normLogin ( queries [ 0 ] . author ) ) : false ;
1173
- const milestoneConflict = hasMatchingQuery && queries [ 0 ] . milestone ? ( ! pr . Milestone || ! pr . Milestone . Title || pr . Milestone . Title !== queries [ 0 ] . milestone ) : false ;
1174
- const labelConflict = hasMatchingQuery ? ! hasResolvedLabels ( queries [ 0 ] ) : false ;
1175
- prCard . appendChild ( createPRCardTitle ( pr , tidePools , jobVagueState ( builds ) , ! hasMatchingQuery , labelConflict , mergeConflict , branchConflict , authorConflict , milestoneConflict ) ) ;
1176
- prCard . appendChild ( createPRCardBody ( pr , builds , queries , mergeConflict , branchConflict , authorConflict , milestoneConflict ) ) ;
1177
+ let branchConflicts , authorConflicts , milestoneConflicts , labelConflicts = 0 ;
1178
+ const prCardBody = document . createElement ( "div" ) ;
1179
+ prCardBody . classList . add ( "mdl-card__supporting-text" ) ;
1180
+ prCardBody . appendChild ( createPRCardBody ( pr , builds , mergeConflict ) ) ;
1181
+ if ( queries . length ) {
1182
+ queries . forEach ( ( query , index ) => {
1183
+ let branchConflict = false ;
1184
+ if ( ! ! ( ( pr . BaseRef && pr . BaseRef . Name && hasMatchingQuery ) &&
1185
+ ( ( query . excludedBranches && query . excludedBranches ! . indexOf ( pr . BaseRef . Name ) !== - 1 ) ||
1186
+ ( query . includedBranches && query . includedBranches ! . indexOf ( pr . BaseRef . Name ) === - 1 ) ) ) ) {
1187
+ branchConflicts ++ ;
1188
+ branchConflict = true ;
1189
+ }
1190
+
1191
+ let authorConflict = false ;
1192
+ if ( hasMatchingQuery && query . author && ( ! pr . Author || ! pr . Author . Login || normLogin ( pr . Author . Login ) !== normLogin ( query . author ) ) ) {
1193
+ authorConflicts ++ ;
1194
+ authorConflict = true ;
1195
+ }
1196
+
1197
+ let milestoneConflict = false ;
1198
+ if ( hasMatchingQuery && query . milestone && ( ! pr . Milestone || ! pr . Milestone . Title || pr . Milestone . Title !== query . milestone ) ) {
1199
+ milestoneConflicts ++ ;
1200
+ milestoneConflict = true ;
1201
+ }
1202
+
1203
+ if ( hasMatchingQuery && ! hasResolvedLabels ( query ) ) {
1204
+ labelConflicts ++ ;
1205
+ }
1206
+
1207
+ const multipleQueries = queries . length > 1 ;
1208
+ const queryNumber = queries . length > 0 ? index + 1 : 0 ;
1209
+ prCardBody . appendChild ( createPRCardBodyQueryInfo ( pr , builds , query , branchConflict , authorConflict , milestoneConflict , multipleQueries , queryNumber ) ) ;
1210
+ } ) ;
1211
+ } else {
1212
+ prCardBody . appendChild ( createPRCardBodyQueryInfo ( pr , builds , null , false , false , false , false , 0 ) ) ;
1213
+ }
1214
+ const prCardTitle = document . createElement ( "div" ) ;
1215
+ prCardTitle . appendChild ( createPRCardTitle ( pr , tidePools , jobVagueState ( builds ) , ! hasMatchingQuery , labelConflicts > 0 , mergeConflict , branchConflicts > 0 , authorConflicts > 0 , milestoneConflicts > 0 ) ) ;
1216
+ prCard . appendChild ( prCardTitle ) ;
1217
+ prCard . appendChild ( prCardBody ) ;
1218
+
1177
1219
return prCard ;
1178
1220
}
1179
1221
@@ -1255,4 +1297,4 @@ function createMessage(msg: string, icStr?: string): HTMLElement {
1255
1297
msgContainer . classList . add ( "message" ) ;
1256
1298
1257
1299
return msgContainer ;
1258
- }
1300
+ }
0 commit comments