Skip to content

Commit

Permalink
Merge branch 'master' into dumb-init
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yoshika authored Apr 8, 2024
2 parents 2576f69 + a39d1c2 commit 9d62f80
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
13 changes: 10 additions & 3 deletions plugins/pipelines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,17 @@ Example payload:
`POST /pipelines/{id}/sync/pullrequests`

#### Get all pipeline events
`page`, `count`, `sort`, and `prNum` are optional
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}`
Query Params:

* `page` - *Optional* Specific page of the set to return
* `count` - *Optional* Number of items per page
* `sort` - *Optional* Sort rangekey by `ascending` or `descending` (default `descending`)
* `type` - *Optional* Get pipeline or pr events (default `pipeline`)
* `prNum` - *Optional* Return only PR events of specified PR number
* `sha` - *Optional* Search `sha` and `configPipelineSha` for events

`GET /pipelines/{id}/events?page={pageNumber}&count={countNumber}&sort={sort}&type={type}&prNum={prNumber}&sha={sha}`

#### Get all pipeline builds
`page`, `count`, `sort`, `latest`, `sortBy`, `fetchSteps`, `readOnly`, and `groupEventId` are optional
Expand Down
25 changes: 19 additions & 6 deletions plugins/pipelines/listEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const joi = require('joi');
const schema = require('screwdriver-data-schema');
const eventListSchema = joi.array().items(schema.models.event.get).label('List of events');
const prNumSchema = schema.models.event.base.extract('prNum');
const shaSchema = schema.models.event.base.extract('sha');
const typeSchema = schema.models.event.base.extract('type');
const pipelineIdSchema = schema.models.pipeline.base.extract('id');

module.exports = () => ({
Expand All @@ -21,6 +23,7 @@ module.exports = () => ({

handler: async (request, h) => {
const factory = request.server.app.pipelineFactory;
const { page, count, sha, prNum } = request.query;

return factory
.get(request.params.id)
Expand All @@ -32,16 +35,25 @@ module.exports = () => ({
const eventType = request.query.type || 'pipeline';
const config = { params: { type: eventType } };

if (request.query.page || request.query.count) {
if (page || count) {
config.paginate = {
page: request.query.page,
count: request.query.count
page,
count
};
}

if (request.query.prNum) {
if (prNum) {
config.params.type = 'pr';
config.params.prNum = request.query.prNum;
config.params.prNum = prNum;
}

if (sha) {
config.search = {
field: ['sha', 'configPipelineSha'],
// Do a search for sha
// See https://www.w3schools.com/sql/sql_like.asp for syntax
keyword: `${sha}%`
};
}

return pipeline.getEvents(config);
Expand All @@ -60,8 +72,9 @@ module.exports = () => ({
}),
query: schema.api.pagination.concat(
joi.object({
type: joi.string(),
type: typeSchema,
prNum: prNumSchema,
sha: shaSchema,
search: joi.forbidden(), // we don't support search for Pipeline list events
getCount: joi.forbidden() // we don't support getCount for Pipeline list events
})
Expand Down
17 changes: 16 additions & 1 deletion test/plugins/pipelines.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ describe('pipeline plugin test', () => {
});
});

it('returns 200 for getting events with pr Number', () => {
it('returns 200 for getting events with pr number', () => {
options.url = `/pipelines/${id}/events?prNum=4`;
server.inject(options).then(reply => {
assert.calledOnce(pipelineMock.getEvents);
Expand All @@ -1495,6 +1495,21 @@ describe('pipeline plugin test', () => {
});
});

it('returns 200 for getting events with sha', () => {
options.url = `/pipelines/${id}/events?sha=ccc49349d3cffbd12ea9e3d41521480b4aa5de5f`;
server.inject(options).then(reply => {
assert.calledOnce(pipelineMock.getEvents);
assert.calledWith(pipelineMock.getEvents, {
search: {
field: ['sha', 'configPipelineSha'],
keyword: 'ccc49349d3cffbd12ea9e3d41521480b4aa5de5f%'
}
});
assert.deepEqual(reply.result, testEvents);
assert.equal(reply.statusCode, 200);
});
});

it('returns 404 for pipeline that does not exist', () => {
pipelineFactoryMock.get.resolves(null);

Expand Down

0 comments on commit 9d62f80

Please sign in to comment.