Make version optional, remove Premium-related code [MAILPOET-1783]

This commit is contained in:
wxa
2019-02-12 18:21:40 +03:00
committed by M. Shull
parent 84f0816dca
commit a829e05bfb
2 changed files with 23 additions and 36 deletions

View File

@ -553,9 +553,6 @@ class RoboFile extends \Robo\Tasks {
function changelogUpdate($opts = ['version-name' => null]) { function changelogUpdate($opts = ['version-name' => null]) {
$this->say("Updating changelog"); $this->say("Updating changelog");
$outputs = $this->getChangelogController()->update($opts['version-name']); $outputs = $this->getChangelogController()->update($opts['version-name']);
if ($opts['quiet']) {
return;
}
$this->say("Changelog \n{$outputs[0]} \n{$outputs[1]}\n\n"); $this->say("Changelog \n{$outputs[0]} \n{$outputs[1]}\n\n");
$this->say("IMPORTANT NOTES \n" . ($outputs[2] ?: 'none')); $this->say("IMPORTANT NOTES \n" . ($outputs[2] ?: 'none'));
} }
@ -588,13 +585,13 @@ class RoboFile extends \Robo\Tasks {
); );
} }
protected function getReleaseVersionController($project) { protected function getReleaseVersionController() {
require_once './tasks/release/ReleaseVersionController.php'; require_once './tasks/release/ReleaseVersionController.php';
$this->loadEnv(); $this->loadEnv();
return \MailPoetTasks\Release\ReleaseVersionController::createWithJiraCredentials( return \MailPoetTasks\Release\ReleaseVersionController::createWithJiraCredentials(
getenv('WP_JIRA_TOKEN'), getenv('WP_JIRA_TOKEN'),
getenv('WP_JIRA_USER'), getenv('WP_JIRA_USER'),
$project \MailPoetTasks\Release\Jira::PROJECT_MAILPOET
); );
} }
@ -626,30 +623,21 @@ class RoboFile extends \Robo\Tasks {
->run(); ->run();
} }
public function jiraReleaseVersion($opts = ['free' => null, 'premium' => null]) { public function jiraReleaseVersion($version = null, $opts = []) {
require_once './tasks/release/Jira.php'; if ($version) {
if (empty($opts['free']) && empty($opts['premium'])) { $this->validateVersion($version);
$this->yell('No Free or Premium version specified', 40, 'red'); }
try {
$output = $this->getReleaseVersionController()
->assignVersionToCompletedTickets($version);
} catch (\Exception $e) {
$this->yell($e->getMessage(), 40, 'red');
exit(1); exit(1);
} }
$output = []; $this->say($output);
if (!empty($opts['free'])) {
$this->validateVersion($opts['free']);
$output[] = $this->getReleaseVersionController(\MailPoetTasks\Release\Jira::PROJECT_MAILPOET)
->assignVersionToCompletedTickets($opts['free']);
}
if (!empty($opts['premium'])) {
$this->validateVersion($opts['premium']);
$output[] = $this->getReleaseVersionController(\MailPoetTasks\Release\Jira::PROJECT_PREMIUM)
->assignVersionToCompletedTickets($opts['premium']);
}
if($opts['quiet']) {
return;
}
$this->say(join("\n", $output));
} }
private function validateVersion($version) { protected function validateVersion($version) {
if (!preg_match('/\d+\.\d+\.\d+/', $version)) { if (!preg_match('/\d+\.\d+\.\d+/', $version)) {
$this->yell('Incorrect version format', 40, 'red'); $this->yell('Incorrect version format', 40, 'red');
exit(1); exit(1);

View File

@ -21,15 +21,13 @@ class ReleaseVersionController {
return new self(new Jira($token, $user, $project), $project); return new self(new Jira($token, $user, $project), $project);
} }
function assignVersionToCompletedTickets($version) { function assignVersionToCompletedTickets($version = null) {
$output = []; $version = $this->checkVersion($version);
$output[] = "Checking version $version in $this->project"; if (!$version) {
throw new \Exception('The version is invalid or already released');
if (!$this->checkVersion($version)) {
$output[] = "The version is invalid or already released";
return join("\n", $output);
} }
$output = [];
$output[] = "Setting version $version to completed tickets in $this->project..."; $output[] = "Setting version $version to completed tickets in $this->project...";
$issues = $this->getDoneIssuesWithoutVersion(); $issues = $this->getDoneIssuesWithoutVersion();
$result = array_map(function ($issue) use ($version) { $result = array_map(function ($issue) use ($version) {
@ -40,7 +38,7 @@ class ReleaseVersionController {
return join("\n", $output); return join("\n", $output);
} }
function getDoneIssuesWithoutVersion() { private function getDoneIssuesWithoutVersion() {
$jql = "project = $this->project AND status = Done AND (fixVersion = EMPTY OR fixVersion IN unreleasedVersions()) AND updated >= -52w"; $jql = "project = $this->project AND status = Done AND (fixVersion = EMPTY OR fixVersion IN unreleasedVersions()) AND updated >= -52w";
$result = $this->jira->search($jql, ['key']); $result = $this->jira->search($jql, ['key']);
return array_map(function ($issue) { return array_map(function ($issue) {
@ -51,7 +49,7 @@ class ReleaseVersionController {
}, $result['issues']); }, $result['issues']);
} }
function checkVersion($version) { private function checkVersion($version) {
try { try {
$version_data = $this->jira->getVersion($version); $version_data = $this->jira->getVersion($version);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -63,12 +61,13 @@ class ReleaseVersionController {
} else if (empty($version_data)) { } else if (empty($version_data)) {
// version does not exist // version does not exist
$this->jira->createVersion($version); $this->jira->createVersion($version);
return $version;
} }
// version exists // version exists
return true; return $version_data['name'];
} }
function setIssueFixVersion($issue_key, $version) { private function setIssueFixVersion($issue_key, $version) {
$data = [ $data = [
'update' => [ 'update' => [
'fixVersions' => [ 'fixVersions' => [