Skip to content

Commit e3057e2

Browse files
committed
#443: Allow setting of gitlab base url
1 parent 6f05b66 commit e3057e2

File tree

6 files changed

+39
-24
lines changed

6 files changed

+39
-24
lines changed

.github/workflows/markdown-normalize.yml

-19
This file was deleted.

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
runs-on: ubuntu-latest
66
strategy:
77
matrix:
8-
php: ['8.1']
8+
php: ['8.1', '8.2']
99
laravel: [10.*]
1010
dependency-version: [prefer-stable]
1111
include:

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"dg/bypass-finals": "^1.4",
3939
"mikey179/vfsstream": "^1.6",
4040
"mockery/mockery": "^1.5",
41-
"orchestra/testbench": "^8.0",
41+
"orchestra/testbench": "^8.1",
4242
"phpunit/phpunit": "^9.5.26"
4343
},
4444
"minimum-stability": "dev",

config/self-update.php

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
'use_branch' => env('SELF_UPDATER_USE_BRANCH', ''),
5151
],
5252
'gitlab' => [
53+
'base_url' => '',
5354
'type' => 'gitlab',
5455
'repository_id' => env('SELF_UPDATER_REPO_URL', ''),
5556
'download_path' => env('SELF_UPDATER_DOWNLOAD_PATH', '/tmp'),

src/SourceRepositoryTypes/GitlabRepositoryType.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,19 @@ public function selectRelease(Collection $collection, string $version)
144144
return $release;
145145
}
146146

147-
final public function getReleases(): Response
147+
/**
148+
* @return array{base_url:string, url:string}
149+
*/
150+
final public function getReleaseUrl(): array
148151
{
149-
$url = '/api/v4/projects/'.$this->config['repository_id'].'/releases';
152+
return [
153+
'base_url' => $this->config['base_url'] ?? self::BASE_URL,
154+
'url' => '/api/v4/projects/'.$this->config['repository_id'].'/releases',
155+
];
156+
}
150157

158+
final public function getReleases(): Response
159+
{
151160
$headers = [];
152161

153162
if ($this->release->hasAccessToken()) {
@@ -156,6 +165,8 @@ final public function getReleases(): Response
156165
];
157166
}
158167

159-
return Http::withHeaders($headers)->baseUrl(self::BASE_URL)->get($url);
168+
$urls = $this->getReleaseUrl();
169+
170+
return Http::withHeaders($headers)->baseUrl($urls['base_url'])->get($urls['url']);
160171
}
161172
}

tests/SourceRepositoryTypes/GitlabRepositoryTypeTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,26 @@ public function it_takes_latest_release_if_no_other_found(): void
174174

175175
$this->assertEquals('1.3', $gitlab->selectRelease(collect($items), '1.7')['tag_name']);
176176
}
177+
178+
/** @test */
179+
public function it_can_use_default_base_url(): void
180+
{
181+
/** @var GitlabRepositoryType $gitlab */
182+
$gitlab = resolve(GitlabRepositoryType::class);
183+
$urls = $gitlab->getReleaseUrl();
184+
185+
$this->assertEquals('https://gitlab.com', $urls['base_url']);
186+
}
187+
188+
/** @test */
189+
public function it_can_use_base_url_from_config(): void
190+
{
191+
config(['self-update.repository_types.gitlab.base_url' => 'https://example.local']);
192+
193+
/** @var GitlabRepositoryType $gitlab */
194+
$gitlab = resolve(GitlabRepositoryType::class);
195+
$urls = $gitlab->getReleaseUrl();
196+
197+
$this->assertEquals('https://example.local', $urls['base_url']);
198+
}
177199
}

0 commit comments

Comments
 (0)