Completed
Push — master ( 9017a1...3ff80b )
by Tomáš
04:23
created

GihubPublishingProcess::runScript()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
ccs 6
cts 6
cp 1
cc 2
eloc 5
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\PHP7_Sculpin\Github;
11
12
use GitWrapper\GitWrapper;
13
use Symplify\PHP7_Sculpin\Utils\FilesystemChecker;
14
15
final class GihubPublishingProcess
16
{
17
    /**
18
     * @var string
19
     */
20
    const CONFIG_EMAIL = '[email protected]';
21
22
    /**
23
     * @var string
24
     */
25
    const CONFIG_NAME = 'Travis';
26
27 2
    public function pushDirectoryContentToRepository(string $outputDirectory, string $githubRepository)
28
    {
29 2
        FilesystemChecker::ensureDirectoryExists($outputDirectory);
30
31 1
        $git = (new GitWrapper())->init($outputDirectory);
32
33 1
        if (getenv('TRAVIS')) {
34 1
            $git->config('user.email', self::CONFIG_EMAIL);
35 1
            $git->config('user.name', self::CONFIG_NAME);
36
        }
37
38 1
        $git->checkout('gh-pages', [
39 1
            'orphan' => true,
40
        ]);
41 1
        $git->add('.');
42 1
        $git->commit('Regenerate output');
43 1
        $git->addRemote('origin', $githubRepository);
44
        $git->push('origin', 'gh-pages', [
45
            'force' => true,
46
            'quiet' => true,
47
        ]);
48
    }
49
}
50