All files build-requests.js

92.86% Statements 13/14
50% Branches 3/6
85.71% Functions 6/7
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37  1x 1x 1x 1x 1x 1x   3x 1x   1x       1x       1x                             1x    
export default function buildRequests({projectId, repoName, requiredImages}) {
    const requests = [];
    requiredImages.forEach(({branch, commitSha, image, build}) => {
        let request = findRequest(requests, {branch, commitSha});
        Eif (!request) {
            request = newBuildRequest({projectId, repoName, branch, commitSha});
            requests.push(request);
        }
        build.steps.forEach(step => request.steps.push(step));
        request.images.push(formatImage(image));
    });
    return requests;
}
 
function findRequest(requests, {branch, commitSha}) {
    return requests.filter(({source: {repoSource}}) => repoSource.branch === branch || repoSource.commitSha === commitSha)[0] || null;
}
 
function newBuildRequest({projectId, repoName, branch, commitSha}) {
    return {
        source: {
            repoSource: {
                projectId,
                repoName,
                branch,
                commitSha,
            }
        },
        steps: [],
        images: [],
    };
}
 
function formatImage({registry, namespace, repository, tag}) {
    return `${registry}/${namespace}/${repository}:${tag}`;
}