src/lib/CodeBoost.ts   A
last analyzed

Complexity

Total Complexity 13
Complexity/F 3.25

Size

Lines of Code 56
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 13
mnd 9
bc 9
fnc 4
bpm 2.25
cpm 3.25
noi 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A CodeBoost.getBoost 0 3 1
A CodeBoost.runBoost 0 9 2
A CodeBoost.init 0 4 4
B CodeBoost.prepareRepository 0 15 6
1
import { AppSettings } from '@/lib/AppSettings';
2
import { Boost } from '@/lib/Boost';
3
import { HasLogger, LogTarget } from '@/traits/HasLogger';
4
import { HistoryManager } from '@/lib/HistoryManager';
5
import { Repository } from '@/lib/Repository';
6
import { Mixin } from 'ts-mixer';
7
8
export class CodeBoost extends Mixin(HasLogger) {
9
    protected repository!: Repository;
10
    public appSettings!: AppSettings;
11
    public historyManager!: HistoryManager;
12
    public repositoryPrepared = false;
13
14
    constructor(appSettings: AppSettings, historyManager: HistoryManager) {
15
        super();
16
        this.createLogger(<LogTarget[]>appSettings?.log_target ?? [], {});
17
        this.appSettings = appSettings;
18
        this.historyManager = historyManager;
19
    }
20
21
    public async init(repository: Repository, appSettings: AppSettings) {
22
        this.appSettings = appSettings;
23
        this.repository = repository;
24
    }
25
26
    public async prepareRepository() {
27
        if (this.repositoryPrepared) {
28
            return;
29
        }
30
31
        await this.repository?.clone();
32
        await this.repository?.prepare();
33
34
        if (this.appSettings.use_forks && !this.appSettings.dry_run) {
35
            console.log('creating fork');
36
            await this.repository?.createFork();
37
        }
38
39
        this.repositoryPrepared = true;
40
    }
41
42
    public async runBoost(boost: string | Boost, args: string[]) {
43
        boost = typeof boost === 'string' ? this.getBoost(boost) : boost;
44
45
        await boost.run(this.repository, args);
46
47
        this.log('Done.');
48
49
        return boost;
50
    }
51
52
    public getBoost(boostName: string) {
53
        return new Boost(this, `${this.appSettings.boosts_path}/${boostName}`);
54
    }
55
}
56