From d8af47ed4af324e08e9d48e12c7caff2c0c1a5f4 Mon Sep 17 00:00:00 2001 From: Sean Dague <sean@dague.net> Date: Mon, 27 Oct 2014 15:10:18 -0400 Subject: [PATCH] only show most recent results per pipeline Change hideci to only show the most recent results of a pipeline. For entries where the pipeline is not parsable we default to assuming the results were in the 'check' pipeline. 3rd Party CI systems are assumed to be 'check' pipeline for the purposes of this patch. Order the display of these results for parsed pipeline entries first, then non parsed entries after. That has the impact of making all the Jenkins results be the top of the page and 3rd Party come later. Also provide a (### rechecks) comment if we find more than 1 result at the current patch set number. This helps reviewers understand that this patch might be unstable as it's been rechecked to get to the current state. Change-Id: I153f73000f9392af6c8bbe850716645b3ba836a0 --- .../openstack_project/files/gerrit/hideci.js | 103 +++++++++++++++--- 1 file changed, 90 insertions(+), 13 deletions(-) diff --git a/modules/openstack_project/files/gerrit/hideci.js b/modules/openstack_project/files/gerrit/hideci.js index 7275c57127..3f1dabbc46 100644 --- a/modules/openstack_project/files/gerrit/hideci.js +++ b/modules/openstack_project/files/gerrit/hideci.js @@ -23,6 +23,8 @@ var psRegex = /^<p>(Uploaded patch set|Patch Set) (\d+)(:|\.)/; var mergeFailedRegex = /Merge Failed\./; // this regex matches the name of CI systems we trust to report merge failures var trustedCIRegex = /^(OpenStack CI|Jenkins)$/; +// this regex matches the pipeline markup +var pipelineNameRegex = /Build \w+ \((\w+) pipeline\)/; var ci_parse_psnum = function($panel) { var match = psRegex.exec($panel.html()); @@ -36,9 +38,19 @@ var ci_parse_is_merge_conflict = function($panel) { return (mergeFailedRegex.exec($panel.html()) !== null); }; +var ci_find_pipeline = function($panel) { + var match = pipelineNameRegex.exec($panel.html()); + if (match !== null) { + return match[1]; + } else { + return null; + } +}; + var ci_parse_results = function($panel) { var result_list = []; var test_results = $panel.find("li.comment_test"); + var pipeline = null; if (test_results !== null) { test_results.each(function(i, li) { var result = {}; @@ -51,6 +63,63 @@ var ci_parse_results = function($panel) { return result_list; }; +/*** + * function ci_group_by_pipeline - create a group by structure for iterating on pipelines + * + * This function takes the full list of comments, the current patch + * number, and builds an array of (pipelinename, comments array) + * tuples. That makes it very easy to process during the display + * phase to ensure we only display the latest result for every + * pipeline. + * + * Comments that do not have a parsable pipeline (3rd party ci + * systems) get collapsed by name, and we specify 'check' for their + * pipeline. + * + **/ + +var ci_group_by_pipeline = function(current, comments) { + var pipelines = []; + var pipeline_comments = []; + var nonpipelines = []; + var nonpipeline_comments = []; + for (var i = 0; i < comments.length; i++) { + var comment = comments[i]; + if ((comment.psnum != current) || !comment.is_ci || (comment.results.length == 0)) { + continue; + } + if (comment.pipeline === null) { + var index = nonpipelines.indexOf(comment.name); + if (index == -1) { + // not found, so create new entries + nonpipelines.push(comment.name); + nonpipeline_comments.push([comment]); + } else { + nonpipeline_comments[index].push(comment); + } + } else { + var index = pipelines.indexOf(comment.pipeline); + if (index == -1) { + // not found, so create new entries + pipelines.push(comment.pipeline); + pipeline_comments.push([comment]); + } else { + pipeline_comments[index].push(comment); + } + } + } + + var results = []; + for (i = 0; i < pipelines.length; i++) { + results.push([pipelines[i], pipeline_comments[i]]); + } + for (i = 0; i < nonpipeline_comments.length; i++) { + // if you don't specify a pipline, it defaults to check + results.push(['check', nonpipeline_comments[i]]); + } + return results; +}; + var ci_parse_comments = function() { var comments = []; $(".commentPanel").each(function() { @@ -61,6 +130,7 @@ var ci_parse_comments = function() { var comment_panel = $(this).find(".commentPanelMessage"); comment.psnum = ci_parse_psnum(comment_panel); 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); @@ -138,20 +208,27 @@ var ci_display_results = function(comments) { 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); + var pipelines = ci_group_by_pipeline(current, comments); + for (var i = 0; i < pipelines.length; i++) { + var pipeline_name = pipelines[i][0]; + var pipeline_comments = pipelines[i][1]; + // the most recent comment on a pipeline + var last = pipelines[i][1].length - 1; + var comment = pipeline_comments[last]; + var rechecks = ""; + if (last > 0) { + rechecks = " (" + last + " rechecks)"; + } - 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); - } + var header = $("<tr>").append($('<td class="header">' + comment.name + " " + pipeline_name + rechecks + '</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); } } };