1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the SVN-Buddy library. |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
8
|
|
|
* @link https://github.com/console-helpers/svn-buddy |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\SVNBuddy\Repository; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use ConsoleHelpers\SVNBuddy\Exception\RepositoryCommandException; |
15
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\Connector\Connector; |
16
|
|
|
|
17
|
|
|
class RevisionUrlBuilder |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Repository connector. |
22
|
|
|
* |
23
|
|
|
* @var Connector |
24
|
|
|
*/ |
25
|
|
|
private $_repositoryConnector; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Repository URL. |
29
|
|
|
* |
30
|
|
|
* @var string |
31
|
|
|
*/ |
32
|
|
|
private $_repositoryUrl; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Creates revision url builder instance. |
36
|
|
|
* |
37
|
|
|
* @param Connector $repository_connector Repository connector. |
38
|
|
|
* @param string $repository_url Repository URL. |
39
|
|
|
*/ |
40
|
7 |
|
public function __construct(Connector $repository_connector, $repository_url) |
41
|
|
|
{ |
42
|
7 |
|
$this->_repositoryConnector = $repository_connector; |
43
|
7 |
|
$this->_repositoryUrl = $repository_url; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Returns mask. |
48
|
|
|
* |
49
|
|
|
* @param string $style Style. |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
6 |
|
public function getMask($style = '') |
54
|
|
|
{ |
55
|
|
|
try { |
56
|
6 |
|
$arcanist_config = \json_decode( |
57
|
6 |
|
$this->_repositoryConnector->getFileContent($this->_repositoryUrl . '/.arcconfig', 'HEAD'), |
|
|
|
|
58
|
6 |
|
true |
59
|
6 |
|
); |
60
|
|
|
} |
61
|
2 |
|
catch ( RepositoryCommandException $e ) { |
62
|
|
|
// Phabricator integration is not configured. |
63
|
2 |
|
return $this->addStyle($style, '{revision}'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
// Phabricator integration is not configured correctly. |
67
|
4 |
|
if ( !\is_array($arcanist_config) |
68
|
4 |
|
|| !isset($arcanist_config['repository.callsign'], $arcanist_config['phabricator.uri']) |
69
|
|
|
) { |
70
|
2 |
|
return $this->addStyle($style, '{revision}'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// Phabricator integration is configured properly. |
74
|
2 |
|
$revision_title = $arcanist_config['phabricator.uri']; |
75
|
2 |
|
$revision_title .= 'r' . $arcanist_config['repository.callsign'] . '{revision}'; |
76
|
|
|
|
77
|
2 |
|
return $this->addStyle($style, $revision_title); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Adds style around a text. |
82
|
|
|
* |
83
|
|
|
* @param string $style Style. |
84
|
|
|
* @param string $text Text. |
85
|
|
|
* |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
6 |
|
protected function addStyle($style, $text) |
89
|
|
|
{ |
90
|
6 |
|
return $style ? '<' . $style . '>' . $text . '</>' : $text; |
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
} |
95
|
|
|
|