Skip to content

Commit a211b11

Browse files
authored
#443 Set Gitlab base url (#445)
1 parent 6f05b66 commit a211b11

File tree

9 files changed

+61
-43
lines changed

9 files changed

+61
-43
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:

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ Configure Gitlab either via the `config/self-updater.php` or use the appropriate
176176
// ...
177177
'repository_types' => [
178178
'gitlab' => [
179+
'base_url' => '',
179180
'type' => 'gitlab',
180181
'repository_id' => env('SELF_UPDATER_REPO_URL', ''),
181182
'download_path' => env('SELF_UPDATER_DOWNLOAD_PATH', '/tmp'),
@@ -187,6 +188,8 @@ Configure Gitlab either via the `config/self-updater.php` or use the appropriate
187188

188189
ℹ Although the environment variable is named `SELF_UPDATER_REPO_URL`, only specify your repository id.
189190

191+
For self-hosted Gitlab instances you can set the `base_url` variable to a domain where the instance is hosted at, f. ex. `http://gitlab.acme.local`.
192+
190193
### Using HTTP archives
191194

192195
The package comes with an _HTTP_ source repository type to fetch

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/Commands/CheckUpdateTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function it_can_run_check_update_command_without_new_version_available():
2626
->pushResponse($this->getResponse200ZipFile());
2727

2828
/** @var GithubTagType $github */
29-
$github = (resolve(GithubRepositoryType::class))->create();
29+
$github = resolve(GithubRepositoryType::class)->create();
3030

3131
$github->deleteVersionFile();
3232

@@ -41,7 +41,7 @@ public function it_can_run_check_update_command_without_new_version_available():
4141
public function it_can_run_check_update_command_with_new_version_available(): void
4242
{
4343
/** @var GithubTagType $github */
44-
$github = (resolve(GithubRepositoryType::class))->create();
44+
$github = resolve(GithubRepositoryType::class)->create();
4545
$github->setVersionFile('v3.5');
4646

4747
config(['self-update.version_installed' => 'v1.0']);

tests/SourceRepositoryTypes/GithubRepositoryTypeTest.php

+17-17
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function setUp(): void
2828
public function it_can_instantiate(): void
2929
{
3030
/** @var GithubTagType $github */
31-
$github = (resolve(GithubRepositoryType::class))->create();
31+
$github = resolve(GithubRepositoryType::class)->create();
3232

3333
$this->assertInstanceOf(GithubTagType::class, $github);
3434
}
@@ -39,7 +39,7 @@ public function it_can_instantiate_branch_type(): void
3939
config(['self-update.repository_types.github.use_branch' => 'v2']);
4040

4141
/** @var GithubBranchType $github */
42-
$github = (resolve(GithubRepositoryType::class))->create();
42+
$github = resolve(GithubRepositoryType::class)->create();
4343

4444
$this->assertInstanceOf(GithubBranchType::class, $github);
4545
}
@@ -52,14 +52,14 @@ public function it_cannot_instantiate_and_fails_with_exception(): void
5252
$this->expectException(\Exception::class);
5353

5454
/** @var GithubTagType $github */
55-
$github = (resolve(GithubRepositoryType::class))->create();
55+
$github = resolve(GithubRepositoryType::class)->create();
5656
}
5757

5858
/** @test */
5959
public function it_can_run_update(): void
6060
{
6161
/** @var GithubTagType $github */
62-
$github = (resolve(GithubRepositoryType::class))->create();
62+
$github = resolve(GithubRepositoryType::class)->create();
6363

6464
Http::fake([
6565
'*' => $this->getResponse200ZipFile(),
@@ -89,7 +89,7 @@ public function it_can_run_update(): void
8989
public function it_can_get_the_version_installed(): void
9090
{
9191
/** @var GithubTagType $github */
92-
$github = (resolve(GithubRepositoryType::class))->create();
92+
$github = resolve(GithubRepositoryType::class)->create();
9393
$this->assertEmpty($github->getVersionInstalled());
9494

9595
config(['self-update.version_installed' => '1.0']);
@@ -103,15 +103,15 @@ public function it_cannot_get_new_version_available_and_fails_with_exception():
103103
$this->expectExceptionMessage('Version installed not found.');
104104

105105
/** @var GithubTagType $github */
106-
$github = (resolve(GithubRepositoryType::class))->create();
106+
$github = resolve(GithubRepositoryType::class)->create();
107107
$github->isNewVersionAvailable();
108108
}
109109

110110
/** @test */
111111
public function it_can_get_new_version_available_from_type_tag_without_version_file(): void
112112
{
113113
/** @var GithubTagType $github */
114-
$github = (resolve(GithubRepositoryType::class))->create();
114+
$github = resolve(GithubRepositoryType::class)->create();
115115
$github->deleteVersionFile();
116116

117117
Event::fake();
@@ -132,7 +132,7 @@ public function it_can_get_new_version_available_from_type_tag_without_version_f
132132
public function it_can_get_new_version_available_from_type_tag_with_version_file(): void
133133
{
134134
/** @var GithubTagType $github */
135-
$github = (resolve(GithubRepositoryType::class))->create();
135+
$github = resolve(GithubRepositoryType::class)->create();
136136
$github->setVersionFile('v2.7');
137137

138138
$this->assertFalse($github->isNewVersionAvailable('v2.7'));
@@ -149,7 +149,7 @@ public function it_can_get_new_version_available_from_type_branch_without_versio
149149
config(['self-update.repository_types.github.use_branch' => 'v2']);
150150

151151
/** @var GithubBranchType $github */
152-
$github = (resolve(GithubRepositoryType::class))->create();
152+
$github = resolve(GithubRepositoryType::class)->create();
153153
$github->deleteVersionFile();
154154

155155
Http::fake([
@@ -166,7 +166,7 @@ public function it_can_get_new_version_available_from_type_branch_with_version_f
166166
config(['self-update.repository_types.github.use_branch' => 'v2']);
167167

168168
/** @var GithubBranchType $github */
169-
$github = (resolve(GithubRepositoryType::class))->create();
169+
$github = resolve(GithubRepositoryType::class)->create();
170170
$github->setVersionFile('2020-02-07T21:09:15Z');
171171

172172
$this->assertFalse($github->isNewVersionAvailable('2020-02-08T21:09:15Z'));
@@ -177,7 +177,7 @@ public function it_can_get_new_version_available_from_type_branch_with_version_f
177177
public function it_can_fetch_github_tag_releases_latest(): void
178178
{
179179
/** @var GithubTagType $github */
180-
$github = (resolve(GithubRepositoryType::class))->create();
180+
$github = resolve(GithubRepositoryType::class)->create();
181181

182182
Http::fakeSequence()
183183
->pushResponse($this->getResponse200Type('tag'))
@@ -194,7 +194,7 @@ public function it_can_fetch_github_tag_releases_latest(): void
194194
public function it_can_fetch_github_tag_releases_specific_version(): void
195195
{
196196
/** @var GithubTagType $github */
197-
$github = (resolve(GithubRepositoryType::class))->create();
197+
$github = resolve(GithubRepositoryType::class)->create();
198198

199199
Http::fakeSequence()
200200
->pushResponse($this->getResponse200Type('tag'))
@@ -211,7 +211,7 @@ public function it_can_fetch_github_tag_releases_specific_version(): void
211211
public function it_can_fetch_github_tag_releases_and_takes_latest_if_version_not_available(): void
212212
{
213213
/** @var GithubTagType $github */
214-
$github = (resolve(GithubRepositoryType::class))->create();
214+
$github = resolve(GithubRepositoryType::class)->create();
215215

216216
Http::fakeSequence()
217217
->pushResponse($this->getResponse200Type('tag'))
@@ -230,7 +230,7 @@ public function it_can_fetch_github_branch_releases_latest(): void
230230
config(['self-update.repository_types.github.use_branch' => 'v2']);
231231

232232
/** @var GithubBranchType $github */
233-
$github = (resolve(GithubRepositoryType::class))->create();
233+
$github = resolve(GithubRepositoryType::class)->create();
234234

235235
Http::fakeSequence()
236236
->pushResponse($this->getResponse200Type('branch'))
@@ -249,7 +249,7 @@ public function it_can_fetch_github_branch_releases_specific_version(): void
249249
config(['self-update.repository_types.github.use_branch' => 'v2']);
250250

251251
/** @var GithubBranchType $github */
252-
$github = (resolve(GithubRepositoryType::class))->create();
252+
$github = resolve(GithubRepositoryType::class)->create();
253253

254254
Http::fakeSequence()
255255
->pushResponse($this->getResponse200Type('branch'))
@@ -268,7 +268,7 @@ public function it_can_fetch_github_branch_releases_and_takes_latest_if_version_
268268
config(['self-update.repository_types.github.use_branch' => 'v2']);
269269

270270
/** @var GithubBranchType $github */
271-
$github = (resolve(GithubRepositoryType::class))->create();
271+
$github = resolve(GithubRepositoryType::class)->create();
272272

273273
Http::fakeSequence()
274274
->pushResponse($this->getResponse200Type('branch'))
@@ -287,7 +287,7 @@ public function it_cannot_fetch_github_branch_releases_if_response_empty(): void
287287
config(['self-update.repository_types.github.use_branch' => 'v2']);
288288

289289
/** @var GithubBranchType $github */
290-
$github = (resolve(GithubRepositoryType::class))->create();
290+
$github = resolve(GithubRepositoryType::class)->create();
291291

292292
Http::fake([
293293
'*' => $this->getResponseEmpty(),

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)