Skip to content

Commit df8561c

Browse files
authored
Merge branch 'master' into 279-upgrade-notes
2 parents cb4609e + 1c26eaa commit df8561c

File tree

10 files changed

+96
-93
lines changed

10 files changed

+96
-93
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,6 @@ To customize the configuration of **yii-dev-tool**, create your local configurat
6969
using file `packages.local.php.example` as example. In this file, you will find examples of all available
7070
configuration options.
7171

72-
Some commands such as `github/protect-branch`, `github/settings`, `release/make` require
73-
a [GitHub personal access token](https://github.com/settings/tokens). Therefore, you need to
74-
create it and save it in `config/github.token` file.
75-
7672
To move `dev` directory where packages are installed to another location, create your local configuration `config/config.local.php`
7773
using file `config/config.local.php.example` as example. Adjust `packagesRootDir` as needed.
7874

dev/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

src/App/Command/Github/BuildStatusCommand.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44

55
namespace Yiisoft\YiiDevTool\App\Command\Github;
66

7-
use Github\Api\Repository\Checks\CheckRuns;
7+
use Github\AuthMethod;
88
use Github\Client;
9-
use RuntimeException;
9+
use Github\Api\Repository\Checks\CheckRuns;
1010
use Yiisoft\YiiDevTool\App\Component\Console\PackageCommand;
1111
use Yiisoft\YiiDevTool\App\Component\Package\Package;
12+
use Yiisoft\YiiDevTool\App\Component\GitHubTokenAware;
1213

1314
final class BuildStatusCommand extends PackageCommand
1415
{
16+
use GitHubTokenAware;
17+
1518
protected function configure()
1619
{
1720
$this
@@ -38,7 +41,7 @@ protected function processPackage(Package $package): void
3841

3942

4043
$client = new Client();
41-
$client->authenticate($this->getToken(), null, Client::AUTH_ACCESS_TOKEN);
44+
$client->authenticate($this->getGitHubToken(), null, AuthMethod::ACCESS_TOKEN);
4245

4346
$checksRunsApi = new CheckRuns($client);
4447

@@ -67,14 +70,4 @@ private function getSettings(): array
6770
/** @noinspection PhpIncludeInspection */
6871
return require $this->getAppRootDir() . 'config/settings.php';
6972
}
70-
71-
private function getToken(): string
72-
{
73-
$tokenFile = $this->getAppRootDir() . 'config/github.token';
74-
if (!file_exists($tokenFile)) {
75-
throw new RuntimeException("There's no $tokenFile. Please create one and put your GitHub token there. You may create it here: https://github.com/settings/tokens. Choose 'repo' rights.");
76-
}
77-
78-
return trim(file_get_contents($tokenFile));
79-
}
8073
}

src/App/Command/Github/ForksRepositoriesCommand.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Yiisoft\YiiDevTool\App\Command\Github;
66

77
use Github\Api\Repository\Forks;
8+
use Github\AuthMethod;
89
use Github\Client;
910
use Github\Exception\RuntimeException as GithubRuntimeException;
1011
use RuntimeException;
@@ -14,9 +15,12 @@
1415
use Symfony\Component\Console\Output\OutputInterface;
1516
use Yiisoft\YiiDevTool\App\Component\Console\OutputManager;
1617
use Yiisoft\YiiDevTool\App\Component\Console\YiiDevToolStyle;
18+
use Yiisoft\YiiDevTool\App\Component\GitHubTokenAware;
1719

1820
final class ForksRepositoriesCommand extends Command
1921
{
22+
use GitHubTokenAware;
23+
2024
private ?OutputManager $io = null;
2125

2226
protected function initialize(InputInterface $input, OutputInterface $output)
@@ -45,15 +49,15 @@ protected function configure()
4549
parent::configure();
4650
}
4751

48-
protected function execute(InputInterface $input, OutputInterface $output)
52+
protected function execute(InputInterface $input, OutputInterface $output): int
4953
{
5054
$ownerRepository = $input->getArgument('owner');
5155
$repositories = $input->getArgument('repositories');
5256

5357
$targetRepositories = array_unique(explode(',', $repositories));
5458

5559
$client = new Client();
56-
$client->authenticate($this->getToken(), null, Client::AUTH_ACCESS_TOKEN);
60+
$client->authenticate($this->getGitHubToken(), null, AuthMethod::ACCESS_TOKEN);
5761
$forks = (new Forks($client));
5862

5963
foreach ($targetRepositories as $repository) {
@@ -74,16 +78,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
7478
return Command::SUCCESS;
7579
}
7680

77-
private function getToken(): string
78-
{
79-
$tokenFile = $this->getAppRootDir() . 'config/github.token';
80-
if (!file_exists($tokenFile)) {
81-
throw new RuntimeException("There's no $tokenFile. Please create one and put your GitHub token there. You may create it here: https://github.com/settings/tokens. Choose 'repo' rights.");
82-
}
83-
84-
return trim(file_get_contents($tokenFile));
85-
}
86-
8781
/**
8882
* Use this method to get a root directory of the tool.
8983
*

src/App/Command/Github/ProtectBranchCommand.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
namespace Yiisoft\YiiDevTool\App\Command\Github;
66

77
use Github\Api\Repository\Protection;
8+
use Github\AuthMethod;
89
use Github\Client;
9-
use RuntimeException;
1010
use Symfony\Component\Console\Input\InputArgument;
1111
use Symfony\Component\Console\Input\InputInterface;
1212
use Yiisoft\YiiDevTool\App\Component\Console\PackageCommand;
1313
use Yiisoft\YiiDevTool\App\Component\Package\Package;
14+
use Yiisoft\YiiDevTool\App\Component\GitHubTokenAware;
1415

1516
final class ProtectBranchCommand extends PackageCommand
1617
{
18+
use GitHubTokenAware;
19+
1720
private ?string $branch = null;
1821

1922
protected function configure()
@@ -42,7 +45,7 @@ protected function processPackage(Package $package): void
4245
$io->preparePackageHeader($package, 'Protecting {package}');
4346

4447
$client = new Client();
45-
$client->authenticate($this->getToken(), null, Client::AUTH_ACCESS_TOKEN);
48+
$client->authenticate($this->getGitHubToken(), null, AuthMethod::ACCESS_TOKEN);
4649
$protectionApi = (new Protection($client));
4750

4851
// See https://docs.github.com/en/rest/reference/repos#update-branch-protection
@@ -53,14 +56,4 @@ protected function processPackage(Package $package): void
5356
'restrictions' => null,
5457
]);
5558
}
56-
57-
private function getToken(): string
58-
{
59-
$tokenFile = $this->getAppRootDir() . 'config/github.token';
60-
if (!file_exists($tokenFile)) {
61-
throw new RuntimeException("There's no $tokenFile. Please create one and put your GitHub token there. You may create it here: https://github.com/settings/tokens. Choose 'repo' rights.");
62-
}
63-
64-
return trim(file_get_contents($tokenFile));
65-
}
6659
}

src/App/Command/Github/SettingsCommand.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
namespace Yiisoft\YiiDevTool\App\Command\Github;
66

77
use Github\Api\Repo;
8+
use Github\AuthMethod;
89
use Github\Client;
9-
use RuntimeException;
1010
use Yiisoft\YiiDevTool\App\Component\Console\PackageCommand;
1111
use Yiisoft\YiiDevTool\App\Component\Package\Package;
12+
use Yiisoft\YiiDevTool\App\Component\GitHubTokenAware;
1213

1314
final class SettingsCommand extends PackageCommand
1415
{
16+
use GitHubTokenAware;
17+
1518
protected function configure()
1619
{
1720
$this
@@ -32,7 +35,7 @@ protected function processPackage(Package $package): void
3235
$io->preparePackageHeader($package, 'Adjusting settings for {package}');
3336

3437
$client = new Client();
35-
$client->authenticate($this->getToken(), null, Client::AUTH_ACCESS_TOKEN);
38+
$client->authenticate($this->getGitHubToken(), null, AuthMethod::ACCESS_TOKEN);
3639
$repoApi = new Repo($client);
3740

3841
$repoApi->update($package->getVendor(), $package->getId(), $this->getSettings());
@@ -43,14 +46,4 @@ private function getSettings(): array
4346
/** @noinspection PhpIncludeInspection */
4447
return require $this->getAppRootDir() . 'config/settings.php';
4548
}
46-
47-
private function getToken(): string
48-
{
49-
$tokenFile = $this->getAppRootDir() . 'config/github.token';
50-
if (!file_exists($tokenFile)) {
51-
throw new RuntimeException("There's no $tokenFile. Please create one and put your GitHub token there. You may create it here: https://github.com/settings/tokens. Choose 'repo' rights.");
52-
}
53-
54-
return trim(file_get_contents($tokenFile));
55-
}
5649
}

src/App/Command/Github/SyncUpstreamRepositoriesCommand.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@
88
use Github\AuthMethod;
99
use Github\Client;
1010
use Github\Exception\RuntimeException as GithubRuntimeException;
11-
use RuntimeException;
1211
use Symfony\Component\Console\Attribute\AsCommand;
1312
use Symfony\Component\Console\Input\InputInterface;
1413
use Symfony\Component\Console\Input\InputOption;
1514
use Symfony\Component\Console\Output\OutputInterface;
1615
use Yiisoft\YiiDevTool\App\Component\Console\PackageCommand;
1716
use Yiisoft\YiiDevTool\App\Component\Package\Package;
17+
use Yiisoft\YiiDevTool\App\Component\GitHubTokenAware;
1818

1919
#[AsCommand(
2020
name: 'github/sync',
2121
description: 'Sync forks from upstream repositories'
2222
)]
2323
final class SyncUpstreamRepositoriesCommand extends PackageCommand
2424
{
25+
use GitHubTokenAware;
26+
2527
private InputInterface $input;
2628

2729
protected function initialize(InputInterface $input, OutputInterface $output)
@@ -79,7 +81,7 @@ private function errorMessage($packageName, $message = ''): array
7981
private function getGithubApiRepository(): Repo
8082
{
8183
$client = new Client();
82-
$client->authenticate($this->getToken(), null, AuthMethod::ACCESS_TOKEN);
84+
$client->authenticate($this->getGitHubToken(), null, AuthMethod::ACCESS_TOKEN);
8385
// Remove anonymous class when method is added to github-api package
8486
// https://github.com/KnpLabs/php-github-api/issues/1083
8587
return new class ($client) extends Repo {
@@ -93,14 +95,4 @@ public function mergeUpstream($username, $repository, $branchName = null)
9395
};
9496
// return (new Repo($client));
9597
}
96-
97-
private function getToken(): string
98-
{
99-
$tokenFile = $this->getAppRootDir() . 'config/github.token';
100-
if (!file_exists($tokenFile)) {
101-
throw new RuntimeException("There's no $tokenFile. Please create one and put your GitHub token there. You may create it here: https://github.com/settings/tokens. Choose 'repo' rights.");
102-
}
103-
104-
return trim(file_get_contents($tokenFile));
105-
}
10698
}

src/App/Command/Release/MakeCommand.php

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
use Yiisoft\YiiDevTool\Infrastructure\Composer\ComposerPackage;
1919
use Yiisoft\YiiDevTool\Infrastructure\Composer\Config\ComposerConfig;
2020
use Yiisoft\YiiDevTool\Infrastructure\Version;
21+
use Yiisoft\YiiDevTool\App\Component\GitHubTokenAware;
2122

2223
use function in_array;
2324

2425
final class MakeCommand extends PackageCommand
2526
{
27+
use GitHubTokenAware;
28+
2629
private ?string $tag = null;
2730

2831
private const MAIN_BRANCHES = ['master', 'main'];
@@ -32,7 +35,7 @@ protected function configure()
3235
$this
3336
->setName('release/make')
3437
->setDescription('Make a package release')
35-
->addOption('tag', null, InputArgument::OPTIONAL, 'Version to tag');
38+
->addOption('tag', null, InputArgument::OPTIONAL, description: 'Version to tag');
3639

3740
parent::configure();
3841
}
@@ -84,18 +87,6 @@ protected function processPackage(Package $package): void
8487
return;
8588
}
8689

87-
$tokenFile = $this->getAppRootDir() . 'config/github.token';
88-
if (!file_exists($tokenFile)) {
89-
$io->warning([
90-
"There's no $tokenFile. Please create one and put your GitHub token there.",
91-
'Token is required to create release on GitHub.',
92-
"You may create it here: https://github.com/settings/tokens. Choose 'repo' rights.",
93-
'Release cancelled.',
94-
]);
95-
96-
return;
97-
}
98-
9990
$dependencyList = $composerConfig->getDependencyList(ComposerConfig::SECTION_REQUIRE);
10091
foreach ($dependencyList->getDependencies() as $dependency) {
10192
if ($dependency->constraintContainsAnyOfStabilityFlags($unstableFlags)) {
@@ -182,9 +173,9 @@ protected function processPackage(Package $package): void
182173
'm' => 'Prepare for next release',
183174
]);
184175

185-
if ($this->confirm('Push commits and tags, and release on GitHub?')) {
176+
if ($this->confirm('Push commits and tag, and release on GitHub?')) {
186177
$git->push();
187-
$git->pushTags();
178+
$git->pushTag((string) $versionToRelease);
188179

189180
$this->releaseOnGithub($package, $versionToRelease);
190181

@@ -254,7 +245,7 @@ private function releaseOnGithub(Package $package, Version $versionToRelease): v
254245

255246
$client = new Client();
256247
try {
257-
$token = $this->getToken();
248+
$token = $this->getGitHubToken();
258249
} catch (RuntimeException $e) {
259250
$io->error($e->getMessage());
260251
$io->warning('Skipped creating release on GitHub.');
@@ -273,16 +264,6 @@ private function releaseOnGithub(Package $package, Version $versionToRelease): v
273264
]);
274265
}
275266

276-
private function getToken(): string
277-
{
278-
$tokenFile = $this->getAppRootDir() . 'config/github.token';
279-
if (!file_exists($tokenFile)) {
280-
throw new RuntimeException("There's no $tokenFile. Please create one and put your GitHub token there. You may create it here: https://github.com/settings/tokens. Choose 'repo' rights.");
281-
}
282-
283-
return trim(file_get_contents($tokenFile));
284-
}
285-
286267
private function displayReleaseSummary(Package $package, ComposerConfig $composerConfig, Changelog $changelog, Version $versionToRelease): void
287268
{
288269
$packageName = $package->getName();
@@ -313,7 +294,7 @@ private function displayReleaseSummary(Package $package, ComposerConfig $compose
313294
}
314295

315296
$text = <<<TEXT
316-
[$description](https://github.com/yiisoft/$packageName) version $versionToRelease was released.
297+
[$description](https://github.com/$packageName) version $versionToRelease was released.
317298
In this version:
318299
319300
$changes

src/App/Component/Console/PackageCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private function isCurrentInstallationValid(Package $package): bool
240240
return true;
241241
}
242242

243-
protected function execute(InputInterface $input, OutputInterface $output)
243+
protected function execute(InputInterface $input, OutputInterface $output): int
244244
{
245245
$this->initPackageList();
246246
$this->initTargetPackages($input);

0 commit comments

Comments
 (0)