• 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

18.92
/plugins/pipelines/badge.js
1
'use strict';
2

3
const joi = require('joi');
1✔
4
const schema = require('screwdriver-data-schema');
1✔
5
const idSchema = schema.models.pipeline.base.extract('id');
1✔
6
const logger = require('screwdriver-logger');
1✔
7
const { getPipelineBadge } = require('./helper');
1✔
8
const BUILD_META_KEYWORD = '%"build":%';
1✔
9

10
module.exports = config => ({
434✔
11
    method: 'GET',
12
    path: '/pipelines/{id}/badge',
13
    options: {
14
        description: 'Get a badge for the pipeline',
15
        notes: 'Redirects to the badge service',
16
        tags: ['api', 'pipelines', 'badge'],
17
        plugins: {
18
            'hapi-rate-limit': {
19
                enabled: false
20
            }
21
        },
22
        handler: async (request, h) => {
UNCOV
23
            const { pipelineFactory, eventFactory } = request.server.app;
×
UNCOV
24
            const pipelineId = request.params.id;
×
UNCOV
25
            const { statusColor } = config;
×
UNCOV
26
            const badgeConfig = {
×
27
                statusColor
28
            };
UNCOV
29
            const contentType = 'image/svg+xml;charset=utf-8';
×
30

UNCOV
31
            try {
×
32
                // Get pipeline
UNCOV
33
                const pipeline = await pipelineFactory.get(pipelineId);
×
34

UNCOV
35
                if (!pipeline) {
×
UNCOV
36
                    return h.response(getPipelineBadge(badgeConfig)).header('Content-Type', contentType);
×
37
                }
38

39
                // Get latest pipeline events
UNCOV
40
                const latestEvents = await eventFactory.list({
×
41
                    params: {
42
                        pipelineId,
43
                        type: 'pipeline'
44
                    },
45
                    // Make sure build exists for event, meta will be {} for skipped builds
46
                    search: {
47
                        field: 'meta',
48
                        keyword: BUILD_META_KEYWORD
49
                    },
50
                    // removing these fields trims most of the bytes
51
                    exclude: ['workflowGraph', 'meta', 'commit'],
52
                    paginate: {
53
                        count: 1
54
                    },
55
                    sort: 'descending',
56
                    sortBy: 'createTime'
57
                });
58

UNCOV
59
                if (!latestEvents || Object.keys(latestEvents).length === 0) {
×
UNCOV
60
                    return h.response(getPipelineBadge(badgeConfig)).header('Content-Type', contentType);
×
61
                }
62

63
                // Only care about latest
UNCOV
64
                const lastEvent = latestEvents[0];
×
UNCOV
65
                const builds = await lastEvent.getBuilds({ readOnly: true, sortBy: 'id', sort: 'descending' });
×
66

UNCOV
67
                if (!builds || builds.length < 1) {
×
UNCOV
68
                    return h.response(getPipelineBadge(badgeConfig)).header('Content-Type', contentType);
×
69
                }
70

71
                // Convert build statuses
UNCOV
72
                const buildsStatus = builds.map(build => build.status.toLowerCase());
×
73

UNCOV
74
                return h
×
75
                    .response(
76
                        getPipelineBadge(
77
                            Object.assign(badgeConfig, {
78
                                buildsStatus,
79
                                label: pipeline.name
80
                            })
81
                        )
82
                    )
83
                    .header('Content-Type', contentType);
84
            } catch (err) {
UNCOV
85
                logger.error(`Failed to get badge for pipeline:${pipelineId}: ${err.message}`);
×
86

UNCOV
87
                return h.response(getPipelineBadge(badgeConfig));
×
88
            }
89
        },
90
        validate: {
91
            params: joi.object({
92
                id: idSchema
93
            })
94
        }
95
    }
96
});
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