1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Task runner, code generator and build tool for easier continuos integration |
5
|
|
|
* |
6
|
|
|
* @link https://github.com/hiqdev/hidev |
7
|
|
|
* @package hidev |
8
|
|
|
* @license BSD-3-Clause |
9
|
|
|
* @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace hidev\controllers; |
13
|
|
|
|
14
|
|
|
use yii\helpers\Json; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Goal for GitHub. |
18
|
|
|
*/ |
19
|
|
|
class GithubController extends CommonController |
20
|
|
|
{ |
21
|
|
|
protected $_name; |
22
|
|
|
protected $_vendor; |
23
|
|
|
protected $_package; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string GitHub OAuth access token |
27
|
|
|
*/ |
28
|
|
|
protected $_token; |
29
|
|
|
|
30
|
|
|
public function setName($value) |
31
|
|
|
{ |
32
|
|
|
list($vendor, $package) = explode('/', $value, 2); |
33
|
|
|
$this->_name = $value; |
34
|
|
|
$this->_vendor = $vendor ?: $package; |
35
|
|
|
$this->_package = $package ?: $vendor; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getName() |
39
|
|
|
{ |
40
|
|
|
if ($this->_name === null) { |
41
|
|
|
$this->setName($this->takeGoal('package')->fullName); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
return $this->_name; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function setVendor($value) |
48
|
|
|
{ |
49
|
|
|
$this->_vendor = $value; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getVendor() |
53
|
|
|
{ |
54
|
|
|
if ($this->_vendor === null) { |
55
|
|
|
$this->_vendor = $this->getVendor()->name; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
return $this->_vendor; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function actionCreate() |
62
|
|
|
{ |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function setPackage($value) |
66
|
|
|
{ |
67
|
|
|
$this->_package = $value; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getPackage() |
71
|
|
|
{ |
72
|
|
|
if ($this->_package === null) { |
73
|
|
|
$this->_package = $this->takeGoal('package')->name; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $this->_package; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Clone repo from github. |
81
|
|
|
* TODO this action must be run without `start`. |
82
|
|
|
* @param string $repo full name vendor/package |
83
|
|
|
* @return int exit code |
84
|
|
|
*/ |
85
|
|
|
public function actionClone($repo) |
86
|
|
|
{ |
87
|
|
|
return $this->passthru('git', ['clone', '[email protected]:' . $repo]); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function actionRelease($version = null) |
91
|
|
|
{ |
92
|
|
|
$this->runRequest('CHANGELOG.md'); |
93
|
|
|
$changelog = $this->takeGoal('CHANGELOG.md'); |
94
|
|
|
$notes = reset($changelog->getFile()->getHandler()->releaseNotes); |
95
|
|
|
$version = $this->takeGoal('bump')->getVersion($version); |
96
|
|
|
|
97
|
|
|
return $this->request('POST', '/repos/' . $this->getName() . '/releases', [ |
98
|
|
|
'tag_name' => $version, |
99
|
|
|
'name' => $version, |
100
|
|
|
'body' => $notes, |
101
|
|
|
]); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function request($method, $path, $data) |
105
|
|
|
{ |
106
|
|
|
return $this->passthru('curl', ['-X', $method, '--data', Json::encode($data), 'https://api.github.com' . $path . '?access_token=' . $this->getToken()]); |
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getToken() |
|
|
|
|
110
|
|
|
{ |
111
|
|
|
if ($this->_token === null) { |
112
|
|
|
$this->_token = $_SERVER['GITHUB_TOKEN']; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return $this->_token; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: