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() {
|
||||
return new \MailPoetTasks\Release\ReleaseVersionController(
|
||||
$this->createJiraController(),
|
||||
$this->createGitHubController(),
|
||||
\MailPoetTasks\Release\JiraController::PROJECT_MAILPOET
|
||||
);
|
||||
}
|
||||
|
@ -16,21 +16,22 @@ class GitHubController {
|
||||
|
||||
const QA_GITHUB_LOGIN = 'veljkho';
|
||||
|
||||
private const API_BASE_URI = 'https://api.github.com/repos/mailpoet';
|
||||
|
||||
/** @var string */
|
||||
private $zipFilename;
|
||||
|
||||
/** @var HttpClient */
|
||||
/** @var Client */
|
||||
private $httpClient;
|
||||
|
||||
public function __construct($username, $token, $project) {
|
||||
$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([
|
||||
'auth' => [$username, $token],
|
||||
'headers' => [
|
||||
'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'];
|
||||
}
|
||||
|
||||
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() {
|
||||
$response = $this->httpClient->get('releases');
|
||||
$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']);
|
||||
}
|
||||
|
||||
public function getLastReleasedVersion() {
|
||||
$response = $this->httpClient->get("project/$this->project/version", [
|
||||
public function getLastReleasedVersion(?string $project = null) {
|
||||
$project = $project ?: $this->project;
|
||||
$response = $this->httpClient->get("project/$project/version", [
|
||||
'query' => [
|
||||
'maxResults' => 1,
|
||||
'orderBy' => '-sequence',
|
||||
|
@ -7,11 +7,15 @@ class ReleaseVersionController {
|
||||
/** @var JiraController */
|
||||
private $jira;
|
||||
|
||||
/** @var GitHubController */
|
||||
private $github;
|
||||
|
||||
/** @var string */
|
||||
private $project;
|
||||
|
||||
public function __construct(JiraController $jira, $project) {
|
||||
public function __construct(JiraController $jira, GitHubController $github, $project) {
|
||||
$this->jira = $jira;
|
||||
$this->github = $github;
|
||||
$this->project = $project;
|
||||
}
|
||||
|
||||
@ -35,39 +39,25 @@ class ReleaseVersionController {
|
||||
public function determineNextVersion() {
|
||||
$lastVersion = $this->jira->getLastReleasedVersion();
|
||||
|
||||
$partToIncrement = VersionHelper::PATCH;
|
||||
$partToIncrement = VersionHelper::MINOR;
|
||||
|
||||
if ($this->project === JiraController::PROJECT_MAILPOET) {
|
||||
$freeIncrement = $this->checkProjectVersionIncrement(JiraController::PROJECT_MAILPOET);
|
||||
$premiumIncrement = $this->checkProjectVersionIncrement(JiraController::PROJECT_PREMIUM);
|
||||
$isPremiumReleased = $this->github->projectBranchExists(
|
||||
JiraController::PROJECT_PREMIUM,
|
||||
GitHubController::RELEASE_SOURCE_BRANCH
|
||||
);
|
||||
|
||||
if (in_array(VersionHelper::MINOR, [$freeIncrement, $premiumIncrement])) {
|
||||
$partToIncrement = VersionHelper::MINOR;
|
||||
if (!$isPremiumReleased) {
|
||||
$partToIncrement = VersionHelper::PATCH;
|
||||
}
|
||||
} elseif ($this->project === JiraController::PROJECT_PREMIUM) {
|
||||
$lastVersion = $this->jira->getLastReleasedVersion(JiraController::PROJECT_MAILPOET);
|
||||
}
|
||||
|
||||
$nextVersion = VersionHelper::incrementVersion($lastVersion['name'], $partToIncrement);
|
||||
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) {
|
||||
$project = $project ?: $this->project;
|
||||
$jql = "project = $project AND status = Done AND (fixVersion = EMPTY OR fixVersion IN unreleasedVersions()) AND updated >= -52w";
|
||||
|
Reference in New Issue
Block a user