Skip to content

Commit

Permalink
ENH Allow using .env file for github token (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Mar 13, 2023
1 parent 027abd0 commit b3591a1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Cow includes commands to help synchronise standardised data to all
* `cow github:ratelimit` Check your current GitHub API rate limiting status (sync commands can use this up quickly)

**Note:** All GitHub API commands require a `GITHUB_ACCESS_TOKEN` environment variable to be set before they can be
used.
used. It can be in the .env file (see [dev mode](#dev_mode)).

### Labels

Expand Down
3 changes: 3 additions & 0 deletions src/Steps/Release/PublishRelease.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ protected function getGithubClient(OutputInterface $output)
protected function getOAUTHToken(OutputInterface $output)
{
$token = getenv('GITHUB_API_TOKEN');
if (empty($token)) {
$token = $_ENV['GITHUB_API_TOKEN'];
}
if (empty($token)) {
$token = Composer::getOAUTHToken($this->getCommandRunner($output));
}
Expand Down
5 changes: 3 additions & 2 deletions src/Utility/GitHubApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ class GitHubApi
public function getClient()
{
if (!$this->client) {
$token = getenv(self::TOKEN_ENV_VAR) ?: $_ENV[self::TOKEN_ENV_VAR];
// Handled here rather than constructor so that exceptions will be formatted by SymfonyStyle
if (!getenv(self::TOKEN_ENV_VAR)) {
if (!$token) {
throw new RuntimeException(self::TOKEN_ENV_VAR . ' environment variable is not defined!');
}

$this->client = new Client();
$this->client->authenticate(getenv(self::TOKEN_ENV_VAR), null, Client::AUTH_HTTP_TOKEN);
$this->client->authenticate($token, null, Client::AUTH_HTTP_TOKEN);
}
return $this->client;
}
Expand Down

0 comments on commit b3591a1

Please sign in to comment.