|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MatthiasMullie\CI\Providers; |
|
4
|
|
|
|
|
5
|
|
|
use MatthiasMullie\CI\Environment; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @author Matthias Mullie <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) 2016, Matthias Mullie. All rights reserved. |
|
10
|
|
|
* @license LICENSE MIT |
|
11
|
|
|
*/ |
|
12
|
|
|
class None implements Environment |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* {@inheritdoc} |
|
16
|
|
|
*/ |
|
17
|
|
|
public static function isCurrent() |
|
18
|
|
|
{ |
|
19
|
|
|
return false; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
|
|
public function getProvider() |
|
26
|
|
|
{ |
|
27
|
|
|
return 'none'; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* {@inheritdoc} |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getRepo() |
|
34
|
|
|
{ |
|
35
|
|
|
if (!$this->isGitRepo()) { |
|
36
|
|
|
return ''; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return exec('git config --get remote.origin.url'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* {@inheritdoc} |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getSlug() |
|
46
|
|
|
{ |
|
47
|
|
|
// when using any of the popular cloud git providers (or anything that's |
|
48
|
|
|
// modeled after the same username\project model), the repo name will |
|
49
|
|
|
// likely be included in this fashion... at least we can try :) |
|
50
|
|
|
$url = $this->getRepo(); |
|
51
|
|
|
$found = preg_match('/([^:\/]+\/[^:\/]+?)(\.git|$)/', $url, $matches); |
|
52
|
|
|
|
|
53
|
|
|
return $found ? $matches[1] : ''; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getBranch() |
|
60
|
|
|
{ |
|
61
|
|
|
if (!$this->isGitRepo()) { |
|
62
|
|
|
return ''; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$branches = shell_exec('git branch'); |
|
66
|
|
|
preg_match('/^\* (.+)$/m', $branches, $branch); |
|
67
|
|
|
|
|
68
|
|
|
return isset($branch) ? $branch[1] : ''; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {@inheritdoc} |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getPullRequest() |
|
75
|
|
|
{ |
|
76
|
|
|
if (!$this->isGitRepo()) { |
|
77
|
|
|
return ''; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
$head = shell_exec('test -f .git/FETCH_HEAD && cat .git/FETCH_HEAD'); |
|
81
|
|
|
$commit = preg_quote($this->getCommit(), '/'); |
|
82
|
|
|
preg_match("/^$commit\\s+'refs\\/pull\\/(.+)\\/head'/m", $head, $match); |
|
83
|
|
|
|
|
84
|
|
|
return isset($match[1]) ? $match[1] : ''; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* {@inheritdoc} |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getCommit() |
|
91
|
|
|
{ |
|
92
|
|
|
if (!$this->isGitRepo()) { |
|
93
|
|
|
return ''; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return exec('git log --pretty=format:"%H" -1'); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* {@inheritdoc} |
|
101
|
|
|
*/ |
|
102
|
|
|
public function getAuthor() |
|
103
|
|
|
{ |
|
104
|
|
|
if (!$this->isGitRepo()) { |
|
105
|
|
|
return ''; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
return exec('git log --pretty=format:"%aN" -1'); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* {@inheritdoc} |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getAuthorEmail() |
|
115
|
|
|
{ |
|
116
|
|
|
if (!$this->isGitRepo()) { |
|
117
|
|
|
return ''; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return exec('git log --pretty=format:"%aE" -1'); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* {@inheritdoc} |
|
125
|
|
|
*/ |
|
126
|
|
|
public function getBuild() |
|
127
|
|
|
{ |
|
128
|
|
|
return ''; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @return bool |
|
133
|
|
|
*/ |
|
134
|
|
|
protected function isGitRepo() |
|
135
|
|
|
{ |
|
136
|
|
|
exec('git status 2>&1', $output, $status); |
|
137
|
|
|
|
|
138
|
|
|
return $status === 0; |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|