diff options
author | John Molakvoæ <skjnldsv@protonmail.com> | 2022-10-27 13:43:55 +0300 |
---|---|---|
committer | John Molakvoæ <skjnldsv@protonmail.com> | 2022-10-27 13:43:55 +0300 |
commit | bf74c0524d324ce87d84a48729c8a95d3335956b (patch) | |
tree | 4886f6806d4c1ca8928df14fe8cf2719e3f8b808 | |
parent | 55ee0f96bb2cdaff8c3a4f21902d6f84f1dcd3a9 (diff) |
Authenticate for repos get as well
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
-rw-r--r-- | changelog/index.php | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/changelog/index.php b/changelog/index.php index bbe7dc7..aac621d 100644 --- a/changelog/index.php +++ b/changelog/index.php @@ -82,6 +82,7 @@ class GenerateChangelogCommand extends Command { $client = new \GuzzleHttp\Client(); $ghClient = new \Github\Client(); + $this->authenticateGithubClient($ghClient); // TODO iterate over all repos $shippedApps = []; @@ -112,6 +113,19 @@ class GenerateChangelogCommand extends Command return [...$reposToIterate, ...array_intersect($orgRepositories, $shippedApps)]; } + protected function authenticateGithubClient(\Github\Client $client) { + if (!file_exists(__DIR__ . '/../credentials.json')) { + throw new Exception('Credentials file is missing - please provide your credentials in credentials.json in the root folder.'); + } + + $credentialsData = json_decode(file_get_contents(__DIR__ . '/../credentials.json'), true); + if (!is_array($credentialsData) || !isset($credentialsData['apikey'])) { + throw new Exception('Credentials file can not be read or does not provide "apikey".'); + } + + $client->authenticate($credentialsData['apikey'], Github\Client::AUTH_ACCESS_TOKEN); + } + /** * @throws Exception */ @@ -193,7 +207,7 @@ class GenerateChangelogCommand extends Command $client = new \Github\Client(); # TODO #$client->addCache($pool); - $client->authenticate($credentialsData['apikey'], Github\Client::AUTH_ACCESS_TOKEN); + $this->authenticateGithubClient($client); $factor = 2; if ($milestoneToCheck !== null) { |