2018-02-24 01:51:09 +03:00
|
|
|
import numeral from 'numeral';
|
2013-07-25 03:41:50 +04:00
|
|
|
|
2018-02-27 21:48:22 +03:00
|
|
|
import treeherder from './treeherder';
|
|
|
|
|
2017-05-30 18:06:11 +03:00
|
|
|
treeherder.filter('stripHtml', function () {
|
|
|
|
return function (input) {
|
2018-03-07 03:52:23 +03:00
|
|
|
const str = input || '';
|
2014-03-27 23:37:28 +04:00
|
|
|
return str.replace(/<\/?[^>]+>/gi, '');
|
2014-03-27 23:12:00 +04:00
|
|
|
};
|
2014-05-06 22:33:31 +04:00
|
|
|
});
|
2014-03-27 23:12:00 +04:00
|
|
|
|
2017-05-30 18:06:11 +03:00
|
|
|
treeherder.filter('linkifyBugs', function () {
|
|
|
|
return function (input) {
|
2018-03-07 03:52:23 +03:00
|
|
|
let str = input || '';
|
2015-03-12 22:05:59 +03:00
|
|
|
|
2018-03-07 03:52:23 +03:00
|
|
|
const bug_matches = str.match(/-- ([0-9]+)|bug.([0-9]+)/ig);
|
|
|
|
const pr_matches = str.match(/PR#([0-9]+)/ig);
|
2015-03-12 22:05:59 +03:00
|
|
|
|
|
|
|
// Settings
|
2018-03-07 03:52:23 +03:00
|
|
|
const bug_title = 'bugzilla.mozilla.org';
|
|
|
|
const bug_url = '<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=$1" ' +
|
2017-10-02 03:14:26 +03:00
|
|
|
'data-bugid="$1" title="' + bug_title + '">$1</a>';
|
2018-03-07 03:52:23 +03:00
|
|
|
const pr_title = 'github.com';
|
|
|
|
const pr_url = '<a href="https://github.com/mozilla-b2g/gaia/pull/$1" ' +
|
2017-10-02 03:14:26 +03:00
|
|
|
'data-prid="$1" title="' + pr_title + '">$1</a>';
|
2015-03-12 22:05:59 +03:00
|
|
|
|
2015-01-29 17:40:21 +03:00
|
|
|
if (bug_matches) {
|
2015-03-12 22:05:59 +03:00
|
|
|
// Separate passes to preserve prefix
|
|
|
|
str = str.replace(/Bug ([0-9]+)/g, "Bug " + bug_url);
|
|
|
|
str = str.replace(/bug ([0-9]+)/g, "bug " + bug_url);
|
|
|
|
str = str.replace(/-- ([0-9]+)/g, "-- " + bug_url);
|
2015-01-29 17:40:21 +03:00
|
|
|
}
|
2015-03-12 22:05:59 +03:00
|
|
|
|
|
|
|
if (pr_matches) {
|
|
|
|
// Separate passes to preserve prefix
|
|
|
|
str = str.replace(/PR#([0-9]+)/g, "PR#" + pr_url);
|
|
|
|
str = str.replace(/pr#([0-9]+)/g, "pr#" + pr_url);
|
|
|
|
}
|
|
|
|
|
2015-01-29 17:40:21 +03:00
|
|
|
return str;
|
2014-04-17 03:02:41 +04:00
|
|
|
};
|
2014-05-06 22:33:31 +04:00
|
|
|
});
|
|
|
|
|
2018-03-02 03:00:28 +03:00
|
|
|
treeherder.filter('getRevisionUrl', function () {
|
2017-05-30 18:06:11 +03:00
|
|
|
return function (revision, projectName) {
|
2015-07-19 14:19:27 +03:00
|
|
|
if (revision) {
|
2018-03-09 02:48:31 +03:00
|
|
|
return `/#/jobs?repo=${projectName}&revision=${revision}`;
|
2015-07-19 14:19:27 +03:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
};
|
2018-03-02 03:00:28 +03:00
|
|
|
});
|
2015-10-31 00:15:45 +03:00
|
|
|
|
2017-05-30 18:06:11 +03:00
|
|
|
treeherder.filter('displayNumber', ['$filter', function ($filter) {
|
|
|
|
return function (input) {
|
2016-08-22 18:18:26 +03:00
|
|
|
if (isNaN(input)) {
|
|
|
|
return "N/A";
|
|
|
|
}
|
|
|
|
|
2017-05-05 16:57:11 +03:00
|
|
|
return $filter('number')(input, 2);
|
2016-08-22 18:18:26 +03:00
|
|
|
};
|
2017-05-05 16:57:11 +03:00
|
|
|
}]);
|
2017-04-11 15:25:46 +03:00
|
|
|
|
2017-05-30 18:06:11 +03:00
|
|
|
treeherder.filter('absoluteValue', function () {
|
|
|
|
return function (input) {
|
2017-04-11 15:25:46 +03:00
|
|
|
return Math.abs(input);
|
|
|
|
};
|
|
|
|
});
|
2017-06-13 20:29:54 +03:00
|
|
|
|
2018-02-24 01:51:09 +03:00
|
|
|
treeherder.filter('abbreviatedNumber', function () {
|
2017-06-13 20:29:54 +03:00
|
|
|
return input =>
|
2017-10-02 02:42:30 +03:00
|
|
|
((input.toString().length <= 5) ? input : numeral(input).format('0.0a'));
|
2018-02-24 01:51:09 +03:00
|
|
|
});
|