This repository has been archived by the owner on Jan 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Build.js
121 lines (118 loc) · 4.04 KB
/
Build.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
define([
'jquery',
'ember-model',
'models/TravisModel',
'ext/DurationCalculations',
'ext/Helpers',
'ext/TravisAjax',
'app/utils'
], function ($, Ember, TravisModel, DurationCalculations, Helpers, TravisAjax, utils) {
var Build = TravisModel.extend(DurationCalculations, {
repositoryId : Ember.attr('number'),
commitId : Ember.attr('number'),
state : Ember.attr('string'),
number : Ember.attr(Number),
branch : Ember.attr('string'),
message : Ember.attr('string'),
_duration : Ember.attr(Number, {key: 'duration'}),
_config : Ember.attr('object', {key: 'config'}),
startedAt : Ember.attr('string'),
finishedAt : Ember.attr('string'),
pullRequest : Ember.attr('boolean'),
pullRequestTitle : Ember.attr('string'),
pullRequestNumber : Ember.attr(Number),
repo : Ember.belongsTo('App.Repo', {key: 'repository_id'}),
commit : Ember.belongsTo('App.Commit'),
jobs : Ember.hasMany('App.Job'),
config : function () {
return Helpers.compact(this.get('_config'));
}.property('_config'),
isPullRequest : function () {
return this.get('eventType') === 'pull_request' || this.get('pullRequest');
}.property('eventType'),
isMatrix : function () {
return this.get('jobs.length') > 1;
}.property('jobs.length'),
isFinished : function () {
var _ref;
return (_ref = this.get('state')) === 'passed' || _ref === 'failed' || _ref === 'errored' || _ref === 'canceled';
}.property('state'),
requiredJobs : function () {
return this.get('jobs').filter(function (data) {
return !data.get('allowFailure');
});
}.property('jobs.@each.allowFailure'),
allowedFailureJobs : function () {
return this.get('jobs').filter(function (data) {
return data.get('allowFailure');
});
}.property('jobs.@each.allowFailure'),
configKeys : function () {
var config, headers, keys;
if (!(config = this.get('config'))) {
return [];
}
keys = $.intersect($.keys(config), Helpers.CONFIG_KEYS);
headers = (function () {
// var _i, _len, _ref, _results;
// _ref = ['build.job', 'build.duration', 'build.finished_at'];
// _results = [];
// for (_i = 0, _len = _ref.length; _i < _len; _i++) {
// key = _ref[_i];
// _results.push(I18n.t(key));
// }
// return _results;
return ['Job', 'Duration, Finished'];
})();
return $.map(headers.concat(keys), function (key) {
return $.camelize(key);
});
}.property('config'),
canCancel : function () {
return this.get('state') === 'created';
}.property('state'),
cancel : function () {
return TravisAjax.post("/builds/" + (this.get('id')), {
_method : 'delete'
});
},
requeue : function () {
return TravisAjax.post('/requests', {
build_id : this.get('id')
});
},
isPropertyLoaded : function (key) {
if (['_duration', 'finishedAt'].contains(key) && !this.get('isFinished')) {
return true;
} else {
return this._super(key);
}
}
});
Build.reopenClass({
byRepoId : function (id, parameters) {
return this.find($.extend(parameters || {}, {
repository_id : id
}));
},
branches : function (options) {
return this.find({
repository_id : options.repoId,
branches : true
});
},
olderThanNumber : function (id, build_number, type) {
var options;
utils.debug(type);
options = {
repository_id : id,
after_number : build_number
};
if (type != null) {
options.event_type = type.replace(/s$/, '');
}
return this.find(options);
}
});
return Build;
});