From 39f6b6e1f5f602f31fa7cd844809a4a7d4e579d2 Mon Sep 17 00:00:00 2001 From: Israel Madueme Date: Tue, 1 May 2018 17:32:45 -0400 Subject: Bug 1453759 - Port OrangeFactor extension to treeherder --- Bugzilla/CGI.pm | 7 ++- extensions/OrangeFactor/Extension.pm | 4 ++ .../hook/bug/edit-after_custom_fields.html.tmpl | 9 +++- .../hook/bug_modal/edit-details_rhs.html.tmpl | 9 +++- extensions/OrangeFactor/web/js/orange_factor.js | 59 ++++++++-------------- 5 files changed, 45 insertions(+), 43 deletions(-) diff --git a/Bugzilla/CGI.pm b/Bugzilla/CGI.pm index 9e8ba6c09..03805ad1e 100644 --- a/Bugzilla/CGI.pm +++ b/Bugzilla/CGI.pm @@ -42,6 +42,11 @@ sub DEFAULT_CSP { img_src => [ 'self', 'https://secure.gravatar.com', 'https://www.google-analytics.com' ], style_src => [ 'self', 'unsafe-inline' ], object_src => [ 'none' ], + connect_src => [ + 'self', + # This is from extensions/OrangeFactor/web/js/orange_factor.js + 'https://treeherder.mozilla.org/api/failurecount/', + ], form_action => [ 'self', # used in template/en/default/search/search-google.html.tmpl @@ -69,7 +74,7 @@ sub SHOW_BUG_MODAL_CSP { connect_src => [ 'self', # This is from extensions/OrangeFactor/web/js/orange_factor.js - 'https://brasstacks.mozilla.com/orangefactor/api/count', + 'https://treeherder.mozilla.org/api/failurecount/', ], frame_src => [ 'self', ], worker_src => [ 'none', ], diff --git a/extensions/OrangeFactor/Extension.pm b/extensions/OrangeFactor/Extension.pm index ab2f1d749..56dd5dc6e 100644 --- a/extensions/OrangeFactor/Extension.pm +++ b/extensions/OrangeFactor/Extension.pm @@ -17,6 +17,8 @@ use Bugzilla::User::Setting; use Bugzilla::Constants; use Bugzilla::Attachment; +use DateTime; + our $VERSION = '1.0'; sub template_before_process { @@ -38,6 +40,8 @@ sub template_before_process { my $bug = exists $vars->{'bugs'} ? $vars->{'bugs'}[0] : $vars->{'bug'}; if ($bug && grep($_->name eq 'intermittent-failure', @{ $bug->keyword_objects })) { $vars->{'orange_factor'} = 1; + $vars->{'date_start'} = ( DateTime->now() - DateTime::Duration->new( days => 7 ) )->ymd(); + $vars->{'date_end'} = DateTime->now->ymd(); } } diff --git a/extensions/OrangeFactor/template/en/default/hook/bug/edit-after_custom_fields.html.tmpl b/extensions/OrangeFactor/template/en/default/hook/bug/edit-after_custom_fields.html.tmpl index a41188a63..1eedab479 100644 --- a/extensions/OrangeFactor/template/en/default/hook/bug/edit-after_custom_fields.html.tmpl +++ b/extensions/OrangeFactor/template/en/default/hook/bug/edit-after_custom_fields.html.tmpl @@ -17,9 +17,14 @@ [% IF cgi.user_agent.match('(?i)gecko') %] - + [% END %] - (link) diff --git a/extensions/OrangeFactor/template/en/default/hook/bug_modal/edit-details_rhs.html.tmpl b/extensions/OrangeFactor/template/en/default/hook/bug_modal/edit-details_rhs.html.tmpl index 30cd65cd2..d6ee5f127 100644 --- a/extensions/OrangeFactor/template/en/default/hook/bug_modal/edit-details_rhs.html.tmpl +++ b/extensions/OrangeFactor/template/en/default/hook/bug_modal/edit-details_rhs.html.tmpl @@ -16,10 +16,15 @@ %] [% IF cgi.user_agent.match('(?i)gecko') %] - + [% END %] - (link) [% END %] diff --git a/extensions/OrangeFactor/web/js/orange_factor.js b/extensions/OrangeFactor/web/js/orange_factor.js index fa9411cf8..78fbb5eb3 100644 --- a/extensions/OrangeFactor/web/js/orange_factor.js +++ b/extensions/OrangeFactor/web/js/orange_factor.js @@ -8,21 +8,17 @@ $(function() { 'use strict'; - var dayMs = 24 * 60 * 60 * 1000; - var limit = 7; function getOrangeCount(data) { - data = data.oranges; - var total = 0, - days = [], - date = getCurrentDateMs() - limit * dayMs; - for(var i = 0; i < limit; i++) { - var iso = dateString(new Date(date)); - var count = data[iso] ? data[iso].orangecount : 0; - days.push(count); - total += count; - date += dayMs; - } + let days = []; + let total = 0; + + data.forEach(entry => { + let failureCount = entry["failure_count"]; + days.push(failureCount); + total += failureCount; + }); + displayGraph(days); displayCount(total); } @@ -53,39 +49,26 @@ $(function() { $('#orange-count').text(count + ' failures on trunk in the past week'); } - function dateString(date) { - function norm(part) { - return JSON.stringify(part).length == 2 ? part : '0' + part; - } - return date.getFullYear() - + "-" + norm(date.getMonth() + 1) - + "-" + norm(date.getDate()); - } - - function getCurrentDateMs() { - var d = new Date; - return d.getTime(); - }; - function orangify() { - $('#orange-count') - .text('Loading...') - .show(); - var bugId = document.forms['changeform'].id.value; - var request = { + let $orangeCount = $('#orange-count'); + let queryParams = $.param({ + bug: $orangeCount.data('bug-id'), + startday: $orangeCount.data('date-start'), + endday: $orangeCount.data('date-end'), + tree: 'trunk' + }); + let request = { dataType: "json", - xhrFields: { - withCredentials: true - }, - url: "https://brasstacks.mozilla.com/orangefactor/api/count?" + - "bugid=" + encodeURIComponent(bugId) + "&tree=trunk" + url: `https://treeherder.mozilla.org/api/failurecount/?${queryParams}` }; + + $orangeCount.text('Loading...').show(); $.ajax(request) .done(function(data) { getOrangeCount(data); }) .fail(function() { - $('#orange-count').text('Please sign into OrangeFactor first'); + $orangeCount.text('Unable to load OrangeFactor at this time.'); }); } -- cgit v1.2.3-24-g4f1b