Skip to content

Commit

Permalink
Retry with PAT on gitlabs (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm committed Sep 5, 2021
1 parent f2a8612 commit 4041e63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/CosyComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -807,9 +807,25 @@ public function run()
$this->client = $this->getClient($this->slug);
$this->privateClient = $this->getClient($this->slug);
$this->privateClient->authenticate($this->userToken, null);
$this->isPrivate = $this->privateClient->repoIsPrivate($this->slug);
// Get the default branch of the repo.
$default_branch = $this->privateClient->getDefaultBranch($this->slug);
try {
$this->isPrivate = $this->privateClient->repoIsPrivate($this->slug);
// Get the default branch of the repo.
$default_branch = $this->privateClient->getDefaultBranch($this->slug);
} catch (\Throwable $e) {
// Could be a personal access token.
if (!method_exists($this->privateClient, 'authenticatePersonalAccessToken')) {
throw $e;
}
try {
$this->privateClient->authenticatePersonalAccessToken($this->userToken, null);
$this->isPrivate = $this->privateClient->repoIsPrivate($this->slug);
// Get the default branch of the repo.
$default_branch = $this->privateClient->getDefaultBranch($this->slug);
} catch (\Throwable $other_exception) {
// Throw the first exception, probably.
throw $e;
}
}
// We also allow the project to override this for violinist.
if ($config->getDefaultBranch()) {
// @todo: Would be better to make sure this can actually be set, based on the branches available. Either
Expand Down
5 changes: 5 additions & 0 deletions src/Providers/Gitlab.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public function authenticatePrivate($user, $token)
$this->client->authenticate($user, Client::AUTH_OAUTH_TOKEN);
}

public function authenticatePersonalAccessToken($user, $token)
{
$this->client->authenticate($user, Client::AUTH_URL_TOKEN);
}

public function repoIsPrivate(Slug $slug)
{
// Consider all gitlab things private, since we have the API key to do so anyway.
Expand Down

0 comments on commit 4041e63

Please sign in to comment.