Skip to content

Commit

Permalink
Fix release for private repositories
Browse files Browse the repository at this point in the history
Signed-off-by: Leandro Silva <leandro.silva@zooxsmart.com>
  • Loading branch information
Lansoweb committed May 22, 2021
1 parent daa21ce commit 481cef7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion bin/console.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Laminas\AutomaticReleases\WebApplication;

use ChangelogGenerator\GitHubOAuthToken;
use DateTimeZone;
use ErrorException;
use Http\Discovery\HttpClientDiscovery;
Expand Down Expand Up @@ -86,7 +87,8 @@ static function (int $errorCode, string $message = '', string $file = '', int $l
);
$createCommitText = new CreateReleaseTextThroughChangelog(JwageGenerateChangelog::create(
$makeRequests,
$httpClient
$httpClient,
new GitHubOAuthToken($githubToken)
));
$createReleaseText = new MergeMultipleReleaseNotes([
new CreateReleaseTextViaKeepAChangelog($changelogExists, new SystemClock(new DateTimeZone('UTC'))),
Expand Down
14 changes: 10 additions & 4 deletions src/Github/JwageGenerateChangelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use ChangelogGenerator\ChangelogConfig;
use ChangelogGenerator\ChangelogGenerator;
use ChangelogGenerator\GitHubCredentials;
use ChangelogGenerator\GitHubOAuthToken;
use ChangelogGenerator\IssueClient;
use ChangelogGenerator\IssueFactory;
use ChangelogGenerator\IssueFetcher;
Expand All @@ -20,23 +22,26 @@
final class JwageGenerateChangelog implements GenerateChangelog
{
private ChangelogGenerator $changelogGenerator;
private GitHubCredentials $gitHubCredentials;

public function __construct(ChangelogGenerator $changelogGenerator)
public function __construct(ChangelogGenerator $changelogGenerator, GitHubCredentials $gitHubCredentials)
{
$this->changelogGenerator = $changelogGenerator;
$this->gitHubCredentials = $gitHubCredentials;
}

public static function create(
RequestFactoryInterface $messageFactory,
ClientInterface $client
ClientInterface $client,
GitHubCredentials $gitHubCredentials
): self {
$issueClient = new IssueClient($messageFactory, $client);
$issueFactory = new IssueFactory();
$issueFetcher = new IssueFetcher($issueClient);
$issueRepository = new IssueRepository($issueFetcher, $issueFactory);
$issueGrouper = new IssueGrouper();

return new self(new ChangelogGenerator($issueRepository, $issueGrouper));
return new self(new ChangelogGenerator($issueRepository, $issueGrouper), $gitHubCredentials);
}

public function __invoke(
Expand All @@ -46,7 +51,8 @@ public function __invoke(
$config = (new ChangelogConfig())
->setUser($repositoryName->owner())
->setRepository($repositoryName->name())
->setMilestone($semVerVersion->fullReleaseName());
->setMilestone($semVerVersion->fullReleaseName())
->setGitHubCredentials($this->gitHubCredentials);

$output = new BufferedOutput();

Expand Down
8 changes: 6 additions & 2 deletions test/unit/Github/JwageGenerateChangelogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use ChangelogGenerator\ChangelogConfig;
use ChangelogGenerator\ChangelogGenerator;
use ChangelogGenerator\GitHubOAuthToken;
use Laminas\AutomaticReleases\Git\Value\SemVerVersion;
use Laminas\AutomaticReleases\Github\JwageGenerateChangelog;
use Laminas\AutomaticReleases\Github\Value\RepositoryName;
Expand All @@ -16,10 +17,13 @@ final class JwageGenerateChangelogTest extends TestCase
{
public function testGenerateChangelog(): void
{
$githubCredentials = new GitHubOAuthToken('token');

$config = (new ChangelogConfig())
->setUser('laminas')
->setRepository('repository-name')
->setMilestone('1.0.0');
->setMilestone('1.0.0')
->setGitHubCredentials($githubCredentials);

$output = new BufferedOutput();

Expand All @@ -32,7 +36,7 @@ public function testGenerateChangelog(): void
$repositoryName = RepositoryName::fromFullName('laminas/repository-name');
$semVerVersion = SemVerVersion::fromMilestoneName('1.0.0');

(new JwageGenerateChangelog($changelogGenerator))
(new JwageGenerateChangelog($changelogGenerator, $githubCredentials))
->__invoke($repositoryName, $semVerVersion);
}
}

0 comments on commit 481cef7

Please sign in to comment.