Skip to content

Commit 9a6a516

Browse files
authored
Merge pull request #28669 from smg247/pr-status
`deck`: differentiate merge queries in pr status card
2 parents f0b21b4 + af7cc02 commit 9a6a516

File tree

1 file changed

+79
-37
lines changed
  • prow/cmd/deck/static/pr

1 file changed

+79
-37
lines changed

prow/cmd/deck/static/pr/pr.ts

+79-37
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {Label, PullRequest, UserData} from '../api/pr';
55
import {ProwJob, ProwJobList, ProwJobState} from '../api/prow';
66
import {Blocker, TideData, TidePool, TideQuery as ITideQuery} from '../api/tide';
77
import {getCookieByName, tidehistory} from '../common/common';
8-
import {relativeURL} from "../common/urls";
8+
import {parseQuery, relativeURL} from "../common/urls";
99

1010
declare const tideData: TideData;
1111
declare const allBuilds: ProwJobList;
@@ -806,11 +806,8 @@ function fillDetail(selector: string, data?: string[] | string): void {
806806
* @param query
807807
* @returns {HTMLElement}
808808
*/
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);
814811
/* eslint-disable @typescript-eslint/no-unnecessary-type-assertion */
815812
const dialog = document.querySelector("#query-dialog")! as HTMLDialogElement;
816813

@@ -830,15 +827,14 @@ function createQueryDetailsBtn(query: ProcessedQuery): HTMLTableDataCellElement
830827
}));
831828
dialog.showModal();
832829
});
833-
mergeIcon.appendChild(iconButton);
834830

835-
return mergeIcon;
831+
return iconButton;
836832
}
837833

838834
/**
839835
* Creates merge requirement table for queries.
840836
*/
841-
function createQueriesTable(prLabels: {Label: Label}[], queries: ProcessedQuery[]): HTMLTableElement {
837+
function createQueriesTable(prLabels: { Label: Label }[], query: ProcessedQuery): HTMLTableElement {
842838
const table = document.createElement("table");
843839
table.classList.add("merge-table");
844840
const thead = document.createElement("thead");
@@ -867,13 +863,10 @@ function createQueriesTable(prLabels: {Label: Label}[], queries: ProcessedQuery[
867863
const col3 = document.createElement("td");
868864

869865
const body = document.createElement("tbody");
870-
queries.forEach((query) => {
871866
const row = document.createElement("tr");
872867
row.appendChild(createMergeLabelCell(query.labels, true));
873868
row.appendChild(createMergeLabelCell(query.missingLabels));
874-
row.appendChild(createQueryDetailsBtn(query));
875869
body.appendChild(row);
876-
});
877870

878871
tableRow.appendChild(col1);
879872
tableRow.appendChild(col2);
@@ -888,13 +881,13 @@ function createQueriesTable(prLabels: {Label: Label}[], queries: ProcessedQuery[
888881
/**
889882
* Creates the merge label requirement status.
890883
*/
891-
function createMergeLabelStatus(prLabels: {Label: Label}[] = [], queries: ProcessedQuery[]): HTMLElement {
884+
function createMergeLabelStatus(prLabels: { Label: Label }[] = [], query: ProcessedQuery): HTMLElement {
892885
const statusContainer = document.createElement("div");
893886
statusContainer.classList.add("status-container");
894887
const status = document.createElement("div");
895888
statusContainer.appendChild(status);
896-
if (queries.length > 0) {
897-
const labelConflict = !hasResolvedLabels(queries[0]);
889+
if (query) {
890+
const labelConflict = !hasResolvedLabels(query);
898891
if (labelConflict) {
899892
status.appendChild(createIcon("error", "", ["status-icon", "failed"]));
900893
status.appendChild(document.createTextNode("Does not meet label requirements"));
@@ -919,7 +912,7 @@ function createMergeLabelStatus(prLabels: {Label: Label}[] = [], queries: Proces
919912
status.classList.add("status", "expandable");
920913
status.appendChild(arrowIcon);
921914

922-
const queriesTable = createQueriesTable(prLabels, queries);
915+
const queriesTable = createQueriesTable(prLabels, query);
923916
if (!labelConflict) {
924917
queriesTable.classList.add("hidden");
925918
arrowIcon.textContent = "expand_more";
@@ -1010,24 +1003,38 @@ function createGenericConflictStatus(pr: PullRequest, hasConflict: boolean, mess
10101003
return statusContainer;
10111004
}
10121005

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");
10171008
const title = document.createElement("h3");
10181009
title.textContent = pr.Title;
1010+
cardBodyHeading.appendChild(title);
1011+
cardBodyHeading.appendChild(createJobStatus(builds));
1012+
cardBodyHeading.appendChild(createMergeConflictStatus(mergeable));
1013+
1014+
return cardBodyHeading;
1015+
}
10191016

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+
}
10231030
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));
10261032
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`));
10301036
}
1037+
10311038
return cardBody;
10321039
}
10331040

@@ -1164,16 +1171,51 @@ function createPRCard(pr: PullRequest, builds: UnifiedContext[] = [], queries: P
11641171
// priority (success)
11651172
builds.sort(compareJobFn);
11661173
prCard.classList.add("pr-card", "mdl-card");
1174+
11671175
const hasMatchingQuery = queries.length > 0;
11681176
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+
11771219
return prCard;
11781220
}
11791221

@@ -1255,4 +1297,4 @@ function createMessage(msg: string, icStr?: string): HTMLElement {
12551297
msgContainer.classList.add("message");
12561298

12571299
return msgContainer;
1258-
}
1300+
}

0 commit comments

Comments
 (0)