found in the LICENSE file.
-->
+<link rel="import" href="ct-commit-list.html">
+
<script>
-function CTFailureGroup(key, failures, annotation) {
+function CTFailureGroup(key, data, category) {
this.key = key;
- this.failures = failures;
- this.annotation = annotation || {};
+ this.data = data;
+ this._annotation = CTFailureGroup._mergeAnnotations(data.getAnnotations());
+ this._originalCategory = category || 'default';
this._computeProperties();
}
});
};
+CTFailureGroup.prototype.setBug = function(bug) {
+ if (/^[0-9]+$/.test(bug))
+ bug = 'https://crbug.com/' + bug;
+ return this._annotate({
+ bug: bug,
+ });
+};
+
+CTFailureGroup.prototype.clearBug = function(bug) {
+ return this._annotate({
+ bug: undefined,
+ });
+};
+
+CTFailureGroup.prototype._failedOnce = function() {
+ return this.data.failedOnce && this.data.failedOnce();
+}
+
CTFailureGroup.prototype._computeProperties = function() {
- this.isSnoozed = Date.now() < this.annotation.snoozeTime;
+ this.isSnoozed = Date.now() < this._annotation.snoozeTime;
if (this.isSnoozed) {
this.category = 'snoozed';
} else {
- // FIXME: crbug.com/400397 Split into: Whole step failure, Tree closer, Test failure, Flaky tests
- this.category = 'default';
+ if (this._failedOnce()) {
+ this.category = 'failedOnce';
+ } else {
+ this.category = this._originalCategory;
+ }
+ // FIXME: crbug.com/400397 Split Tree closers into their own list.
}
+
+ this.bug = this._annotation.bug;
+ // FIXME: Bug labels would be simpler to implement as a filter in the UI.
+ if (this.bug != null)
+ this.bugLabel = 'Bug ' + /([0-9]{3,})/.exec(this.bug)[0];
+ else
+ this.bugLabel = undefined;
+};
+
+CTFailureGroup._mergeAnnotations = function(failureAnnotations) {
+ // FIXME: This should be a union of all bugs.
+ var bug = failureAnnotations.map('bug').compact().first();
+
+ // The group is only snoozed if all the failures specify a snooze-time, and only
+ // until the first has elapsed.
+ var snoozeTimes = failureAnnotations.map('snoozeTime').compact();
+ var snoozeTime = snoozeTimes.length < failureAnnotations.length ? undefined : snoozeTimes.min();
+
+ var annotation = {};
+ if (bug != null) {
+ annotation.bug = bug;
+ }
+ if (snoozeTime != null) {
+ annotation.snoozeTime = snoozeTime;
+ }
+ return annotation;
};
CTFailureGroup.prototype._annotate = function(newAnnotation) {
+ var failureAnnotations = [];
// FIXME: Post the new annotation to frontend rather than storing locally.
return CTFailureGroup.fetchAnnotations().then(function(annotations) {
- var annotation = annotations[this.key] || {};
+ this.data.failureKeys().forEach(function(failureKey) {
+ var annotation = annotations[failureKey] || {};
+
+ Object.keys(newAnnotation, function(key, value) {
+ if (value === undefined) {
+ delete annotation[key];
+ } else {
+ annotation[key] = value;
+ }
+ });
- Object.keys(newAnnotation, function(key, value) {
- if (value === 'undefined') {
- delete annotation[key];
+ if (Object.size(annotation) == 0) {
+ delete annotations[failureKey];
} else {
- annotation[key] = value;
+ annotations[failureKey] = annotation;
+ failureAnnotations.push(annotation);
}
});
- if (Object.size(annotation) == 0) {
- delete annotations[this.key];
- } else {
- annotations[this.key] = annotation;
- }
-
localStorage.CTFailureGroupAnnotations = JSON.stringify(annotations);
-
- this.annotation = annotation;
+ this._annotation = CTFailureGroup._mergeAnnotations(failureAnnotations);
this._computeProperties();
}.bind(this));
};