Merge "refactor of hideci for readability and modularity"
This commit is contained in:
commit
bd2df6c7c3
@ -1,4 +1,5 @@
|
|||||||
// Copyright (c) 2014 VMware, Inc.
|
// Copyright (c) 2014 VMware, Inc.
|
||||||
|
// Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
// not use this file except in compliance with the License. You may obtain
|
// not use this file except in compliance with the License. You may obtain
|
||||||
@ -13,189 +14,181 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
|
|
||||||
// this regex matches the hash part of review pages
|
// this regex matches the hash part of review pages
|
||||||
var hashRegex = /^\#\/c\/[\/\d]+$/
|
var hashRegex = /^\#\/c\/[\/\d]+$/;
|
||||||
// this regex matches CI comments
|
// this regex matches CI comments
|
||||||
var ciRegex = /^(.* CI|Jenkins)$/
|
var ciRegex = /^(.* CI|Jenkins)$/;
|
||||||
// this regex matches "Patch set #"
|
// this regex matches "Patch set #"
|
||||||
var psRegex = /^Patch Set (\d+):/
|
var psRegex = /^<p>(Uploaded patch set|Patch Set) (\d+)(:|\.)/;
|
||||||
// this regex matches merge failure messages
|
// this regex matches merge failure messages
|
||||||
var mergeFailedRegex = /^Merge Failed\./
|
var mergeFailedRegex = /Merge Failed\./;
|
||||||
// this regex matches the name of CI systems we trust to report merge failures
|
// this regex matches the name of CI systems we trust to report merge failures
|
||||||
var trustedCIRegex = /^(OpenStack CI|Jenkins)$/
|
var trustedCIRegex = /^(OpenStack CI|Jenkins)$/;
|
||||||
|
|
||||||
ci_find_comments = function() {
|
var ci_parse_psnum = function($panel) {
|
||||||
var comments = [];
|
var match = psRegex.exec($panel.html());
|
||||||
var last_merge_failure = null;
|
if (match !== null) {
|
||||||
$("p").each(function() {
|
return parseInt(match[2]);
|
||||||
var match = psRegex.exec(this.innerHTML);
|
|
||||||
if (match !== null) {
|
|
||||||
var psnum = parseInt(match[1]);
|
|
||||||
var top = $(this).parent().parent().parent();
|
|
||||||
var name = top.attr("name");
|
|
||||||
if (!name) {
|
|
||||||
top = $(this).parent().parent().parent();
|
|
||||||
name = $(this).parent().prev().children()[0].innerHTML;
|
|
||||||
}
|
|
||||||
// Search this comment for results
|
|
||||||
var comment_object = $(this).parent();
|
|
||||||
var result_list = [];
|
|
||||||
comment_object.find("li.comment_test").each(function(i, li) {
|
|
||||||
var result = {};
|
|
||||||
result["name"] = $(li).find("span.comment_test_name").find("a")[0].innerHTML;
|
|
||||||
result["link"] = $(li).find("span.comment_test_name").find("a")[0];
|
|
||||||
result["result"] = $(li).find("span.comment_test_result")[0];
|
|
||||||
result_list.push(result);
|
|
||||||
});
|
|
||||||
|
|
||||||
var comment = {"name":name, "psnum":psnum, "top":top,
|
|
||||||
"merge_failure":null,
|
|
||||||
"results":result_list,
|
|
||||||
"comment":comment_object};
|
|
||||||
comments.push(comment);
|
|
||||||
|
|
||||||
// Keep a pointer to the most recent merge failure message from
|
|
||||||
// the trusted CI system. If there is a message from the system
|
|
||||||
// after it, drop the reference. This way we end up with a pointer
|
|
||||||
// iff the last comment from the trusted system is a merge failure.
|
|
||||||
if (trustedCIRegex.exec(name) !== null) {
|
|
||||||
if ($(this).next().length>0 &&
|
|
||||||
mergeFailedRegex.exec($(this).next()[0].innerHTML) !== null) {
|
|
||||||
last_merge_failure = comment;
|
|
||||||
} else if (result_list.length>0) {
|
|
||||||
last_merge_failure = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// If the last comment from the trusted system is a merge failure,
|
|
||||||
// mark that comment as a merge failure so it is displayed. (We
|
|
||||||
// want to ignore it if there was a merge failure that was
|
|
||||||
// superceded.)
|
|
||||||
if (last_merge_failure !== null) {
|
|
||||||
last_merge_failure["merge_failure"] = true;
|
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
var ci_parse_is_merge_conflict = function($panel) {
|
||||||
|
return (mergeFailedRegex.exec($panel.html()) !== null);
|
||||||
|
};
|
||||||
|
|
||||||
|
var ci_parse_results = function($panel) {
|
||||||
|
var result_list = [];
|
||||||
|
var test_results = $panel.find("li.comment_test");
|
||||||
|
if (test_results !== null) {
|
||||||
|
test_results.each(function(i, li) {
|
||||||
|
var result = {};
|
||||||
|
result["name"] = $(li).find("span.comment_test_name").find("a")[0].innerHTML;
|
||||||
|
result["link"] = $(li).find("span.comment_test_name").find("a")[0];
|
||||||
|
result["result"] = $(li).find("span.comment_test_result")[0];
|
||||||
|
result_list.push(result);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return result_list;
|
||||||
|
};
|
||||||
|
|
||||||
|
var ci_parse_comments = function() {
|
||||||
|
var comments = [];
|
||||||
|
$(".commentPanel").each(function() {
|
||||||
|
var comment = {};
|
||||||
|
comment.name = $(this).attr("name");
|
||||||
|
comment.email = $(this).attr("email");
|
||||||
|
comment.date = $(this).find(".commentPanelDateCell").attr("title");
|
||||||
|
var comment_panel = $(this).find(".commentPanelMessage");
|
||||||
|
comment.psnum = ci_parse_psnum(comment_panel);
|
||||||
|
comment.merge_conflict = ci_parse_is_merge_conflict(comment_panel);
|
||||||
|
comment.results = ci_parse_results(comment_panel);
|
||||||
|
comment.is_ci = (ciRegex.exec(comment.name) !== null);
|
||||||
|
comment.is_trusted_ci = (trustedCIRegex.exec(comment.name) !== null);
|
||||||
|
comment.ref = this;
|
||||||
|
comments.push(comment);
|
||||||
|
});
|
||||||
return comments;
|
return comments;
|
||||||
};
|
};
|
||||||
|
|
||||||
ci_update_table = function() {
|
var ci_latest_patchset = function(comments) {
|
||||||
var patchsets = [];
|
var psnum = 0;
|
||||||
|
for (var i = 0; i < comments.length; i++) {
|
||||||
|
psnum = Math.max(psnum, comments[i].psnum);
|
||||||
|
}
|
||||||
|
return psnum;
|
||||||
|
};
|
||||||
|
|
||||||
var comments = ci_find_comments();
|
var ci_is_merge_conflict = function(comments) {
|
||||||
$.each(comments, function(comment_index, comment) {
|
var latest = ci_latest_patchset(comments);
|
||||||
while (patchsets.length < comment["psnum"]) {
|
var conflict = false;
|
||||||
// Whether there is a current merge failure in this
|
for (var i = 0; i < comments.length; i++) {
|
||||||
// patchset.
|
var comment = comments[i];
|
||||||
patchsets.push({"_merge_failure": false});
|
// only if we are actually talking about the latest patch set
|
||||||
}
|
if (comment.psnum == latest) {
|
||||||
|
if (comment.is_trusted_ci) {
|
||||||
// If this comment has results
|
conflict = comment.merge_conflict;
|
||||||
if (comment["results"].length > 0) {
|
|
||||||
// Get the name of the system
|
|
||||||
var name = comment["name"];
|
|
||||||
// an item in patchsets is a hash of systems
|
|
||||||
var systems = patchsets[comment["psnum"]-1];
|
|
||||||
var system;
|
|
||||||
// Get or create the system object for this system
|
|
||||||
if (name in systems) {
|
|
||||||
system = systems[name];
|
|
||||||
} else {
|
|
||||||
// A system object has an ordered list of jobs (so
|
|
||||||
// we preserve what was in the comments), and a
|
|
||||||
// hash of results (so later runs of the same job
|
|
||||||
// on the same patchset override previous results).
|
|
||||||
system = {"jobs": [], "results": {}};
|
|
||||||
systems[name] = system;
|
|
||||||
}
|
}
|
||||||
$.each(comment["results"], function(i, result) {
|
|
||||||
// For each result, add the name of the job to the
|
|
||||||
// ordered list if it isn't there already
|
|
||||||
if (system["jobs"].indexOf(result["name"]) < 0) {
|
|
||||||
system["jobs"].push(result["name"]);
|
|
||||||
}
|
|
||||||
// Then set or override the result
|
|
||||||
system["results"][result["name"]] = result;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// The merge failure flag will only be set on a comment if it
|
}
|
||||||
// is the most recent comment and is a merge failure.
|
return conflict;
|
||||||
if (comment["merge_failure"] === true) {
|
};
|
||||||
patchsets[comment["psnum"]-1]["_merge_failure"] = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (patchsets.length > 0) {
|
var ci_prepare_results_table = function() {
|
||||||
// Create a table and insert it after the approval table
|
// Create a table and insert it after the approval table
|
||||||
var table = $("table.test_result_table")[0];
|
var table = $("table.test_result_table")[0];
|
||||||
if (!table) {
|
if (!table) {
|
||||||
table = document.createElement("table");
|
table = document.createElement("table");
|
||||||
$(table).addClass("test_result_table");
|
$(table).addClass("test_result_table");
|
||||||
$(table).addClass("infoTable").css({"margin-top":"1em", "margin-bottom":"1em"});
|
$(table).addClass("infoTable").css({"margin-top":"1em", "margin-bottom":"1em"});
|
||||||
var approval_table = $("div.approvalTable");
|
var approval_table = $("div.approvalTable");
|
||||||
if (approval_table.length) {
|
if (approval_table.length) {
|
||||||
var outer_table = document.createElement("table");
|
var outer_table = document.createElement("table");
|
||||||
$(outer_table).insertBefore(approval_table);
|
$(outer_table).insertBefore(approval_table);
|
||||||
var outer_table_row = document.createElement("tr");
|
var outer_table_row = document.createElement("tr");
|
||||||
$(outer_table).append(outer_table_row);
|
$(outer_table).append(outer_table_row);
|
||||||
var td = document.createElement("td");
|
var td = document.createElement("td");
|
||||||
$(outer_table_row).append(td);
|
$(outer_table_row).append(td);
|
||||||
$(td).css({"vertical-align":"top"});
|
$(td).css({"vertical-align":"top"});
|
||||||
$(td).append(approval_table);
|
$(td).append(approval_table);
|
||||||
td = document.createElement("td");
|
td = document.createElement("td");
|
||||||
$(outer_table_row).append(td);
|
$(outer_table_row).append(td);
|
||||||
$(td).css({"vertical-align":"top"});
|
$(td).css({"vertical-align":"top"});
|
||||||
$(td).append(table);
|
$(td).append(table);
|
||||||
} else {
|
|
||||||
var big_table_row = $("div.screen>div>div>table>tbody>tr");
|
|
||||||
var td = $(big_table_row).children()[1];
|
|
||||||
$(td).append(table);
|
|
||||||
}
|
|
||||||
// Hide existing comments
|
|
||||||
ci_toggle_visibility(comments);
|
|
||||||
} else {
|
} else {
|
||||||
$(table).empty();
|
var big_table_row = $("div.screen>div>div>table>tbody>tr");
|
||||||
|
var td = $(big_table_row).children()[1];
|
||||||
|
$(td).append(table);
|
||||||
}
|
}
|
||||||
var patchset = patchsets[patchsets.length-1];
|
} else {
|
||||||
if (!patchset["_merge_failure"]) {
|
$(table).empty();
|
||||||
$.each(patchset, function(name, system) {
|
}
|
||||||
if (name != "_merge_failure") {
|
return table;
|
||||||
// Add a header for each system
|
};
|
||||||
var header = $("<tr>").append($('<td class="header" colspan="2">'+name+'</td>'));
|
|
||||||
$(table).append(header);
|
var ci_display_results = function(comments) {
|
||||||
// Add the results
|
var table = ci_prepare_results_table();
|
||||||
$.each(system["jobs"], function(i, name) {
|
if (ci_is_merge_conflict(comments)) {
|
||||||
var result = system["results"][name];
|
var mc_header = $("<tr>").append($('<td class="merge_conflict" colpsan="2">Patch in Merge Conflict</td>'));
|
||||||
var tr = $("<tr>");
|
mc_header.css('width', '400');
|
||||||
tr.append($("<td>").append($(result["link"]).clone()));
|
mc_header.css('font-weight', 'bold');
|
||||||
tr.append($("<td>").append($(result["result"]).clone()));
|
mc_header.css('color', 'red');
|
||||||
$(table).append(tr);
|
mc_header.css('padding-left', '2em');
|
||||||
});
|
$(table).append(mc_header);
|
||||||
}
|
|
||||||
});
|
return;
|
||||||
|
}
|
||||||
|
var current = ci_latest_patchset(comments);
|
||||||
|
for (var i = 0; i < comments.length; i++) {
|
||||||
|
var comment = comments[i];
|
||||||
|
if ((comment.psnum == current) && comment.is_ci && (comment.results.length > 0)) {
|
||||||
|
var header = $("<tr>").append($('<td class="header">' + comment.name + '</td>'));
|
||||||
|
header.append('<td class="header ci_date">' + comment.date + '</td>');
|
||||||
|
$(table).append(header);
|
||||||
|
|
||||||
|
for (var j = 0; j < comment.results.length; j++) {
|
||||||
|
var result = comment.results[j];
|
||||||
|
var tr = $("<tr>");
|
||||||
|
tr.append($("<td>").append($(result["link"]).clone()));
|
||||||
|
tr.append($("<td>").append($(result["result"]).clone()));
|
||||||
|
$(table).append(tr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ci_page_loaded = function() {
|
var ci_toggle_visibility = function(comments) {
|
||||||
|
if (!comments) {
|
||||||
|
comments = ci_parse_comments();
|
||||||
|
}
|
||||||
|
$.each(comments, function(i, comment) {
|
||||||
|
if (comment.is_ci) {
|
||||||
|
$(comment.ref).toggle();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var ci_hide_ci_comments = function(comments) {
|
||||||
|
if (!comments) {
|
||||||
|
comments = ci_parse_comments();
|
||||||
|
}
|
||||||
|
$.each(comments, function(i, comment) {
|
||||||
|
if (comment.is_ci) {
|
||||||
|
$(comment.ref).hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var ci_page_loaded = function() {
|
||||||
if (hashRegex.test(window.location.hash)) {
|
if (hashRegex.test(window.location.hash)) {
|
||||||
$("#toggleci").show();
|
$("#toggleci").show();
|
||||||
ci_update_table();
|
var comments = ci_parse_comments();
|
||||||
|
ci_display_results(comments);
|
||||||
|
ci_hide_ci_comments(comments);
|
||||||
} else {
|
} else {
|
||||||
$("#toggleci").hide();
|
$("#toggleci").hide();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ci_toggle_visibility = function(comments) {
|
|
||||||
if (!comments) {
|
|
||||||
comments = ci_find_comments();
|
|
||||||
}
|
|
||||||
$.each(comments, function(i, comment) {
|
|
||||||
if (ciRegex.exec(comment["name"]) &&
|
|
||||||
!comment["merge_failure"]) {
|
|
||||||
comment["top"].toggle();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
var input = document.createElement("input");
|
var input = document.createElement("input");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user