• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

screwdriver-cd / screwdriver / #3202

25 Jul 2025 04:52PM UTC coverage: 67.669% (-27.3%) from 94.935%
#3202

push

screwdriver

web-flow
feat(3363): Update the existing endpoint to get admin for a pipeline from the specified SCM context (#3370)

1284 of 2114 branches covered (60.74%)

Branch coverage included in aggregate %.

1 of 11 new or added lines in 1 file covered. (9.09%)

1235 existing lines in 49 files now uncovered.

3417 of 4833 relevant lines covered (70.7%)

50.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

15.49
/plugins/pipelines/listEvents.js
1
'use strict';
2

3
const boom = require('@hapi/boom');
1✔
4
const joi = require('joi');
1✔
5
const schema = require('screwdriver-data-schema');
1✔
6
const eventListSchema = joi.array().items(schema.models.event.get).label('List of events');
1✔
7
const prNumSchema = schema.models.event.base.extract('prNum');
1✔
8
const shaSchema = joi
1✔
9
    .string()
10
    .hex()
11
    .max(40)
12
    .description('SHA or partial SHA')
13
    .example('ccc49349d3cffbd12ea9e3d41521480b4aa5de5f');
14
const typeSchema = schema.models.event.base.extract('type');
1✔
15
const pipelineIdSchema = schema.models.pipeline.base.extract('id');
1✔
16
const INEQUALITY_SIGNS = /^(gt|lt):([\d]+)$/;
1✔
17
const queryIdSchema = joi
1✔
18
    .alternatives()
19
    .try(pipelineIdSchema, joi.string().regex(INEQUALITY_SIGNS))
20
    .description('Event ID; alternatively can use greater than or less than prefix (gt:/lt:)')
21
    .example('gt:12345');
22

23
module.exports = () => ({
434✔
24
    method: 'GET',
25
    path: '/pipelines/{id}/events',
26
    options: {
27
        description: 'Get pipeline type events for this pipeline',
28
        notes: 'Returns pipeline events for the given pipeline',
29
        tags: ['api', 'pipelines', 'events'],
30
        auth: {
31
            strategies: ['token'],
32
            scope: ['user', 'build', 'pipeline']
33
        },
34

35
        handler: async (request, h) => {
UNCOV
36
            const factory = request.server.app.pipelineFactory;
×
UNCOV
37
            const { page, count, sha, prNum, id, sort, sortBy, groupEventId, message, author, creator } = request.query;
×
38

UNCOV
39
            return factory
×
40
                .get(request.params.id)
41
                .then(pipeline => {
UNCOV
42
                    if (!pipeline) {
×
UNCOV
43
                        throw boom.notFound('Pipeline does not exist');
×
44
                    }
45

UNCOV
46
                    const eventType = request.query.type || 'pipeline';
×
UNCOV
47
                    const config = { params: { type: eventType }, sort };
×
48

UNCOV
49
                    if (page || count) {
×
UNCOV
50
                        config.paginate = {
×
51
                            page,
52
                            count
53
                        };
54
                    }
55

UNCOV
56
                    if (sortBy) {
×
UNCOV
57
                        config.sortBy = sortBy;
×
58
                    }
59

UNCOV
60
                    if (prNum) {
×
UNCOV
61
                        config.params.type = 'pr';
×
UNCOV
62
                        config.params.prNum = prNum;
×
63
                    }
64

65
                    // Do a search
66
                    // See https://www.w3schools.com/sql/sql_like.asp for syntax
UNCOV
67
                    if (sha) {
×
UNCOV
68
                        config.search = { field: ['sha', 'configPipelineSha'], keyword: `${sha}%` };
×
UNCOV
69
                    } else if (message) {
×
UNCOV
70
                        config.search = { field: ['commit'], keyword: `%"message":"${message}%` };
×
UNCOV
71
                    } else if (author) {
×
72
                        // searches name and username
UNCOV
73
                        config.search = { field: ['commit'], keyword: `%name":"${author}%` };
×
UNCOV
74
                    } else if (creator) {
×
75
                        // searches name and username
UNCOV
76
                        let inverse = false;
×
UNCOV
77
                        let creatorName = creator;
×
78

UNCOV
79
                        if (creator.startsWith('ne:')) {
×
UNCOV
80
                            inverse = true;
×
UNCOV
81
                            creatorName = creator.substring(3); // Remove 'ne:' prefix
×
82
                        }
83

UNCOV
84
                        config.search = {
×
85
                            field: ['creator'],
86
                            keyword: `%name":"${creatorName}%`,
87
                            inverse
88
                        };
89
                    }
90

UNCOV
91
                    if (groupEventId) {
×
UNCOV
92
                        config.params.groupEventId = groupEventId;
×
93
                    }
94

95
                    // Event id filter; can use greater than(`gt:`) or less than(`lt:`) prefix
UNCOV
96
                    if (id) {
×
UNCOV
97
                        config.params.id = id;
×
98
                    }
99

UNCOV
100
                    return pipeline.getEvents(config);
×
101
                })
UNCOV
102
                .then(events => h.response(events.map(e => e.toJson())))
×
103
                .catch(err => {
UNCOV
104
                    throw err;
×
105
                });
106
        },
107
        response: {
108
            schema: eventListSchema
109
        },
110
        validate: {
111
            params: joi.object({
112
                id: pipelineIdSchema
113
            }),
114
            query: schema.api.pagination.concat(
115
                joi
116
                    .object({
117
                        type: typeSchema,
118
                        prNum: prNumSchema,
119
                        sha: shaSchema,
120
                        message: joi.string().label('Commit message').example('fix: Typo'),
121
                        author: joi.string().label('Author Name').example('Dao Lam'),
122
                        creator: joi
123
                            .string()
124
                            .label('Creator Name')
125
                            .description('Creator Name; optionally use "ne:" prefix to exclude creator')
126
                            .example('Dao Lam')
127
                            .example('ne:Dao Lam'),
128
                        id: queryIdSchema,
129
                        groupEventId: pipelineIdSchema,
130
                        search: joi.forbidden(), // we don't support search for Pipeline list events
131
                        getCount: joi.forbidden() // we don't support getCount for Pipeline list events
132
                    })
133
                    // https://joi.dev/api/?v=17.13.3#objectoxorpeers-options
134
                    .oxor('sha', 'message', 'author', 'creator')
135
                    .messages({
136
                        'object.oxor': 'You can only specify one search parameter: sha, message, author, or creator.'
137
                    })
138
            )
139
        }
140
    }
141
});
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc