Skip to content

Commit

Permalink
Update [Gitea] defaults to gitea.com (#9872)
Browse files Browse the repository at this point in the history
* fix(gitea): set gitea.com as default, update tests and message

* fix(gitea): removed required flag

* test(gitea): migrate tests to try.gitea.io

* fix(test): fix auth test nock

* fix(ci): revert tests to codeberg, update description with better verbiage, rename documenation to description

* doc(api): reference flagship url for swagger information in comments
  • Loading branch information
CanisHelix authored Jan 8, 2024
1 parent 57aaaad commit 79dd749
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 33 deletions.
6 changes: 3 additions & 3 deletions services/gitea/gitea-base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand All @@ -24,7 +24,7 @@ describe('GiteaBase', function () {
public: {
services: {
gitea: {
authorizedOrigins: ['https://codeberg.org'],
authorizedOrigins: ['https://gitea.com'],
},
},
},
Expand All @@ -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' })
Expand Down
7 changes: 4 additions & 3 deletions services/gitea/gitea-helper.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -9,4 +10,4 @@ function httpErrorsFor() {
}
}

export { documentation, httpErrorsFor }
export { description, httpErrorsFor }
17 changes: 8 additions & 9 deletions services/gitea/gitea-languages-count.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/*
Expand All @@ -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 {
Expand All @@ -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',
}),
],
},
Expand All @@ -58,15 +57,15 @@ 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`,
httpErrors: httpErrorsFor('user or repo not found'),
})
}

async handle({ user, repo }, { gitea_url: baseUrl }) {
async handle({ user, repo }, { gitea_url: baseUrl = 'https://gitea.com' }) {
const data = await this.fetch({
user,
repo,
Expand Down
11 changes: 8 additions & 3 deletions services/gitea/gitea-languages-count.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
)
Expand All @@ -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',
Expand Down
17 changes: 8 additions & 9 deletions services/gitea/gitea-release.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand All @@ -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',
Expand Down Expand Up @@ -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`,
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 15 additions & 6 deletions services/gitea/gitea-release.tester.js
Original file line number Diff line number Diff line change
@@ -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',
)
Expand Down

0 comments on commit 79dd749

Please sign in to comment.