/
controller.js
162 lines (144 loc) · 6.77 KB
/
controller.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
"use strict";
treeherder.controller('BugsPluginCtrl', [
'$scope', '$rootScope', 'ThLog', 'ThTextLogStepModel',
'ThBugSuggestionsModel', 'thPinboard', 'thEvents','$q',
'thTabs', '$timeout', 'thUrl', '$uibModal', '$location',
function BugsPluginCtrl(
$scope, $rootScope, ThLog, ThTextLogStepModel, ThBugSuggestionsModel,
thPinboard, thEvents, $q, thTabs, $timeout, thUrl, $uibModal, $location) {
var $log = new ThLog(this.constructor.name);
$log.debug("bugs plugin initialized");
$scope.bug_limit = 20;
$scope.tabs = thTabs.tabs;
$scope.filerInAddress = false;
var query;
// update function triggered by the plugins controller
thTabs.tabs.failureSummary.update = function() {
var newValue = thTabs.tabs.failureSummary.contentId;
$scope.suggestions = [];
$scope.bugSuggestionsLoaded = false;
// cancel any existing failure summary queries
if (query) {
query.$cancelRequest();
}
if (angular.isDefined(newValue)) {
thTabs.tabs.failureSummary.is_loading = true;
query = ThBugSuggestionsModel.query({
project: $rootScope.repoName,
jobId: newValue
}, function(suggestions) {
suggestions.forEach(function(suggestion) {
suggestion.bugs.too_many_open_recent = (
suggestion.bugs.open_recent.length > $scope.bug_limit
);
suggestion.bugs.too_many_all_others = (
suggestion.bugs.all_others.length > $scope.bug_limit
);
suggestion.valid_open_recent = (
suggestion.bugs.open_recent.length > 0 &&
!suggestion.bugs.too_many_open_recent
);
suggestion.valid_all_others = (
suggestion.bugs.all_others.length > 0 &&
!suggestion.bugs.too_many_all_others &&
// If we have too many open_recent bugs, we're unlikely to have
// relevant all_others bugs, so don't show them either.
!suggestion.bugs.too_many_open_recent
);
});
// if we have no bug suggestions, populate with the raw errors from
// the log (we can do this asynchronously, it should normally be
// fast)
if (!suggestions.length) {
query = ThTextLogStepModel.query({
project: $rootScope.repoName,
jobId: newValue
}, function(textLogSteps) {
$scope.errors = textLogSteps
.filter(step => step.result !== 'success')
.map(function(step) {
return {
name: step.name,
result: step.result,
lvURL: thUrl.getLogViewerUrl(newValue) +
"#L" + step.finished_line_number
};
});
});
}
$scope.suggestions = suggestions;
$scope.bugSuggestionsLoaded = true;
thTabs.tabs.failureSummary.is_loading = false;
});
}
};
var showBugFilerButton = function() {
$scope.filerInAddress = $location.search().bugfiler === true;
};
showBugFilerButton();
$rootScope.$on('$locationChangeSuccess', function() {
showBugFilerButton();
});
$scope.fileBug = function(index) {
var summary = $scope.suggestions[index].search;
var allFailures = [];
var crashSignatures = [];
var crashRegex = /application crashed \[@ (.+)\]$/g;
for (var i=0; i<$scope.suggestions.length; i++) {
allFailures.push($scope.suggestions[i].search.split(" | "));
var crash = $scope.suggestions[i].search.match(crashRegex);
if (crash) {
var signature = crash[0].split("application crashed ")[1];
if (!crashSignatures.includes(signature)) {
crashSignatures.push(crash[0].split("application crashed ")[1]);
}
}
}
var modalInstance = $uibModal.open({
templateUrl: 'partials/main/intermittent.html',
controller: 'BugFilerCtrl',
size: 'lg',
openedClass: "filer-open",
resolve: {
summary: function() {
return summary;
},
fullLog: function() {
return $scope.job_log_urls[0].url;
},
parsedLog: function() {
return $scope.lvFullUrl;
},
reftest: function() {
return $scope.isReftest() ? $scope.reftestUrl : "";
},
selectedJob: function() {
return $scope.selectedJob;
},
allFailures: function() {
return allFailures;
},
crashSignatures: function() {
return crashSignatures;
},
successCallback: function() {
return function(data) {
// Auto-classify this failure now that the bug has been filed
// and we have a bug number
thPinboard.addBug({id: data.success});
$rootScope.$evalAsync(
$rootScope.$emit(
thEvents.saveClassification));
// Open the newly filed bug in a new tab or window for further editing
window.open("https://bugzilla.mozilla.org/show_bug.cgi?id=" + data.success);
};
}
}
});
thPinboard.pinJob($scope.selectedJob);
modalInstance.opened.then(function () {
window.setTimeout(() => modalInstance.initiate(), 0);
});
};
}
]);