2 namespace Robo\Task\Development;
7 * Publishes new GitHub release.
11 * $this->taskGitHubRelease('0.1.0')
12 * ->uri('consolidation-org/Robo')
13 * ->description('Add stuff people need.')
14 * ->change('Fix #123')
15 * ->change('Add frobulation method to all widgets')
20 class GitHubRelease extends GitHub
35 protected $description = '';
40 protected $changes = [];
45 protected $draft = false;
50 protected $prerelease = false;
55 protected $comittish = 'master';
60 public function __construct($tag)
70 public function tag($tag)
81 public function draft($draft)
83 $this->draft = $draft;
92 public function name($name)
99 * @param string $description
103 public function description($description)
105 $this->description = $description;
110 * @param bool $prerelease
114 public function prerelease($prerelease)
116 $this->prerelease = $prerelease;
121 * @param string $comittish
125 public function comittish($comittish)
127 $this->comittish = $comittish;
132 * @param string $description
136 public function appendDescription($description)
138 if (!empty($this->description)) {
139 $this->description .= "\n\n";
141 $this->description .= $description;
145 public function changes(array $changes)
147 $this->changes = array_merge($this->changes, $changes);
152 * @param string $change
156 public function change($change)
158 $this->changes[] = $change;
165 protected function getBody()
167 $body = $this->description;
168 if (!empty($this->changes)) {
169 $changes = array_map(
175 $changesText = implode("\n", $changes);
176 $body .= "### Changelog \n\n$changesText";
184 public function run()
186 $this->printTaskInfo('Releasing {tag}', ['tag' => $this->tag]);
188 list($code, $data) = $this->sendRequest(
191 "tag_name" => $this->tag,
192 "target_commitish" => $this->comittish,
193 "name" => $this->name,
194 "body" => $this->getBody(),
195 "draft" => $this->draft,
196 "prerelease" => $this->prerelease
203 in_array($code, [200, 201]) ? 0 : 1,
204 isset($data->message) ? $data->message : '',
205 ['response' => $data, 'time' => $this->getExecutionTime()]