-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0fed669
commit c5a46ac
Showing
7 changed files
with
111 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
return [ | ||
'github' => 'GitHub', | ||
'bitbucket' => 'BitBucket', | ||
'envoyer' => 'Envoyer', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace TallStackUi\EnvBar\Providers; | ||
|
||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\Http; | ||
|
||
class EnvoyerProvider extends AbstractProvider | ||
{ | ||
protected array $keys = [ | ||
'token', | ||
'project_id', | ||
]; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function fetch(): ?string | ||
{ | ||
$this->validate(); | ||
|
||
return Cache::remember($this->cacheKey(), now()->addDays($this->configuration->get('cached_for', 1)), function (): ?string { | ||
$response = Http::withToken($this->configuration->get('token')) | ||
->get('https://envoyer.io/api/projects/'.$this->configuration->get('project_id')); | ||
|
||
return $response->failed() | ||
? null | ||
: $response->json('project.last_deployed_branch'); | ||
}); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function provider(): string | ||
{ | ||
return 'envoyer'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace Tests\Browser\EnvBar; | ||
|
||
use Illuminate\Config\Repository; | ||
use Illuminate\Support\Facades\Cache; | ||
use Laravel\Dusk\Browser; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\Attributes\TestWith; | ||
use Tests\Browser\BrowserTestCase; | ||
|
||
class EnvoyerProviderTest extends BrowserTestCase | ||
{ | ||
#[Test] | ||
public function see_release(): void | ||
{ | ||
$this->beforeServingApplication(function ($app, Repository $config): void { | ||
Cache::shouldReceive('remember')->andReturn('v2.0.0'); | ||
|
||
$config->set('envbar.provider', 'envoyer'); | ||
|
||
$config->set('envbar.providers.envoyer', [ | ||
'token' => 'tallstackui', | ||
'project_id' => '12345', | ||
]); | ||
}); | ||
|
||
$this->browse(function (Browser $browser): void { | ||
$browser->visit('/') | ||
->waitForText('Latest Envoyer Release') | ||
->assertSee('Latest Envoyer Release') | ||
->assertSee('v2.0.0'); | ||
}); | ||
} | ||
|
||
#[Test] | ||
#[TestWith(['', '12345'])] | ||
#[TestWith(['foo', ''])] | ||
public function throw_exception_when_parameters_is_empty(string $token, string $project): void | ||
{ | ||
$this->beforeServingApplication(function ($app, Repository $config) use ($token, $project): void { | ||
Cache::shouldReceive('remember')->andReturn('v2.0.0'); | ||
|
||
$config->set('envbar.provider', 'envoyer'); | ||
|
||
$config->set('envbar.providers.envoyer', [ | ||
'token' => $token, | ||
'project_id' => $project, | ||
]); | ||
}); | ||
|
||
$this->browse(function (Browser $browser) use ($token): void { | ||
$expected = $token === '' ? 'token' : 'repository'; | ||
|
||
$browser->visit('/')->assertSee("The Envoyer provider requires the $expected key to be set."); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters