-
Notifications
You must be signed in to change notification settings - Fork 168
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5451c20
feat: Add pipelines/id/builds endpoint
tkyi 77b713a
Merge branch 'master' into groupEventBuilds
tkyi 4afe6b5
fix: add more options to listBuilds endpoint
tkyi a893b76
Merge branch 'master' into groupEventBuilds
tkyi f3477b9
Merge branch 'master' into groupEventBuilds
tkyi 4e01c3a
fix: README
tkyi 041ec07
fix: response validation
tkyi ce289ad
Merge branch 'master' into groupEventBuilds
tkyi 8dfefa9
Merge branch 'master' into groupEventBuilds
tkyi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,12 @@ Only PR events of specified PR number will be searched when `prNum` is set | |
|
||
`GET /pipelines/{id}/events?page={pageNumber}&count={countNumber}&sort={sort}&prNum={prNumber}` | ||
|
||
#### Get all pipeline builds | ||
`page`, `count`, `sort`, `latest`, `sortBy`, `fetchSteps`, `readOnly`, and `groupEventId` are optional | ||
When `latest=true` and `groupEventId` is set, only latest builds in a pipeline based on groupEventId will be returned. `latest` and `groupEventId` must be set together | ||
|
||
`GET /pipelines/{id}/builds?page={pageNumber}&count={countNumber}&sort={sort}&latest=true&groupEventId={groupEventId}&sortBy={sortBy}&fetchSteps=false&readOnly=false` | ||
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.
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. yes |
||
|
||
#### Get all jobs (including pull requests jobs) | ||
`archived` is optional and has a default value of `false`, which makes the endpoint not return archived jobs (e.g. closed pull requests) | ||
|
||
|
@@ -380,4 +386,4 @@ Example payload: | |
{ | ||
"trusted": true | ||
} | ||
``` | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
'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; | ||
const { sort, sortBy, page, count, fetchSteps, readOnly, groupEventId, latest } = request.query; | ||
|
||
return factory | ||
.get(request.params.id) | ||
.then(pipeline => { | ||
if (!pipeline) { | ||
throw boom.notFound('Pipeline does not exist'); | ||
} | ||
|
||
const config = readOnly | ||
? { sort, sortBy: 'createTime', readOnly: true } | ||
: { sort, sortBy: 'createTime' }; | ||
|
||
if (sortBy) { | ||
config.sortBy = sortBy; | ||
} | ||
|
||
if (page || count) { | ||
config.paginate = { page, count }; | ||
} | ||
|
||
if (groupEventId) { | ||
config.params = { | ||
...config.params, | ||
groupEventId | ||
}; | ||
|
||
// Latest flag only works in conjunction with groupEventId | ||
if (latest) { | ||
config.params.latest = latest; | ||
} | ||
} | ||
|
||
return pipeline.getBuilds(config); | ||
}) | ||
.then(async builds => { | ||
let data; | ||
|
||
if (fetchSteps) { | ||
data = await Promise.all(builds.map(b => b.toJsonWithSteps())); | ||
} else { | ||
data = await Promise.all(builds.map(b => b.toJson())); | ||
} | ||
|
||
return h.response(data); | ||
}) | ||
.catch(err => { | ||
throw err; | ||
}); | ||
}, | ||
response: { | ||
schema: buildListSchema | ||
}, | ||
validate: { | ||
params: joi.object({ | ||
id: pipelineIdSchema | ||
}), | ||
query: schema.api.pagination.concat( | ||
joi.object({ | ||
readOnly: joi.boolean().truthy('true').falsy('false').default(true), | ||
fetchSteps: joi.boolean().truthy('true').falsy('false').default(true), | ||
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 | ||
}) | ||
) | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.