github.com/yrj2011/jx-test-infra@v0.0.0-20190529031832-7a2065ee98eb/prow/cmd/deck/static/tidescript.js (about) 1 "use strict"; 2 3 window.onload = function() { 4 var infoDiv = document.getElementById("info-div"); 5 var infoH2 = infoDiv.getElementsByTagName("h4")[0]; 6 infoH2.addEventListener("click", infoToggle(infoDiv.getElementsByTagName("span")[0]), true); 7 8 redraw(); 9 }; 10 11 document.addEventListener("DOMContentLoaded", function(event) { 12 configure(); 13 }); 14 15 function configure() { 16 if(!branding){ 17 return; 18 } 19 if (branding.logo) { 20 document.getElementById('img').src = branding.logo; 21 } 22 if (branding.favicon) { 23 document.getElementById('favicon').href = branding.favicon; 24 } 25 if (branding.background_color) { 26 document.body.style.background = branding.background_color; 27 } 28 if (branding.header_color) { 29 document.getElementsByTagName('header')[0].style.backgroundColor = branding.header_color; 30 } 31 } 32 33 function infoToggle(toToggle) { 34 return function(event) { 35 if (toToggle.className == "hidden") { 36 toToggle.className = ""; 37 event.target.textContent = "Merge Requirements: (click to collapse)"; 38 } else { 39 toToggle.className = "hidden"; 40 event.target.textContent = "Merge Requirements: (click to expand)"; 41 } 42 } 43 } 44 45 function redraw() { 46 redrawQueries(); 47 redrawPools(); 48 } 49 50 function createLink(href, text) { 51 var a = document.createElement("a"); 52 a.href = href; 53 a.appendChild(document.createTextNode(text)); 54 return a; 55 } 56 57 function createSpan(classList, style, text) { 58 var s = document.createElement("span"); 59 s.classList.add(...classList); 60 s.style = style; 61 s.appendChild(document.createTextNode(text)); 62 return s; 63 } 64 65 function normalizeLabelToClass(label) { 66 // css class names cannot contain whitespace 67 return label.replace(" ", ""); 68 } 69 70 function redrawQueries() { 71 var queries = document.getElementById("queries"); 72 while (queries.firstChild) 73 queries.removeChild(queries.firstChild); 74 75 if (!tideData.Queries) { 76 return; 77 } 78 for (var i = 0; i < tideData.Queries.length; i++) { 79 var query = tideData.Queries[i]; 80 var tideQuery = tideData.TideQueries[i]; 81 82 // create list entry for the query, all details will be within this element 83 var li = document.createElement("li"); 84 85 // GitHub query search link 86 var a = createLink( 87 "https://github.com/search?utf8=" + encodeURIComponent("\u2713") + "&q=" + encodeURIComponent(query), 88 "GitHub Search Link" 89 ); 90 li.appendChild(a); 91 92 // build the description 93 // all queries should implicitly mean this 94 var explanationPrefix = " - Meaning: Is an open Pull Request in one of the following repos: "; 95 li.appendChild(document.createTextNode(explanationPrefix)); 96 var ul = document.createElement("ul"); 97 var innerLi = document.createElement("li"); 98 ul.appendChild(innerLi); 99 li.appendChild(ul); 100 // add the list of repos, defaulting to an empty array if no repos have been provided. 101 var repos = tideQuery["repos"] || []; 102 for (var j = 0; j < repos.length; j++) { 103 innerLi.appendChild(createLink("https://github.com/" + repos[j], repos[j])); 104 if (j+1 < repos.length) { 105 innerLi.appendChild(document.createTextNode(", ")); 106 } 107 } 108 // required labels 109 var hasLabels = tideQuery.hasOwnProperty("labels") && tideQuery["labels"].length > 0; 110 if (hasLabels) { 111 var labels = tideQuery["labels"]; 112 li.appendChild(createSpan(["emphasis"], "", "with")); 113 li.appendChild(document.createTextNode(" the following labels: ")); 114 li.appendChild(document.createElement("br")); 115 var ul = document.createElement("ul"); 116 var innerLi = document.createElement("li"); 117 ul.appendChild(innerLi); 118 li.appendChild(ul); 119 for (var j = 0; j < labels.length; j++) { 120 var label = labels[j]; 121 innerLi.appendChild(createSpan(["label", normalizeLabelToClass(label)], "", label)); 122 if (j+1 < labels.length) { 123 innerLi.appendChild(document.createTextNode(" ")); 124 } 125 } 126 } 127 // required to be not present labels 128 var hasMissingLabels = tideQuery.hasOwnProperty("missingLabels") && tideQuery["missingLabels"].length > 0; 129 if (hasMissingLabels) { 130 var missingLabels = tideQuery["missingLabels"]; 131 if (hasLabels) { 132 li.appendChild(createSpan(["emphasis"], "", "and without")); 133 } else { 134 li.appendChild(createSpan(["emphasis"], "", "without")); 135 } 136 li.appendChild(document.createTextNode(" the following labels: ")); 137 li.appendChild(document.createElement("br")); 138 var ul = document.createElement("ul"); 139 var innerLi = document.createElement("li"); 140 ul.appendChild(innerLi); 141 li.appendChild(ul); 142 for (var j = 0; j < missingLabels.length; j++) { 143 var label = missingLabels[j]; 144 innerLi.appendChild(createSpan(["label", normalizeLabelToClass(label)], "", label)); 145 if (j+1 < missingLabels.length) { 146 innerLi.appendChild(document.createTextNode(" ")); 147 } 148 } 149 } 150 151 // GitHub native review required 152 var reviewApprovedRequired = tideQuery.hasOwnProperty("reviewApprovedRequired") && tideQuery["reviewApprovedRequired"]; 153 if (reviewApprovedRequired) { 154 li.appendChild(document.createTextNode("and must be ")); 155 li.appendChild(createLink( 156 "https://help.github.com/articles/about-pull-request-reviews/", 157 "approved by GitHub review" 158 )); 159 } 160 161 // actually add the entry 162 queries.appendChild(li); 163 } 164 } 165 166 function redrawPools() { 167 var pools = document.getElementById("pools").getElementsByTagName("tbody")[0]; 168 while (pools.firstChild) 169 pools.removeChild(pools.firstChild); 170 171 if (!tideData.Pools) { 172 return; 173 } 174 for (var i = 0; i < tideData.Pools.length; i++) { 175 var pool = tideData.Pools[i]; 176 var r = document.createElement("tr"); 177 178 179 var deckLink = "/?repo="+pool.Org+"%2F"+pool.Repo; 180 var branchLink = "https://github.com/" + pool.Org + "/" + pool.Repo + "/tree/" + pool.Branch; 181 var linksTD = document.createElement("td"); 182 linksTD.appendChild(createLink(deckLink, pool.Org + "/" + pool.Repo)); 183 linksTD.appendChild(document.createTextNode(" ")); 184 linksTD.appendChild(createLink(branchLink, pool.Branch)); 185 r.appendChild(linksTD); 186 r.appendChild(createActionCell(pool)); 187 r.appendChild(createBatchCell(pool)); 188 r.appendChild(createPRCell(pool, pool.SuccessPRs)); 189 r.appendChild(createPRCell(pool, pool.PendingPRs)); 190 r.appendChild(createPRCell(pool, pool.MissingPRs)); 191 192 pools.appendChild(r); 193 } 194 } 195 196 function createLinkCell(text, url, title) { 197 var c = document.createElement("td"); 198 var a = document.createElement("a"); 199 a.href = url; 200 if (title !== "") { 201 a.title = title; 202 } 203 a.appendChild(document.createTextNode(text)); 204 c.appendChild(a); 205 return c; 206 } 207 208 function createActionCell(pool) { 209 var targeted = pool.Target && pool.Target.length; 210 var blocked = pool.Blockers && pool.Blockers.length; 211 var action = pool.Action.replace("_", " "); 212 if (targeted || blocked) { 213 action += ": " 214 } 215 var c = document.createElement("td"); 216 c.appendChild(document.createTextNode(action)); 217 218 if (blocked) { 219 c.classList.add("blocked"); 220 addBlockersToElem(c, pool) 221 } else if (targeted) { 222 addPRsToElem(c, pool, pool.Target) 223 } 224 return c; 225 } 226 227 function createPRCell(pool, prs) { 228 var c = document.createElement("td"); 229 addPRsToElem(c, pool, prs) 230 return c; 231 } 232 233 function createBatchCell(pool) { 234 var td = document.createElement('td'); 235 if (pool.BatchPending) { 236 var numbers = pool.BatchPending.map(p => String(p.Number)); 237 var batchRef = pool.Branch + ',' + numbers.join(','); 238 var href = '/?repo=' + encodeURIComponent(pool.Org + '/' + pool.Repo) + 239 '&type=batch&pull=' + encodeURIComponent(batchRef); 240 var link = document.createElement('a'); 241 link.href = href; 242 link.appendChild(document.createTextNode(numbers.join(' '))); 243 td.appendChild(link); 244 } 245 return td; 246 } 247 248 // addPRsToElem adds a space separated list of PR numbers that link to the corresponding PR on github. 249 function addPRsToElem(elem, pool, prs) { 250 if (prs) { 251 for (var i = 0; i < prs.length; i++) { 252 var a = document.createElement("a"); 253 a.href = "https://github.com/" + pool.Org + "/" + pool.Repo + "/pull/" + prs[i].Number; 254 a.appendChild(document.createTextNode("#" + prs[i].Number)); 255 elem.appendChild(a); 256 // Add a space after each PR number except the last. 257 if (i+1 < prs.length) { 258 elem.appendChild(document.createTextNode(" ")); 259 } 260 } 261 } 262 } 263 264 // addBlockersToElem adds a space separated list of Issue numbers that link to the 265 // corresponding Issues on github that are blocking merge. 266 function addBlockersToElem(elem, pool) { 267 var bs = pool.Blockers 268 for (var i = 0; i < pool.Blockers.length; i++) { 269 var b = pool.Blockers[i]; 270 var id = "blocker-" + pool.Org + "-" + pool.Repo + "-" + b.Number; 271 var a = document.createElement("a"); 272 a.href = b.URL; 273 a.appendChild(document.createTextNode("#" + b.Number)); 274 a.id = id; 275 addToolTipToElem(a, document.createTextNode(b.Title)); 276 277 278 elem.appendChild(a); 279 // Add a space after each PR number except the last. 280 if (i+1 < pool.Blockers.length) { 281 elem.appendChild(document.createTextNode(" ")); 282 } 283 } 284 } 285 286 function addToolTipToElem(elem, tipElem) { 287 var tooltip = document.createElement("div"); 288 tooltip.appendChild(tipElem); 289 tooltip.setAttribute("data-mdl-for", elem.id); 290 tooltip.classList.add("mdl-tooltip", "mdl-tooltip--large"); 291 elem.appendChild(tooltip); 292 }