• 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

13.64
/plugins/pipelines/remove.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 logger = require('screwdriver-logger');
1✔
7
const idSchema = schema.models.pipeline.base.extract('id');
1✔
8

9
module.exports = () => ({
434✔
10
    method: 'DELETE',
11
    path: '/pipelines/{id}',
12
    options: {
13
        description: 'Delete a single pipeline',
14
        notes: 'Returns null if successful',
15
        tags: ['api', 'pipelines'],
16
        auth: {
17
            strategies: ['token'],
18
            scope: ['user', '!guest']
19
        },
20

21
        handler: async (request, h) => {
UNCOV
22
            const { pipelineFactory, bannerFactory } = request.server.app;
×
UNCOV
23
            const { userFactory } = request.server.app;
×
UNCOV
24
            const { username, scmContext, scmUserId } = request.auth.credentials;
×
25

26
            // Fetch the pipeline and user models
UNCOV
27
            return Promise.all([pipelineFactory.get(request.params.id), userFactory.get({ username, scmContext })])
×
28
                .then(([pipeline, user]) => {
UNCOV
29
                    if (!pipeline) {
×
UNCOV
30
                        throw boom.notFound('Pipeline does not exist');
×
31
                    }
UNCOV
32
                    if (pipeline.state === 'DELETING') {
×
UNCOV
33
                        throw boom.conflict('This pipeline is already being deleted.');
×
34
                    }
UNCOV
35
                    if (pipeline.configPipelineId && pipeline.state !== 'INACTIVE') {
×
UNCOV
36
                        throw boom.forbidden(
×
37
                            'Child pipeline can only be removed' +
38
                                ` after removing it from scmUrls in config pipeline ${pipeline.configPipelineId}`
39
                        );
40
                    }
UNCOV
41
                    if (!user) {
×
UNCOV
42
                        throw boom.notFound(`User ${username} does not exist`);
×
43
                    }
44

45
                    // ask the user for permissions on this repo
UNCOV
46
                    return (
×
47
                        user
48
                            .getPermissions(pipeline.scmUri)
49
                            // check if user has admin access
50
                            .then(permissions => {
UNCOV
51
                                if (!permissions.admin) {
×
UNCOV
52
                                    throw boom.forbidden(
×
53
                                        `User ${username} does not have admin permission for this repo`
54
                                    );
55
                                }
56
                            })
57
                            .catch(error => {
UNCOV
58
                                const scmDisplayName = bannerFactory.scm.getDisplayName({ scmContext });
×
59
                                // Lookup whether user is admin
UNCOV
60
                                const adminDetails = request.server.plugins.banners.screwdriverAdminDetails(
×
61
                                    username,
62
                                    scmDisplayName,
63
                                    scmUserId
64
                                );
65

66
                                // Allow cluster admins to remove pipeline
UNCOV
67
                                if (adminDetails.isAdmin) {
×
UNCOV
68
                                    return Promise.resolve(null);
×
69
                                }
70

UNCOV
71
                                throw boom.boomify(error, { statusCode: error.statusCode });
×
72
                            })
73
                            // user has good permissions, remove the pipeline
74
                            .then(async () => {
UNCOV
75
                                logger.info(
×
76
                                    `[Audit] user ${user.username}:${scmContext} deletes the pipeline pipelineId:${request.params.id}, scmUri:${pipeline.scmUri}.`
77
                                );
UNCOV
78
                                await pipeline.remove();
×
79
                            })
UNCOV
80
                            .then(() => h.response().code(204))
×
81
                    );
82
                })
83
                .catch(err => {
UNCOV
84
                    throw err;
×
85
                });
86
        },
87
        validate: {
88
            params: joi.object({
89
                id: idSchema
90
            })
91
        }
92
    }
93
});
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