Skip to content

Commit db06fc8

Browse files
committed
Add Bitbucket V2 source control using OAuth consumers
1 parent bb24726 commit db06fc8

File tree

3 files changed

+408
-3
lines changed

3 files changed

+408
-3
lines changed

app/Actions/SourceControl/ConnectSourceControl.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,21 @@ public function connect(User $user, array $input): SourceControl
2929

3030
$sourceControl->provider_data = $sourceControl->provider()->createData($input);
3131

32-
if (! $sourceControl->provider()->connect()) {
32+
try {
33+
if (! $sourceControl->provider()->connect()) {
34+
throw ValidationException::withMessages([
35+
'provider' => __('Cannot connect to :provider or invalid credentials!', ['provider' => $sourceControl->provider]),
36+
]);
37+
}
38+
} catch (\Exception $e) {
39+
// Re-throw validation exceptions as-is
40+
if ($e instanceof ValidationException) {
41+
throw $e;
42+
}
43+
44+
// For all other exceptions, wrap in validation exception to show the error message in the frontend
3345
throw ValidationException::withMessages([
34-
'token' => __('Cannot connect to :provider or invalid token!', ['provider' => $sourceControl->provider]),
46+
'provider' => $e->getMessage(),
3547
]);
3648
}
3749

app/Providers/SourceControlServiceProvider.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\DTOs\DynamicForm;
77
use App\Plugins\RegisterSourceControl;
88
use App\SourceControlProviders\Bitbucket;
9+
use App\SourceControlProviders\BitbucketV2;
910
use App\SourceControlProviders\Gitea;
1011
use App\SourceControlProviders\Github;
1112
use App\SourceControlProviders\Gitlab;
@@ -20,6 +21,7 @@ public function boot(): void
2021
$this->github();
2122
$this->gitlab();
2223
$this->bitbucket();
24+
$this->bitbucketV2();
2325
$this->gitea();
2426
}
2527

@@ -59,7 +61,7 @@ private function gitlab(): void
5961
private function bitbucket(): void
6062
{
6163
RegisterSourceControl::make(Bitbucket::id())
62-
->label('Bitbucket')
64+
->label('Bitbucket (deprecated)')
6365
->handler(Bitbucket::class)
6466
->form(
6567
DynamicForm::make([
@@ -74,6 +76,24 @@ private function bitbucket(): void
7476
->register();
7577
}
7678

79+
private function bitbucketV2(): void
80+
{
81+
RegisterSourceControl::make(BitbucketV2::id())
82+
->label('Bitbucket V2')
83+
->handler(BitbucketV2::class)
84+
->form(
85+
DynamicForm::make([
86+
DynamicField::make('key')
87+
->text()
88+
->label('Key'),
89+
DynamicField::make('secret')
90+
->text()
91+
->label('Secret'),
92+
])
93+
)
94+
->register();
95+
}
96+
7797
private function gitea(): void
7898
{
7999
RegisterSourceControl::make(Gitea::id())

0 commit comments

Comments
 (0)