OLD | NEW |
1 <!-- | 1 <!-- |
2 Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 3 Use of this source code is governed by a BSD-style license that can be |
4 found in the LICENSE file. | 4 found in the LICENSE file. |
5 --> | 5 --> |
6 | 6 |
7 <link rel="import" href="ct-commit-list.html"> | 7 <link rel="import" href="ct-commit-list.html"> |
8 | 8 |
9 <script> | 9 <script> |
10 function CTFailureGroup(key, failures, annotation) { | 10 function CTFailureGroup(key, failures, annotation) { |
11 this.key = key; | 11 this.key = key; |
12 this.failures = failures; | 12 this.failures = failures; |
13 this.annotation = annotation || {}; | 13 this._annotation = annotation || {}; |
14 this._computeProperties(); | 14 this._computeProperties(); |
15 } | 15 } |
16 | 16 |
17 CTFailureGroup.prototype.snoozeUntil = function(time) { | 17 CTFailureGroup.prototype.snoozeUntil = function(time) { |
18 return this._annotate({ | 18 return this._annotate({ |
19 snoozeTime: time, | 19 snoozeTime: time, |
20 }); | 20 }); |
21 }; | 21 }; |
22 | 22 |
23 CTFailureGroup.prototype.unsnooze = function() { | 23 CTFailureGroup.prototype.unsnooze = function() { |
24 return this._annotate({ | 24 return this._annotate({ |
25 snoozeTime: undefined, | 25 snoozeTime: undefined, |
26 }); | 26 }); |
27 }; | 27 }; |
28 | 28 |
29 CTFailureGroup.prototype.commitList = function(commits) { | 29 CTFailureGroup.prototype.commitList = function(commits) { |
30 return new CTCommitList(this, commits); | 30 return new CTCommitList(this, commits); |
31 }; | 31 }; |
32 | 32 |
| 33 CTFailureGroup.prototype.setBug = function(bug) { |
| 34 if (/^[0-9]+$/.test(bug)) |
| 35 bug = 'http://crbug.com/' + bug; |
| 36 return this._annotate({ |
| 37 bug: bug, |
| 38 }); |
| 39 }; |
| 40 |
33 CTFailureGroup.prototype._computeProperties = function() { | 41 CTFailureGroup.prototype._computeProperties = function() { |
34 this.isSnoozed = Date.now() < this.annotation.snoozeTime; | 42 this.isSnoozed = Date.now() < this._annotation.snoozeTime; |
35 if (this.isSnoozed) { | 43 if (this.isSnoozed) { |
36 this.category = 'snoozed'; | 44 this.category = 'snoozed'; |
37 } else { | 45 } else { |
38 // FIXME: crbug.com/400397 Split into: Whole step failure, Tree closer, Test
failure, Flaky tests | 46 // FIXME: crbug.com/400397 Split into: Whole step failure, Tree closer, Test
failure, Flaky tests |
39 this.category = 'default'; | 47 this.category = 'default'; |
40 } | 48 } |
| 49 |
| 50 this.bug = this._annotation.bug; |
| 51 if (this.bug !== undefined) |
| 52 this.bugLabel = 'Bug ' + /([0-9]{3,})/.exec(this.bug)[0]; |
| 53 else |
| 54 this.bugLabel = undefined; |
41 }; | 55 }; |
42 | 56 |
43 CTFailureGroup.prototype._annotate = function(newAnnotation) { | 57 CTFailureGroup.prototype._annotate = function(newAnnotation) { |
44 // FIXME: Post the new annotation to frontend rather than storing locally. | 58 // FIXME: Post the new annotation to frontend rather than storing locally. |
45 return CTFailureGroup.fetchAnnotations().then(function(annotations) { | 59 return CTFailureGroup.fetchAnnotations().then(function(annotations) { |
46 var annotation = annotations[this.key] || {}; | 60 var annotation = annotations[this.key] || {}; |
47 | 61 |
48 Object.keys(newAnnotation, function(key, value) { | 62 Object.keys(newAnnotation, function(key, value) { |
49 if (value === 'undefined') { | 63 if (value === 'undefined') { |
50 delete annotation[key]; | 64 delete annotation[key]; |
51 } else { | 65 } else { |
52 annotation[key] = value; | 66 annotation[key] = value; |
53 } | 67 } |
54 }); | 68 }); |
55 | 69 |
56 if (Object.size(annotation) == 0) { | 70 if (Object.size(annotation) == 0) { |
57 delete annotations[this.key]; | 71 delete annotations[this.key]; |
58 } else { | 72 } else { |
59 annotations[this.key] = annotation; | 73 annotations[this.key] = annotation; |
60 } | 74 } |
61 | 75 |
62 localStorage.CTFailureGroupAnnotations = JSON.stringify(annotations); | 76 localStorage.CTFailureGroupAnnotations = JSON.stringify(annotations); |
63 | 77 |
64 this.annotation = annotation; | 78 this._annotation = annotation; |
65 this._computeProperties(); | 79 this._computeProperties(); |
66 }.bind(this)); | 80 }.bind(this)); |
67 }; | 81 }; |
68 | 82 |
69 CTFailureGroup.fetchAnnotations = function() { | 83 CTFailureGroup.fetchAnnotations = function() { |
70 // FIXME: Fetch annotations from frontend. | 84 // FIXME: Fetch annotations from frontend. |
71 var stored = localStorage.CTFailureGroupAnnotations; | 85 var stored = localStorage.CTFailureGroupAnnotations; |
72 var annotations = stored ? JSON.parse(stored) : {}; | 86 var annotations = stored ? JSON.parse(stored) : {}; |
73 return Promise.resolve(annotations); | 87 return Promise.resolve(annotations); |
74 }; | 88 }; |
75 </script> | 89 </script> |
OLD | NEW |