diff --git a/.github/workflows/markdown-normalize.yml b/.github/workflows/markdown-normalize.yml deleted file mode 100644 index 0a8c4fa..0000000 --- a/.github/workflows/markdown-normalize.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: normalize markdown - -on: - push: - paths: - - '*.md' - -jobs: - normalize: - timeout-minutes: 1 - runs-on: ubuntu-latest - steps: - - name: Git checkout - uses: actions/checkout@v3 - - - name: Prettify markdown - uses: creyD/prettier_action@v4.3 - with: - prettier_options: --write **/*.md diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 032707c..35f0675 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: ['8.1'] + php: ['8.1', '8.2'] laravel: [10.*] dependency-version: [prefer-stable] include: diff --git a/README.md b/README.md index ef92abc..796d042 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,7 @@ Configure Gitlab either via the `config/self-updater.php` or use the appropriate // ... 'repository_types' => [ 'gitlab' => [ + 'base_url' => '', 'type' => 'gitlab', 'repository_id' => env('SELF_UPDATER_REPO_URL', ''), '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 ℹ Although the environment variable is named `SELF_UPDATER_REPO_URL`, only specify your repository id. +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`. + ### Using HTTP archives The package comes with an _HTTP_ source repository type to fetch diff --git a/composer.json b/composer.json index e0d36ab..966e629 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "dg/bypass-finals": "^1.4", "mikey179/vfsstream": "^1.6", "mockery/mockery": "^1.5", - "orchestra/testbench": "^8.0", + "orchestra/testbench": "^8.1", "phpunit/phpunit": "^9.5.26" }, "minimum-stability": "dev", diff --git a/config/self-update.php b/config/self-update.php index eef1702..b7d348d 100644 --- a/config/self-update.php +++ b/config/self-update.php @@ -50,6 +50,7 @@ 'use_branch' => env('SELF_UPDATER_USE_BRANCH', ''), ], 'gitlab' => [ + 'base_url' => '', 'type' => 'gitlab', 'repository_id' => env('SELF_UPDATER_REPO_URL', ''), 'download_path' => env('SELF_UPDATER_DOWNLOAD_PATH', '/tmp'), diff --git a/src/SourceRepositoryTypes/GitlabRepositoryType.php b/src/SourceRepositoryTypes/GitlabRepositoryType.php index 2522167..9648093 100644 --- a/src/SourceRepositoryTypes/GitlabRepositoryType.php +++ b/src/SourceRepositoryTypes/GitlabRepositoryType.php @@ -144,10 +144,19 @@ public function selectRelease(Collection $collection, string $version) return $release; } - final public function getReleases(): Response + /** + * @return array{base_url:string, url:string} + */ + final public function getReleaseUrl(): array { - $url = '/api/v4/projects/'.$this->config['repository_id'].'/releases'; + return [ + 'base_url' => $this->config['base_url'] ?? self::BASE_URL, + 'url' => '/api/v4/projects/'.$this->config['repository_id'].'/releases', + ]; + } + final public function getReleases(): Response + { $headers = []; if ($this->release->hasAccessToken()) { @@ -156,6 +165,8 @@ final public function getReleases(): Response ]; } - return Http::withHeaders($headers)->baseUrl(self::BASE_URL)->get($url); + $urls = $this->getReleaseUrl(); + + return Http::withHeaders($headers)->baseUrl($urls['base_url'])->get($urls['url']); } } diff --git a/tests/Commands/CheckUpdateTest.php b/tests/Commands/CheckUpdateTest.php index ae6720b..57a4624 100644 --- a/tests/Commands/CheckUpdateTest.php +++ b/tests/Commands/CheckUpdateTest.php @@ -26,7 +26,7 @@ public function it_can_run_check_update_command_without_new_version_available(): ->pushResponse($this->getResponse200ZipFile()); /** @var GithubTagType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); $github->deleteVersionFile(); @@ -41,7 +41,7 @@ public function it_can_run_check_update_command_without_new_version_available(): public function it_can_run_check_update_command_with_new_version_available(): void { /** @var GithubTagType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); $github->setVersionFile('v3.5'); config(['self-update.version_installed' => 'v1.0']); diff --git a/tests/SourceRepositoryTypes/GithubRepositoryTypeTest.php b/tests/SourceRepositoryTypes/GithubRepositoryTypeTest.php index fc8f0aa..93f33df 100644 --- a/tests/SourceRepositoryTypes/GithubRepositoryTypeTest.php +++ b/tests/SourceRepositoryTypes/GithubRepositoryTypeTest.php @@ -28,7 +28,7 @@ protected function setUp(): void public function it_can_instantiate(): void { /** @var GithubTagType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); $this->assertInstanceOf(GithubTagType::class, $github); } @@ -39,7 +39,7 @@ public function it_can_instantiate_branch_type(): void config(['self-update.repository_types.github.use_branch' => 'v2']); /** @var GithubBranchType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); $this->assertInstanceOf(GithubBranchType::class, $github); } @@ -52,14 +52,14 @@ public function it_cannot_instantiate_and_fails_with_exception(): void $this->expectException(\Exception::class); /** @var GithubTagType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); } /** @test */ public function it_can_run_update(): void { /** @var GithubTagType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); Http::fake([ '*' => $this->getResponse200ZipFile(), @@ -89,7 +89,7 @@ public function it_can_run_update(): void public function it_can_get_the_version_installed(): void { /** @var GithubTagType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); $this->assertEmpty($github->getVersionInstalled()); config(['self-update.version_installed' => '1.0']); @@ -103,7 +103,7 @@ public function it_cannot_get_new_version_available_and_fails_with_exception(): $this->expectExceptionMessage('Version installed not found.'); /** @var GithubTagType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); $github->isNewVersionAvailable(); } @@ -111,7 +111,7 @@ public function it_cannot_get_new_version_available_and_fails_with_exception(): public function it_can_get_new_version_available_from_type_tag_without_version_file(): void { /** @var GithubTagType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); $github->deleteVersionFile(); Event::fake(); @@ -132,7 +132,7 @@ public function it_can_get_new_version_available_from_type_tag_without_version_f public function it_can_get_new_version_available_from_type_tag_with_version_file(): void { /** @var GithubTagType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); $github->setVersionFile('v2.7'); $this->assertFalse($github->isNewVersionAvailable('v2.7')); @@ -149,7 +149,7 @@ public function it_can_get_new_version_available_from_type_branch_without_versio config(['self-update.repository_types.github.use_branch' => 'v2']); /** @var GithubBranchType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); $github->deleteVersionFile(); Http::fake([ @@ -166,7 +166,7 @@ public function it_can_get_new_version_available_from_type_branch_with_version_f config(['self-update.repository_types.github.use_branch' => 'v2']); /** @var GithubBranchType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); $github->setVersionFile('2020-02-07T21:09:15Z'); $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 public function it_can_fetch_github_tag_releases_latest(): void { /** @var GithubTagType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); Http::fakeSequence() ->pushResponse($this->getResponse200Type('tag')) @@ -194,7 +194,7 @@ public function it_can_fetch_github_tag_releases_latest(): void public function it_can_fetch_github_tag_releases_specific_version(): void { /** @var GithubTagType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); Http::fakeSequence() ->pushResponse($this->getResponse200Type('tag')) @@ -211,7 +211,7 @@ public function it_can_fetch_github_tag_releases_specific_version(): void public function it_can_fetch_github_tag_releases_and_takes_latest_if_version_not_available(): void { /** @var GithubTagType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); Http::fakeSequence() ->pushResponse($this->getResponse200Type('tag')) @@ -230,7 +230,7 @@ public function it_can_fetch_github_branch_releases_latest(): void config(['self-update.repository_types.github.use_branch' => 'v2']); /** @var GithubBranchType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); Http::fakeSequence() ->pushResponse($this->getResponse200Type('branch')) @@ -249,7 +249,7 @@ public function it_can_fetch_github_branch_releases_specific_version(): void config(['self-update.repository_types.github.use_branch' => 'v2']); /** @var GithubBranchType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); Http::fakeSequence() ->pushResponse($this->getResponse200Type('branch')) @@ -268,7 +268,7 @@ public function it_can_fetch_github_branch_releases_and_takes_latest_if_version_ config(['self-update.repository_types.github.use_branch' => 'v2']); /** @var GithubBranchType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); Http::fakeSequence() ->pushResponse($this->getResponse200Type('branch')) @@ -287,7 +287,7 @@ public function it_cannot_fetch_github_branch_releases_if_response_empty(): void config(['self-update.repository_types.github.use_branch' => 'v2']); /** @var GithubBranchType $github */ - $github = (resolve(GithubRepositoryType::class))->create(); + $github = resolve(GithubRepositoryType::class)->create(); Http::fake([ '*' => $this->getResponseEmpty(), diff --git a/tests/SourceRepositoryTypes/GitlabRepositoryTypeTest.php b/tests/SourceRepositoryTypes/GitlabRepositoryTypeTest.php index 3373086..06d0519 100644 --- a/tests/SourceRepositoryTypes/GitlabRepositoryTypeTest.php +++ b/tests/SourceRepositoryTypes/GitlabRepositoryTypeTest.php @@ -174,4 +174,26 @@ public function it_takes_latest_release_if_no_other_found(): void $this->assertEquals('1.3', $gitlab->selectRelease(collect($items), '1.7')['tag_name']); } + + /** @test */ + public function it_can_use_default_base_url(): void + { + /** @var GitlabRepositoryType $gitlab */ + $gitlab = resolve(GitlabRepositoryType::class); + $urls = $gitlab->getReleaseUrl(); + + $this->assertEquals('https://gitlab.com', $urls['base_url']); + } + + /** @test */ + public function it_can_use_base_url_from_config(): void + { + config(['self-update.repository_types.gitlab.base_url' => 'https://example.local']); + + /** @var GitlabRepositoryType $gitlab */ + $gitlab = resolve(GitlabRepositoryType::class); + $urls = $gitlab->getReleaseUrl(); + + $this->assertEquals('https://example.local', $urls['base_url']); + } }