• 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

14.58
/plugins/pipelines/helper.js
1
'use strict';
2

3
const schema = require('screwdriver-data-schema');
1✔
4
const { makeBadge } = require('badge-maker');
1✔
5

6
/**
7
 * Format the scm url to include a branch and make case insensitive
8
 * @method formatCheckoutUrl
9
 * @param  {String}     checkoutUrl     Checkout url (ex: git@github.com:screwdriver-cd/screwdriver.git#branchName)
10
 *                                      or (ex: https://github.com/screwdriver-cd/screwdriver.git#branchName)
11
 * @return {String}                     Lowercase scm url with branch name
12
 */
13
const formatCheckoutUrl = checkoutUrl => {
1✔
UNCOV
14
    let result = checkoutUrl;
×
UNCOV
15
    const MATCH_COMPONENT_BRANCH_NAME = 4;
×
UNCOV
16
    const matched = schema.config.regex.CHECKOUT_URL.exec(result);
×
UNCOV
17
    const branchName = matched[MATCH_COMPONENT_BRANCH_NAME];
×
18

19
    // Check if branch name exists
20
    // Do not convert branch name to lowercase
UNCOV
21
    if (branchName) {
×
UNCOV
22
        result = result.split('#')[0].toLowerCase().concat(branchName);
×
23
    } else {
UNCOV
24
        result = result.toLowerCase();
×
25
    }
26

UNCOV
27
    return result;
×
28
};
29

30
/**
31
 * Get rid of leading/trailing slashes in rootDir, return empty string as default
32
 * @method sanitizeRootDir
33
 * @param  {String}     rootDir     Root directory (ex: /src/component/app/ or /)
34
 * @return {String}                 Root dir with no leading/trailing slashes
35
 */
36
const sanitizeRootDir = (rootDir = '') => {
1!
UNCOV
37
    return rootDir.replace(/^(\/+|\.\/|\.\.\/)|\/+$/g, '');
×
38
};
39

40
/**
41
 * Generate Badge for pipeline
42
 * @method getPipelineBadge
43
 * @param  {Object} statusColor             Mapping for status and color
44
 * @param  {Array}  [buildsStatus=[]]       An array of builds
45
 * @param  {String} [label='pipeline']         Subject of the badge
46
 * @return {String}
47
 */
48
const getPipelineBadge = ({ statusColor, buildsStatus = [], label = 'pipeline' }) => {
1!
UNCOV
49
    const counts = {};
×
UNCOV
50
    const parts = [];
×
UNCOV
51
    let worst = 'lightgrey';
×
52

UNCOV
53
    const levels = Object.keys(statusColor);
×
54

UNCOV
55
    buildsStatus.forEach(status => {
×
UNCOV
56
        counts[status] = (counts[status] || 0) + 1;
×
57
    });
58

UNCOV
59
    levels.forEach(status => {
×
UNCOV
60
        if (counts[status]) {
×
UNCOV
61
            parts.push(`${counts[status]} ${status}`);
×
UNCOV
62
            worst = statusColor[status];
×
63
        }
64
    });
65

UNCOV
66
    return makeBadge({
×
67
        label,
68
        message: parts.length > 0 ? parts.join(', ') : 'unknown',
×
69
        color: worst
70
    });
71
};
72

73
/**
74
 * Generate Badge for Job
75
 * @method getJobBadge
76
 * @param  {Object} statusColor             Mapping for status and color
77
 * @param  {Array}  [builds=[]]       An array of builds
78
 * @param  {String} [label='job']         Subject of the badge
79
 * @return {String}
80
 */
81
const getJobBadge = ({ statusColor, builds = [], label = 'job' }) => {
1!
UNCOV
82
    let color = 'lightgrey';
×
UNCOV
83
    let status = 'unknown';
×
84

UNCOV
85
    if (builds.length > 0) {
×
UNCOV
86
        status = builds[0].status.toLowerCase();
×
UNCOV
87
        color = statusColor[status];
×
88
    }
89

UNCOV
90
    return makeBadge({
×
91
        label,
92
        message: status,
93
        color
94
    });
95
};
96

97
module.exports = {
1✔
98
    formatCheckoutUrl,
99
    getJobBadge,
100
    getPipelineBadge,
101
    sanitizeRootDir
102
};
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