-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add pipelines/id/builds endpoint [2] #3070
Changes from 2 commits
5451c20
77b713a
4afe6b5
a893b76
f3477b9
4e01c3a
041ec07
ce289ad
8dfefa9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
'use strict'; | ||
|
||
const boom = require('@hapi/boom'); | ||
const joi = require('joi'); | ||
const schema = require('screwdriver-data-schema'); | ||
const buildListSchema = joi.array().items(schema.models.build.get).label('List of builds'); | ||
const groupEventIdSchema = schema.models.event.base.extract('groupEventId'); | ||
const pipelineIdSchema = schema.models.pipeline.base.extract('id'); | ||
|
||
module.exports = () => ({ | ||
method: 'GET', | ||
path: '/pipelines/{id}/builds', | ||
options: { | ||
description: 'Get builds for this pipeline', | ||
notes: 'Returns builds for the given pipeline', | ||
tags: ['api', 'pipelines', 'builds'], | ||
auth: { | ||
strategies: ['token'], | ||
scope: ['user', 'build', 'pipeline'] | ||
}, | ||
|
||
handler: async (request, h) => { | ||
const factory = request.server.app.pipelineFactory; | ||
|
||
return factory | ||
.get(request.params.id) | ||
.then(pipeline => { | ||
if (!pipeline) { | ||
throw boom.notFound('Pipeline does not exist'); | ||
} | ||
|
||
const config = {}; | ||
|
||
if (request.query.page || request.query.count) { | ||
config.paginate = { | ||
page: request.query.page, | ||
count: request.query.count | ||
}; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have a default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. put the default paginate in models |
||
|
||
if (request.query.groupEventId) { | ||
config.params = { | ||
...config.params, | ||
groupEventId: request.query.groupEventId | ||
}; | ||
|
||
// Latest flag only works in conjunction with groupEventId | ||
if (request.query.latest) { | ||
config.params.latest = request.query.latest; | ||
} | ||
} | ||
|
||
return pipeline.getBuilds(config); | ||
}) | ||
.then(builds => h.response(builds.map(b => b.toJson()))) | ||
.catch(err => { | ||
throw err; | ||
}); | ||
}, | ||
response: { | ||
schema: buildListSchema | ||
}, | ||
validate: { | ||
params: joi.object({ | ||
id: pipelineIdSchema | ||
}), | ||
query: schema.api.pagination.concat( | ||
joi.object({ | ||
groupEventId: groupEventIdSchema, | ||
latest: joi.boolean().truthy('true').falsy('false').default(false), | ||
search: joi.forbidden(), // we don't support search for Pipeline list builds | ||
getCount: joi.forbidden() // we don't support getCount for Pipeline list builds | ||
}) | ||
) | ||
} | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.