fix hideci for new change screen

The previous hideci enhancements and refactor was not tested on the
new change screen, which sadly removes all the semantic markup around
the displayed changes (boo gerrit).

Do the base parsing based on the looping over the p tags as was done
in the initial version instead of matching divs by semantic tags. A
few of the parsing functions needs to be adapted to know if they are
on old vs. new change screen (like finding the date).

Spot tested locally with new and old change screen, seems to be
working.

Change-Id: Ieadfb78fa4d152d12cb64fc69d808fa510d28abd
This commit is contained in:
Sean Dague 2014-10-28 13:01:54 -04:00
parent d8af47ed4a
commit e923601fdc

View File

@ -18,7 +18,7 @@ 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 = /^<p>(Uploaded patch set|Patch Set) (\d+)(:|\.)/; var psRegex = /^(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
@ -26,14 +26,6 @@ var trustedCIRegex = /^(OpenStack CI|Jenkins)$/;
// this regex matches the pipeline markup // this regex matches the pipeline markup
var pipelineNameRegex = /Build \w+ \((\w+) pipeline\)/; var pipelineNameRegex = /Build \w+ \((\w+) pipeline\)/;
var ci_parse_psnum = function($panel) {
var match = psRegex.exec($panel.html());
if (match !== null) {
return parseInt(match[2]);
}
return 0;
};
var ci_parse_is_merge_conflict = function($panel) { var ci_parse_is_merge_conflict = function($panel) {
return (mergeFailedRegex.exec($panel.html()) !== null); return (mergeFailedRegex.exec($panel.html()) !== null);
}; };
@ -122,20 +114,38 @@ var ci_group_by_pipeline = function(current, comments) {
var ci_parse_comments = function() { var ci_parse_comments = function() {
var comments = []; var comments = [];
$(".commentPanel").each(function() { $("p").each(function() {
var comment = {}; var match = psRegex.exec($(this).html());
comment.name = $(this).attr("name"); if (match !== null) {
comment.email = $(this).attr("email"); var psnum = parseInt(match[2]);
comment.date = $(this).find(".commentPanelDateCell").attr("title"); var top = $(this).parent().parent().parent();
var comment_panel = $(this).find(".commentPanelMessage"); // old change screen
comment.psnum = ci_parse_psnum(comment_panel); var name = top.attr("name");
comment.merge_conflict = ci_parse_is_merge_conflict(comment_panel); if (!name) {
comment.pipeline = ci_find_pipeline(comment_panel); // new change screen
comment.results = ci_parse_results(comment_panel); name = $(this).parent().prev().children()[0].innerHTML;
comment.is_ci = (ciRegex.exec(comment.name) !== null); }
comment.is_trusted_ci = (trustedCIRegex.exec(comment.name) !== null); var comment = {};
comment.ref = this; comment.name = name;
comments.push(comment);
var date_cell = top.find(".commentPanelDateCell");
if (date_cell.attr("title")) {
// old change screen
comment.date = date_cell.attr("title");
} else {
// new change screen
comment.date = $(this).parent().prev().children()[2].innerHTML;
}
var comment_panel = $(this).parent();
comment.psnum = psnum;
comment.merge_conflict = ci_parse_is_merge_conflict(comment_panel);
comment.pipeline = ci_find_pipeline(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 = top;
comments.push(comment);
}
}); });
return comments; return comments;
}; };