-
Notifications
You must be signed in to change notification settings - Fork 168
/
listTriggers.js
54 lines (50 loc) · 1.7 KB
/
listTriggers.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
'use strict';
const boom = require('boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const { EXTERNAL_TRIGGER, JOB_NAME } = schema.config.regex;
const pipelineIdSchema = joi.reach(schema.models.pipeline.base, 'id');
const destSchema = joi.string().regex(EXTERNAL_TRIGGER).max(64);
const triggerListSchema = joi.array().items(joi.object({
jobName: JOB_NAME,
triggers: joi.array().items(destSchema)
})).label('List of triggers');
module.exports = () => ({
method: 'GET',
path: '/pipelines/{id}/triggers',
config: {
description: 'Get all jobs for a given pipeline',
notes: 'Returns all jobs for a given pipeline',
tags: ['api', 'pipelines', 'jobs'],
auth: {
strategies: ['token'],
scope: ['user', 'build', 'pipeline']
},
plugins: {
'hapi-swagger': {
security: [{ token: [] }]
}
},
handler: (request, reply) => {
const { pipelineFactory, triggerFactory } = request.server.app;
const pipelineId = request.params.id;
return pipelineFactory.get(pipelineId)
.then((pipeline) => {
if (!pipeline) {
throw boom.notFound('Pipeline does not exist');
}
return triggerFactory.getTriggers({ pipelineId });
})
.then(triggers => reply(triggers))
.catch(err => reply(boom.boomify(err)));
},
response: {
schema: triggerListSchema
},
validate: {
params: {
id: pipelineIdSchema
}
}
}
});