-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from weierophinney/hotfix/fix-changelog-operat…
…ions Idempotent operations for reading, checkout branch prior to writing
- Loading branch information
Showing
11 changed files
with
293 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Laminas\AutomaticReleases\Changelog; | ||
|
||
use Laminas\AutomaticReleases\Git\Value\BranchName; | ||
|
||
interface ChangelogExists | ||
{ | ||
/** | ||
* @param non-empty-string $repositoryDirectory | ||
*/ | ||
public function __invoke( | ||
BranchName $sourceBranch, | ||
string $repositoryDirectory | ||
): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Laminas\AutomaticReleases\Changelog; | ||
|
||
use Laminas\AutomaticReleases\Git\Value\BranchName; | ||
use Symfony\Component\Process\Process; | ||
|
||
class ChangelogExistsViaConsole implements ChangelogExists | ||
{ | ||
/** | ||
* @param non-empty-string $repositoryDirectory | ||
*/ | ||
public function __invoke( | ||
BranchName $sourceBranch, | ||
string $repositoryDirectory | ||
): bool { | ||
$process = new Process(['git', 'show', $sourceBranch->name() . ':CHANGELOG.md'], $repositoryDirectory); | ||
$process->run(); | ||
|
||
return $process->isSuccessful(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
use Laminas\AutomaticReleases\Changelog\BumpAndCommitChangelogVersion; | ||
use Laminas\AutomaticReleases\Changelog\BumpAndCommitChangelogVersionViaKeepAChangelog; | ||
use Laminas\AutomaticReleases\Changelog\ChangelogExists; | ||
use Laminas\AutomaticReleases\Changelog\ChangelogExistsViaConsole; | ||
use Laminas\AutomaticReleases\Git\CheckoutBranch; | ||
use Laminas\AutomaticReleases\Git\CommitFile; | ||
use Laminas\AutomaticReleases\Git\Push; | ||
|
@@ -44,6 +46,7 @@ protected function setUp(): void | |
$this->push = $this->createMock(Push::class); | ||
$this->logger = $this->createMock(LoggerInterface::class); | ||
$this->bumpAndCommitChangelog = new BumpAndCommitChangelogVersionViaKeepAChangelog( | ||
new ChangelogExistsViaConsole(), | ||
$this->checkoutBranch, | ||
$this->commitFile, | ||
$this->push, | ||
|
@@ -58,12 +61,8 @@ public function testReturnsEarlyWhenNoChangelogFilePresent(): void | |
$version = SemVerVersion::fromMilestoneName('1.0.1'); | ||
|
||
$this->checkoutBranch | ||
->expects($this->once()) | ||
->method('__invoke') | ||
->with( | ||
$this->equalTo($repoDir), | ||
$sourceBranch | ||
); | ||
->expects($this->never()) | ||
->method('__invoke'); | ||
|
||
$this->logger | ||
->expects($this->once()) | ||
|
@@ -118,6 +117,13 @@ public function testAddsNewReleaseVersionUsingBumpTypeToChangelogFileAndCommitsA | |
|
||
Assert::stringNotEmpty($repoDir); | ||
|
||
$changelogExists = $this->createMock(ChangelogExists::class); | ||
$changelogExists | ||
->expects($this->once()) | ||
->method('__invoke') | ||
->with($sourceBranch, $repoDir) | ||
->willReturn(true); | ||
|
||
$this->logger | ||
->expects($this->once()) | ||
->method('info') | ||
|
@@ -154,8 +160,16 @@ public function testAddsNewReleaseVersionUsingBumpTypeToChangelogFileAndCommitsA | |
->with( | ||
); | ||
|
||
$bumpAndCommitChangelog = new BumpAndCommitChangelogVersionViaKeepAChangelog( | ||
$changelogExists, | ||
$this->checkoutBranch, | ||
$this->commitFile, | ||
$this->push, | ||
$this->logger | ||
); | ||
|
||
$this->assertNull( | ||
($this->bumpAndCommitChangelog)( | ||
$bumpAndCommitChangelog( | ||
$bumpType, | ||
$repoDir, | ||
$version, | ||
|
@@ -191,6 +205,13 @@ private function createMockChangelog(): string | |
|
||
file_put_contents($changelogFile, self::CHANGELOG_STUB); | ||
|
||
(new Process(['git', 'init', '.'], $repo))->mustRun(); | ||
(new Process(['git', 'config', 'user.email', '[email protected]'], $repo))->mustRun(); | ||
(new Process(['git', 'config', 'user.name', 'Just Me'], $repo))->mustRun(); | ||
(new Process(['git', 'add', '.'], $repo))->mustRun(); | ||
(new Process(['git', 'commit', '-m', 'Initial import'], $repo))->mustRun(); | ||
(new Process(['git', 'switch', '-c', '1.0.x'], $repo))->mustRun(); | ||
|
||
return $changelogFile; | ||
} | ||
|
||
|
Oops, something went wrong.