diff --git a/services/gitea/gitea-base.spec.js b/services/gitea/gitea-base.spec.js index 868e964920080..0323801ca5888 100644 --- a/services/gitea/gitea-base.spec.js +++ b/services/gitea/gitea-base.spec.js @@ -10,7 +10,7 @@ class DummyGiteaService extends GiteaBase { async handle() { const data = await this.fetch({ schema: Joi.any(), - url: 'https://codeberg.org/api/v1/repos/CanisHelix/shields-badge-test/releases', + url: 'https://gitea.com/api/v1/repos/CanisHelix/shields-badge-test/releases', }) return { message: data.message } } @@ -24,7 +24,7 @@ describe('GiteaBase', function () { public: { services: { gitea: { - authorizedOrigins: ['https://codeberg.org'], + authorizedOrigins: ['https://gitea.com'], }, }, }, @@ -34,7 +34,7 @@ describe('GiteaBase', function () { } it('sends the auth information as configured', async function () { - const scope = nock('https://codeberg.org') + const scope = nock('https://gitea.com') .get('/api/v1/repos/CanisHelix/shields-badge-test/releases') .matchHeader('Authorization', 'Bearer fake-key') .reply(200, { message: 'fake message' }) diff --git a/services/gitea/gitea-helper.js b/services/gitea/gitea-helper.js index 51242d819d508..684f41d6bf44f 100644 --- a/services/gitea/gitea-helper.js +++ b/services/gitea/gitea-helper.js @@ -1,5 +1,6 @@ -const documentation = ` -Note that the gitea_url parameter is required because there is canonical hosted gitea service provided by Gitea. +const description = ` +By default this badge looks for repositories on [gitea.com](https://gitea.com). +To specify another instance like [codeberg](https://codeberg.org/), [forgejo](https://forgejo.org/) or a self-hosted instance, use the \`gitea_url\` query param. ` function httpErrorsFor() { @@ -9,4 +10,4 @@ function httpErrorsFor() { } } -export { documentation, httpErrorsFor } +export { description, httpErrorsFor } diff --git a/services/gitea/gitea-languages-count.service.js b/services/gitea/gitea-languages-count.service.js index 819198521b647..4afef5d47fd87 100644 --- a/services/gitea/gitea-languages-count.service.js +++ b/services/gitea/gitea-languages-count.service.js @@ -2,7 +2,7 @@ import Joi from 'joi' import { nonNegativeInteger, optionalUrl } from '../validators.js' import { metric } from '../text-formatters.js' import { pathParam, queryParam } from '../index.js' -import { documentation, httpErrorsFor } from './gitea-helper.js' +import { description, httpErrorsFor } from './gitea-helper.js' import GiteaBase from './gitea-base.js' /* @@ -12,7 +12,7 @@ The keys could be anything and {} is a valid response (e.g: for an empty repo) const schema = Joi.object().pattern(/./, nonNegativeInteger) const queryParamSchema = Joi.object({ - gitea_url: optionalUrl.required(), + gitea_url: optionalUrl, }).required() export default class GiteaLanguageCount extends GiteaBase { @@ -28,20 +28,19 @@ export default class GiteaLanguageCount extends GiteaBase { '/gitea/languages/count/{user}/{repo}': { get: { summary: 'Gitea language count', - description: documentation, + description, parameters: [ pathParam({ name: 'user', - example: 'forgejo', + example: 'gitea', }), pathParam({ name: 'repo', - example: 'forgejo', + example: 'tea', }), queryParam({ name: 'gitea_url', - example: 'https://codeberg.org', - required: true, + example: 'https://gitea.com', }), ], }, @@ -58,7 +57,7 @@ export default class GiteaLanguageCount extends GiteaBase { } async fetch({ user, repo, baseUrl }) { - // https://try.gitea.io/api/swagger#/repository/repoGetLanguages + // https://gitea.com/api/swagger#/repository/repoGetLanguages return super.fetch({ schema, url: `${baseUrl}/api/v1/repos/${user}/${repo}/languages`, @@ -66,7 +65,7 @@ export default class GiteaLanguageCount extends GiteaBase { }) } - async handle({ user, repo }, { gitea_url: baseUrl }) { + async handle({ user, repo }, { gitea_url: baseUrl = 'https://gitea.com' }) { const data = await this.fetch({ user, repo, diff --git a/services/gitea/gitea-languages-count.tester.js b/services/gitea/gitea-languages-count.tester.js index 9d4f6a965e327..fe94a2fe905f7 100644 --- a/services/gitea/gitea-languages-count.tester.js +++ b/services/gitea/gitea-languages-count.tester.js @@ -3,7 +3,12 @@ import { createServiceTester } from '../tester.js' export const t = await createServiceTester() -t.create('language count (empty repo)') +t.create('language count').get('/gitea/tea.json').expectBadge({ + label: 'languages', + message: Joi.number().integer().positive(), +}) + +t.create('language count (empty repo) (self-managed)') .get( '/CanisHelix/shields-badge-test-empty.json?gitea_url=https://codeberg.org', ) @@ -12,14 +17,14 @@ t.create('language count (empty repo)') message: '0', }) -t.create('language count') +t.create('language count (self-managed)') .get('/CanisHelix/shields-badge-test.json?gitea_url=https://codeberg.org') .expectBadge({ label: 'languages', message: Joi.number().integer().positive(), }) -t.create('language count (user or repo not found)') +t.create('language count (user or repo not found) (self-managed)') .get('/CanisHelix/does-not-exist.json?gitea_url=https://codeberg.org') .expectBadge({ label: 'languages', diff --git a/services/gitea/gitea-release.service.js b/services/gitea/gitea-release.service.js index 2188f0e135fcf..8a6b2817ec8c4 100644 --- a/services/gitea/gitea-release.service.js +++ b/services/gitea/gitea-release.service.js @@ -2,7 +2,7 @@ import Joi from 'joi' import { optionalUrl } from '../validators.js' import { latest, renderVersionBadge } from '../version.js' import { NotFound, pathParam, queryParam } from '../index.js' -import { documentation, httpErrorsFor } from './gitea-helper.js' +import { description, httpErrorsFor } from './gitea-helper.js' import GiteaBase from './gitea-base.js' const schema = Joi.array().items( @@ -18,7 +18,7 @@ const displayNameEnum = ['tag', 'release'] const dateOrderByEnum = ['created_at', 'published_at'] const queryParamSchema = Joi.object({ - gitea_url: optionalUrl.required(), + gitea_url: optionalUrl, include_prereleases: Joi.equal(''), sort: Joi.string() .valid(...sortEnum) @@ -44,20 +44,19 @@ export default class GiteaRelease extends GiteaBase { '/gitea/v/release/{user}/{repo}': { get: { summary: 'Gitea Release', - description: documentation, + description, parameters: [ pathParam({ name: 'user', - example: 'forgejo', + example: 'gitea', }), pathParam({ name: 'repo', - example: 'forgejo', + example: 'tea', }), queryParam({ name: 'gitea_url', - example: 'https://codeberg.org', - required: true, + example: 'https://gitea.com', }), queryParam({ name: 'include_prereleases', @@ -87,7 +86,7 @@ export default class GiteaRelease extends GiteaBase { static defaultBadgeData = { label: 'release' } async fetch({ user, repo, baseUrl }) { - // https://try.gitea.io/api/swagger#/repository/repoGetRelease + // https://gitea.com/api/swagger#/repository/repoGetRelease return super.fetch({ schema, url: `${baseUrl}/api/v1/repos/${user}/${repo}/releases`, @@ -122,7 +121,7 @@ export default class GiteaRelease extends GiteaBase { async handle( { user, repo }, { - gitea_url: baseUrl, + gitea_url: baseUrl = 'https://gitea.com', include_prereleases: pre, sort, display_name: displayName, diff --git a/services/gitea/gitea-release.tester.js b/services/gitea/gitea-release.tester.js index 1f6894e6215cf..9c7602997e8ce 100644 --- a/services/gitea/gitea-release.tester.js +++ b/services/gitea/gitea-release.tester.js @@ -1,39 +1,48 @@ +import Joi from 'joi' import { createServiceTester } from '../tester.js' export const t = await createServiceTester() t.create('Release (latest by date)') + .get('/gitea/tea.json') + .expectBadge({ + label: 'release', + message: Joi.string(), + color: Joi.any().valid(...['orange', 'blue']), + }) + +t.create('Release (latest by date) (self-managed)') .get('/CanisHelix/shields-badge-test.json?gitea_url=https://codeberg.org') .expectBadge({ label: 'release', message: 'v3.0.0', color: 'blue' }) -t.create('Release (latest by date, order by created_at)') +t.create('Release (latest by date, order by created_at) (self-managed)') .get( '/CanisHelix/shields-badge-test.json?gitea_url=https://codeberg.org&date_order_by=created_at', ) .expectBadge({ label: 'release', message: 'v3.0.0', color: 'blue' }) -t.create('Release (latest by date, order by published_at)') +t.create('Release (latest by date, order by published_at) (self-managed)') .get( '/CanisHelix/shields-badge-test.json?gitea_url=https://codeberg.org&date_order_by=published_at', ) .expectBadge({ label: 'release', message: 'v3.0.0', color: 'blue' }) -t.create('Release (latest by semver)') +t.create('Release (latest by semver) (self-managed)') .get( '/CanisHelix/shields-badge-test.json?gitea_url=https://codeberg.org&sort=semver', ) .expectBadge({ label: 'release', message: 'v4.0.0', color: 'blue' }) -t.create('Release (latest by semver pre-release)') +t.create('Release (latest by semver pre-release) (self-managed)') .get( '/CanisHelix/shields-badge-test.json?gitea_url=https://codeberg.org&sort=semver&include_prereleases', ) .expectBadge({ label: 'release', message: 'v5.0.0-rc1', color: 'orange' }) -t.create('Release (project not found)') +t.create('Release (project not found) (self-managed)') .get('/CanisHelix/does-not-exist.json?gitea_url=https://codeberg.org') .expectBadge({ label: 'release', message: 'user or repo not found' }) -t.create('Release (no tags)') +t.create('Release (no tags) (self-managed)') .get( '/CanisHelix/shields-badge-test-empty.json?gitea_url=https://codeberg.org', )