Passed
Push — main ( 6aef38...e372cf )
by Patrick
01:52
created

examples/php-support/1.0.0/init.js   A

Complexity

Total Complexity 7
Complexity/F 3.5

Size

Lines of Code 42
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 7
mnd 5
bc 5
fnc 2
bpm 2.5
cpm 3.5
noi 0
1
const findTestWorkflow = async function ({
2
    boost, git, libs, repository, tools 
3
}) {
4
    boost.log('finding tests workflow...');
5
6
    if (typeof boost.state.testWorkflowFile === 'string' && boost.state.testWorkflowFile.length > 0) {
7
        boost.log('found tests workflow');
8
        return boost.state.testWorkflowFile;
9
    }
10
11
    boost.state.testWorkflowFile = '';
12
13
    for (const file of libs.fs.readdirSync(repository.path + '/.github/workflows', { encoding: 'utf-8', withFileTypes: true })) {
14
        if (file.isDirectory()) {
15
            continue;
16
        }
17
18
        if (file.name.endsWith('.yml') || file.name.endsWith('.yaml')) {
19
            const data = tools.readfile(repository.path + '/.github/workflows/' + file.name);
20
            if (data.includes('test') && (data.includes('phpunit') || data.includes('pest'))) {
21
                boost.log('found tests workflow ' + file.name);
22
                boost.state.testWorkflowFile = repository.path + '/.github/workflows/' + file.name;
23
                return boost.state.testWorkflowFile;
24
            }
25
        }
26
    }
27
28
    boost.log('could not find tests workflow');
29
    return false;
30
};
31
32
/** @type {import('@/lib/Boost').BoostScriptHandler} */
33
module.exports.handler = async function (params) {
34
    params.boost.log('initializing boost...');
35
36
    params.boost.state.testWorkflowFile = '';
37
    params.boost.state.updatedComposerJson = false;
38
39
    await findTestWorkflow(params);
40
41
    params.boost.log('finished initializing boost');
42
};
43