-
Notifications
You must be signed in to change notification settings - Fork 282
Expand file tree
/
Copy pathsettings.js
More file actions
89 lines (78 loc) · 2.45 KB
/
settings.js
File metadata and controls
89 lines (78 loc) · 2.45 KB
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
import { hash } from 'rsvp';
import EmberObject from '@ember/object';
import TravisRoute from 'travis/routes/basic';
import config from 'travis/config/environment';
import { inject as service } from '@ember/service';
export default TravisRoute.extend({
api: service(),
auth: service(),
permissions: service(),
raven: service(),
flashes: service(),
needsAuth: true,
setupController(controller, model) {
this._super(...arguments);
controller.set('repo', this.modelFor('repo'));
this.controllerFor('repo').activate('settings');
return controller.set('concurrentBuildsLimit', !!model.settings.maximum_number_of_builds);
},
fetchEnvVars() {
const repo = this.modelFor('repo');
return repo.get('envVars.promise');
},
fetchCustomSshKey() {
if (config.endpoints.sshKey) {
const repo = this.modelFor('repo');
return this.store.find('ssh_key', repo.get('id')).then(((result) => {
if (!result.get('isNew')) {
return result;
}
}), (xhr) => {
if (xhr.status === 404) {
return false;
}
});
}
},
fetchSshKey() {
if (config.endpoints.sshKey) {
const repo = this.modelFor('repo');
if (repo.serverType === 'perforce') return;
const url = `/repos/${repo.get('id')}/key`;
return this.api.get(url, { travisApiVersion: null }).then((data) => {
const fingerprint = EmberObject.create({
fingerprint: data.fingerprint
});
return fingerprint;
}).catch(e => {
// 404s happen regularly and are unremarkable
if (e.status !== 404) {
this.raven.logException(e);
}
});
}
},
fetchRepositoryActiveFlag() {
const repoId = this.modelFor('repo').get('id');
return this.api.get(`/repo/${repoId}`).then(response => response.active);
},
beforeModel() {
const repo = this.modelFor('repo');
if (!repo.permissions.settings_read) {
this.transitionTo('repo.index');
this.flashes.error('Your permissions are insufficient to access this repository\'s settings');
}
},
model() {
const repo = this.modelFor('repo');
return hash({
settings: repo.fetchSettings.perform(),
repository: repo,
envVars: this.fetchEnvVars(),
sshKey: this.fetchSshKey(),
customSshKey: this.fetchCustomSshKey(),
hasPushAccess: this.permissions.hasPushPermission(repo),
repositoryActive: this.fetchRepositoryActiveFlag()
});
}
});