Change logic of release next version
Premium should have the same minor version like free when is released. Free will be released only with a patch version when premium branch doesn't exist. We assume that premium isn't released when branch doesn't exist. [MAILPOET-3152]
This commit is contained in:
@ -953,6 +953,7 @@ class RoboFile extends \Robo\Tasks {
|
|||||||
protected function getReleaseVersionController() {
|
protected function getReleaseVersionController() {
|
||||||
return new \MailPoetTasks\Release\ReleaseVersionController(
|
return new \MailPoetTasks\Release\ReleaseVersionController(
|
||||||
$this->createJiraController(),
|
$this->createJiraController(),
|
||||||
|
$this->createGitHubController(),
|
||||||
\MailPoetTasks\Release\JiraController::PROJECT_MAILPOET
|
\MailPoetTasks\Release\JiraController::PROJECT_MAILPOET
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -16,21 +16,22 @@ class GitHubController {
|
|||||||
|
|
||||||
const QA_GITHUB_LOGIN = 'veljkho';
|
const QA_GITHUB_LOGIN = 'veljkho';
|
||||||
|
|
||||||
|
private const API_BASE_URI = 'https://api.github.com/repos/mailpoet';
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $zipFilename;
|
private $zipFilename;
|
||||||
|
|
||||||
/** @var HttpClient */
|
/** @var Client */
|
||||||
private $httpClient;
|
private $httpClient;
|
||||||
|
|
||||||
public function __construct($username, $token, $project) {
|
public function __construct($username, $token, $project) {
|
||||||
$this->zipFilename = $project === self::PROJECT_MAILPOET ? self::FREE_ZIP_FILENAME : self::PREMIUM_ZIP_FILENAME;
|
$this->zipFilename = $project === self::PROJECT_MAILPOET ? self::FREE_ZIP_FILENAME : self::PREMIUM_ZIP_FILENAME;
|
||||||
$githubPath = $project === self::PROJECT_MAILPOET ? 'mailpoet' : 'mailpoet-premium';
|
|
||||||
$this->httpClient = new Client([
|
$this->httpClient = new Client([
|
||||||
'auth' => [$username, $token],
|
'auth' => [$username, $token],
|
||||||
'headers' => [
|
'headers' => [
|
||||||
'Accept' => 'application/vnd.github.v3+json',
|
'Accept' => 'application/vnd.github.v3+json',
|
||||||
],
|
],
|
||||||
'base_uri' => "https://api.github.com/repos/mailpoet/$githubPath/",
|
'base_uri' => self::API_BASE_URI . "/{$this->getGithubPathByProject($project)}/",
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,6 +146,22 @@ class GitHubController {
|
|||||||
return $data['sha'];
|
return $data['sha'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function projectBranchExists(string $project, string $branch): bool {
|
||||||
|
$githubProject = $this->getGithubPathByProject($project);
|
||||||
|
$branch = urlencode($branch);
|
||||||
|
try {
|
||||||
|
$this->httpClient->get(
|
||||||
|
self::API_BASE_URI . "/{$githubProject}/git/ref/heads/{$branch}"
|
||||||
|
);
|
||||||
|
} catch (ClientException $e) {
|
||||||
|
if ($e->getCode() === 404) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private function ensureNoDraftReleaseExists() {
|
private function ensureNoDraftReleaseExists() {
|
||||||
$response = $this->httpClient->get('releases');
|
$response = $this->httpClient->get('releases');
|
||||||
$data = json_decode($response->getBody()->getContents(), true);
|
$data = json_decode($response->getBody()->getContents(), true);
|
||||||
@ -201,4 +218,8 @@ class GitHubController {
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getGithubPathByProject(string $project): string {
|
||||||
|
return urlencode($project === self::PROJECT_MAILPOET ? 'mailpoet' : 'mailpoet-premium');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,8 +75,9 @@ class JiraController {
|
|||||||
return reset($version['values']);
|
return reset($version['values']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLastReleasedVersion() {
|
public function getLastReleasedVersion(?string $project = null) {
|
||||||
$response = $this->httpClient->get("project/$this->project/version", [
|
$project = $project ?: $this->project;
|
||||||
|
$response = $this->httpClient->get("project/$project/version", [
|
||||||
'query' => [
|
'query' => [
|
||||||
'maxResults' => 1,
|
'maxResults' => 1,
|
||||||
'orderBy' => '-sequence',
|
'orderBy' => '-sequence',
|
||||||
|
@ -7,11 +7,15 @@ class ReleaseVersionController {
|
|||||||
/** @var JiraController */
|
/** @var JiraController */
|
||||||
private $jira;
|
private $jira;
|
||||||
|
|
||||||
|
/** @var GitHubController */
|
||||||
|
private $github;
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $project;
|
private $project;
|
||||||
|
|
||||||
public function __construct(JiraController $jira, $project) {
|
public function __construct(JiraController $jira, GitHubController $github, $project) {
|
||||||
$this->jira = $jira;
|
$this->jira = $jira;
|
||||||
|
$this->github = $github;
|
||||||
$this->project = $project;
|
$this->project = $project;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,39 +39,25 @@ class ReleaseVersionController {
|
|||||||
public function determineNextVersion() {
|
public function determineNextVersion() {
|
||||||
$lastVersion = $this->jira->getLastReleasedVersion();
|
$lastVersion = $this->jira->getLastReleasedVersion();
|
||||||
|
|
||||||
$partToIncrement = VersionHelper::PATCH;
|
$partToIncrement = VersionHelper::MINOR;
|
||||||
|
|
||||||
if ($this->project === JiraController::PROJECT_MAILPOET) {
|
if ($this->project === JiraController::PROJECT_MAILPOET) {
|
||||||
$freeIncrement = $this->checkProjectVersionIncrement(JiraController::PROJECT_MAILPOET);
|
$isPremiumReleased = $this->github->projectBranchExists(
|
||||||
$premiumIncrement = $this->checkProjectVersionIncrement(JiraController::PROJECT_PREMIUM);
|
JiraController::PROJECT_PREMIUM,
|
||||||
|
GitHubController::RELEASE_SOURCE_BRANCH
|
||||||
|
);
|
||||||
|
|
||||||
if (in_array(VersionHelper::MINOR, [$freeIncrement, $premiumIncrement])) {
|
if (!$isPremiumReleased) {
|
||||||
$partToIncrement = VersionHelper::MINOR;
|
$partToIncrement = VersionHelper::PATCH;
|
||||||
}
|
}
|
||||||
|
} elseif ($this->project === JiraController::PROJECT_PREMIUM) {
|
||||||
|
$lastVersion = $this->jira->getLastReleasedVersion(JiraController::PROJECT_MAILPOET);
|
||||||
}
|
}
|
||||||
|
|
||||||
$nextVersion = VersionHelper::incrementVersion($lastVersion['name'], $partToIncrement);
|
$nextVersion = VersionHelper::incrementVersion($lastVersion['name'], $partToIncrement);
|
||||||
return $nextVersion;
|
return $nextVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkProjectVersionIncrement($project) {
|
|
||||||
$issues = $this->getUnreleasedDoneIssues($project);
|
|
||||||
|
|
||||||
$partToIncrement = VersionHelper::PATCH;
|
|
||||||
$fieldId = JiraController::VERSION_INCREMENT_FIELD_ID;
|
|
||||||
|
|
||||||
foreach ($issues as $issue) {
|
|
||||||
if (!empty($issue['fields'][$fieldId]['value'])
|
|
||||||
&& $issue['fields'][$fieldId]['value'] === VersionHelper::MINOR
|
|
||||||
) {
|
|
||||||
$partToIncrement = VersionHelper::MINOR;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $partToIncrement;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getUnreleasedDoneIssues($project = null) {
|
private function getUnreleasedDoneIssues($project = null) {
|
||||||
$project = $project ?: $this->project;
|
$project = $project ?: $this->project;
|
||||||
$jql = "project = $project AND status = Done AND (fixVersion = EMPTY OR fixVersion IN unreleasedVersions()) AND updated >= -52w";
|
$jql = "project = $project AND status = Done AND (fixVersion = EMPTY OR fixVersion IN unreleasedVersions()) AND updated >= -52w";
|
||||||
|
Reference in New Issue
Block a user