| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 Copyright 2014 The Chromium Authors. All rights reserved. | |
| 3 Use of this source code is governed by a BSD-style license that can be | |
| 4 found in the LICENSE file. | |
| 5 --> | |
| 6 | |
| 7 <link rel="import" href="ct-commit-list.html"> | |
| 8 | |
| 9 <script> | |
| 10 function CTFailureGroup(tree, data, category) { | |
| 11 this.key = data.key; | |
| 12 this.tree = tree; | |
| 13 this.examineUrl = this.tree + '/failure/' + encodeURIComponent(this.key); | |
| 14 this.data = data; | |
| 15 | |
| 16 this._annotation = CTFailureGroup._mergeAnnotations(data.getAnnotations()); | |
| 17 this._originalCategory = category || 'default'; | |
| 18 this._computeProperties(); | |
| 19 } | |
| 20 | |
| 21 CTFailureGroup.prototype.snoozeUntil = function(time) { | |
| 22 return this._annotate({ | |
| 23 snoozeTime: time, | |
| 24 }); | |
| 25 }; | |
| 26 | |
| 27 CTFailureGroup.prototype.unsnooze = function() { | |
| 28 return this._annotate({ | |
| 29 snoozeTime: undefined, | |
| 30 }); | |
| 31 }; | |
| 32 | |
| 33 CTFailureGroup.prototype.setBug = function(bug) { | |
| 34 if (/^[0-9]+$/.test(bug)) | |
| 35 bug = 'https://crbug.com/' + bug; | |
| 36 return this._annotate({ | |
| 37 bug: bug, | |
| 38 }); | |
| 39 }; | |
| 40 | |
| 41 CTFailureGroup.prototype.clearBug = function(bug) { | |
| 42 return this._annotate({ | |
| 43 bug: undefined, | |
| 44 }); | |
| 45 }; | |
| 46 | |
| 47 CTFailureGroup.prototype._isTreeCloser = function() { | |
| 48 return this.data.isTreeCloser && this.data.isTreeCloser(); | |
| 49 } | |
| 50 | |
| 51 CTFailureGroup.prototype._failedOnce = function() { | |
| 52 return this.data.failedOnce && this.data.failedOnce(); | |
| 53 } | |
| 54 | |
| 55 CTFailureGroup.prototype._computeProperties = function() { | |
| 56 this.isSnoozed = Date.now() < this._annotation.snoozeTime; | |
| 57 if (this.isSnoozed) { | |
| 58 this.category = 'snoozed'; | |
| 59 } else if (this._isTreeCloser()) { | |
| 60 this.category = 'treeCloser'; | |
| 61 } else if (this._failedOnce()) { | |
| 62 this.category = 'failedOnce'; | |
| 63 } else { | |
| 64 this.category = this._originalCategory; | |
| 65 } | |
| 66 | |
| 67 this.bug = this._annotation.bug; | |
| 68 // FIXME: Bug labels would be simpler to implement as a filter in the UI. | |
| 69 if (this.bug != null) | |
| 70 this.bugLabel = 'Bug ' + /([0-9]{3,})/.exec(this.bug)[0]; | |
| 71 else | |
| 72 this.bugLabel = undefined; | |
| 73 }; | |
| 74 | |
| 75 CTFailureGroup._mergeAnnotations = function(failureAnnotations) { | |
| 76 // FIXME: This should be a union of all bugs. | |
| 77 var bug = failureAnnotations.map('bug').compact().first(); | |
| 78 | |
| 79 // The group is only snoozed if all the failures specify a snooze-time, and on
ly | |
| 80 // until the first has elapsed. | |
| 81 var snoozeTimes = failureAnnotations.map('snoozeTime').compact(); | |
| 82 var snoozeTime = snoozeTimes.length < failureAnnotations.length ? undefined :
snoozeTimes.min(); | |
| 83 | |
| 84 var annotation = {}; | |
| 85 if (bug != null) { | |
| 86 annotation.bug = bug; | |
| 87 } | |
| 88 if (snoozeTime != null) { | |
| 89 annotation.snoozeTime = snoozeTime; | |
| 90 } | |
| 91 return annotation; | |
| 92 }; | |
| 93 | |
| 94 CTFailureGroup.prototype._annotate = function(newAnnotation) { | |
| 95 var failureAnnotations = []; | |
| 96 // FIXME: Post the new annotation to frontend rather than storing locally. | |
| 97 return CTFailureGroup.fetchAnnotations().then(function(annotations) { | |
| 98 this.data.failureKeys().forEach(function(failureKey) { | |
| 99 var annotation = annotations[failureKey] || {}; | |
| 100 | |
| 101 Object.keys(newAnnotation, function(key, value) { | |
| 102 if (value === undefined) { | |
| 103 delete annotation[key]; | |
| 104 } else { | |
| 105 annotation[key] = value; | |
| 106 } | |
| 107 }); | |
| 108 | |
| 109 if (Object.size(annotation) == 0) { | |
| 110 delete annotations[failureKey]; | |
| 111 } else { | |
| 112 annotations[failureKey] = annotation; | |
| 113 failureAnnotations.push(annotation); | |
| 114 } | |
| 115 }); | |
| 116 | |
| 117 localStorage.CTFailureGroupAnnotations = JSON.stringify(annotations); | |
| 118 this._annotation = CTFailureGroup._mergeAnnotations(failureAnnotations); | |
| 119 this._computeProperties(); | |
| 120 }.bind(this)); | |
| 121 }; | |
| 122 | |
| 123 CTFailureGroup.fetchAnnotations = function() { | |
| 124 // FIXME: Fetch annotations from frontend. | |
| 125 var stored = localStorage.CTFailureGroupAnnotations; | |
| 126 var annotations = stored ? JSON.parse(stored) : {}; | |
| 127 return Promise.resolve(annotations); | |
| 128 }; | |
| 129 </script> | |
| OLD | NEW |