Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 51 additions & 51 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/Application/Release/Port/ReleaseDraftRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ interface ReleaseDraftRepository
{
public function branchHead(string $repository, string $branch): string;

public function isAncestor(string $repository, string $ancestorSha, string $descendantSha): bool;

public function tagTarget(string $repository, string $tag): ?string;

public function releaseByTag(string $repository, string $tag): ?ReleaseDraftInfo;
Expand Down
6 changes: 5 additions & 1 deletion src/Application/Release/ReleaseDrafter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public function prepare(
}

$branchHead = $this->github->branchHead($prepared->repository, $prepared->branch);
if ($branchHead !== $prepared->finalSha && !$this->git->isAncestor($prepared->finalSha, $branchHead)) {
if ($branchHead !== $prepared->finalSha && !$this->github->isAncestor(
$prepared->repository,
$prepared->finalSha,
$branchHead,
)) {
throw new DomainException(sprintf(
'Release branch no longer contains finalized release %s; current head is %s.',
$prepared->finalSha,
Expand Down
23 changes: 23 additions & 0 deletions src/Infrastructure/GitHub/GitHubReleaseDraftRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,29 @@ public function branchHead(string $repository, string $branch): string
return $sha;
}

public function isAncestor(string $repository, string $ancestorSha, string $descendantSha): bool
{
if ($ancestorSha === $descendantSha) {
return true;
}

$data = $this->request(
'GET',
sprintf(
'/repos/%s/compare/%s...%s',
$repository,
rawurlencode($ancestorSha),
rawurlencode($descendantSha),
),
);
$status = $data['status'] ?? null;
if (!in_array($status, ['ahead', 'behind', 'diverged', 'identical'], true)) {
throw new DomainException('GitHub returned an invalid commit comparison status.');
}

return $status === 'ahead' || $status === 'identical';
}

public function tagTarget(string $repository, string $tag): ?string
{
$response = $this->client->request('GET', sprintf(
Expand Down
Loading
Loading