screwdriver-api
Version:
API server for the Screwdriver.cd service
59 lines (53 loc) • 1.73 kB
JavaScript
;
const boom = require('@hapi/boom');
const joi = require('joi');
const schema = require('screwdriver-data-schema');
const { JOB_NAME } = schema.config.regex;
const pipelineIdSchema = schema.models.pipeline.base.extract('id');
const destSchema = schema.models.trigger.base.extract('dest');
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',
options: {
description: 'Get all triggers for a given pipeline',
notes: 'Returns all triggers for a given pipeline',
tags: ['api', 'pipelines', 'triggers'],
auth: {
strategies: ['token'],
scope: ['user', 'build', 'pipeline']
},
handler: async (request, h) => {
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 => h.response(triggers))
.catch(err => {
throw err;
});
},
response: {
schema: triggerListSchema
},
validate: {
params: joi.object({
id: pipelineIdSchema
})
}
}
});