diff --git a/services/gitlab/gitlab-contributors.service.js b/services/gitlab/gitlab-contributors.service.js index 00ebb6ad9b..5b8bb08dba 100644 --- a/services/gitlab/gitlab-contributors.service.js +++ b/services/gitlab/gitlab-contributors.service.js @@ -1,6 +1,7 @@ import Joi from 'joi' import { optionalUrl, nonNegativeInteger } from '../validators.js' import { renderContributorBadge } from '../contributor-count.js' +import { documentation, errorMessagesFor } from './gitlab-helper.js' import GitLabBase from './gitlab-base.js' const schema = Joi.object({ 'x-total': nonNegativeInteger }).required() @@ -9,19 +10,6 @@ const queryParamSchema = Joi.object({ gitlab_url: optionalUrl, }).required() -const documentation = ` -
- You may use your GitLab Project Id (e.g. 278964) or your Project Path (e.g. gitlab-org/gitlab ) -
-` - -const customDocumentation = ` -- Note that only network-accessible jihulab.com and other self-managed GitLab instances are supported. - You may use your GitLab Project Id (e.g. 13953) or your Project Path (e.g. gitlab-cn/gitlab ) in https://jihulab.com -
-` - export default class GitlabContributors extends GitLabBase { static category = 'activity' static route = { @@ -46,7 +34,7 @@ export default class GitlabContributors extends GitLabBase { project: 'gitlab-cn/gitlab', }, staticPreview: this.render({ contributorCount: 415 }), - documentation: customDocumentation, + documentation, }, ] @@ -64,9 +52,7 @@ export default class GitlabContributors extends GitLabBase { project )}/repository/contributors`, options: { searchParams: { page: '1', per_page: '1' } }, - errorMessages: { - 404: 'project not found', - }, + errorMessages: errorMessagesFor('project not found'), }) ) const data = this.constructor._validate(res.headers, schema) diff --git a/services/gitlab/gitlab-coverage.service.js b/services/gitlab/gitlab-coverage.service.js index adfadc4132..a39354c996 100644 --- a/services/gitlab/gitlab-coverage.service.js +++ b/services/gitlab/gitlab-coverage.service.js @@ -2,6 +2,7 @@ import Joi from 'joi' import { coveragePercentage } from '../color-formatters.js' import { optionalUrl } from '../validators.js' import { BaseSvgScrapingService, NotFound } from '../index.js' +import { documentation, errorMessagesFor } from './gitlab-helper.js' const schema = Joi.object({ message: Joi.string() @@ -14,7 +15,7 @@ const queryParamSchema = Joi.object({ job_name: Joi.string(), }).required() -const documentation = ` +const moreDocs = `
Important: If your project is publicly visible, but the badge is like this:
@@ -54,7 +55,7 @@ export default class GitlabCoverage extends BaseSvgScrapingService {
branch: 'master',
},
staticPreview: this.render({ coverage: 67 }),
- documentation,
+ documentation: documentation + moreDocs,
},
{
title: 'Gitlab code coverage (specific job)',
@@ -65,14 +66,14 @@ export default class GitlabCoverage extends BaseSvgScrapingService {
},
queryParams: { job_name: 'test coverage report' },
staticPreview: this.render({ coverage: 96 }),
- documentation,
+ documentation: documentation + moreDocs,
},
{
title: 'Gitlab code coverage (self-managed)',
namedParams: { user: 'GNOME', repo: 'at-spi2-core', branch: 'master' },
queryParams: { gitlab_url: 'https://gitlab.gnome.org' },
staticPreview: this.render({ coverage: 93 }),
- documentation,
+ documentation: documentation + moreDocs,
},
{
title: 'Gitlab code coverage (self-managed, specific job)',
@@ -82,7 +83,7 @@ export default class GitlabCoverage extends BaseSvgScrapingService {
job_name: 'unit-test',
},
staticPreview: this.render({ coverage: 93 }),
- documentation,
+ documentation: documentation + moreDocs,
},
]
@@ -100,10 +101,7 @@ export default class GitlabCoverage extends BaseSvgScrapingService {
// it is recommended to not use the query param at all if not required
jobName = jobName ? `?job=${jobName}` : ''
const url = `${baseUrl}/${user}/${repo}/badges/${branch}/coverage.svg${jobName}`
- const errorMessages = {
- 401: 'repo not found',
- 404: 'repo not found',
- }
+ const errorMessages = errorMessagesFor('project not found')
return this._requestSvg({
schema,
url,
diff --git a/services/gitlab/gitlab-helper.js b/services/gitlab/gitlab-helper.js
new file mode 100644
index 0000000000..d1f24ebba1
--- /dev/null
+++ b/services/gitlab/gitlab-helper.js
@@ -0,0 +1,19 @@
+const documentation = `
+
+ You may use your GitLab Project Id (e.g. 278964) or your Project Path (e.g. + gitlab-org/gitlab ). + Note that only internet-accessible GitLab instances are supported, for example + https://jihulab.com, + https://gitlab.gnome.org, or + https://gitlab.com. +
+` + +function errorMessagesFor(notFoundMessage = 'project not found') { + return { + 401: notFoundMessage, + 404: notFoundMessage, + } +} + +export { documentation, errorMessagesFor } diff --git a/services/gitlab/gitlab-issues.service.js b/services/gitlab/gitlab-issues.service.js index 2e8b6b3e20..ad86069f95 100644 --- a/services/gitlab/gitlab-issues.service.js +++ b/services/gitlab/gitlab-issues.service.js @@ -1,6 +1,7 @@ import Joi from 'joi' import { optionalUrl, nonNegativeInteger } from '../validators.js' import { metric } from '../text-formatters.js' +import { documentation, errorMessagesFor } from './gitlab-helper.js' import GitLabBase from './gitlab-base.js' const schema = Joi.object({ @@ -18,13 +19,6 @@ const queryParamSchema = Joi.object({ gitlab_url: optionalUrl, }).required() -const documentation = ` -- You may use your GitLab Project Id (e.g. 278964) or your Project Path (e.g. gitlab-org/gitlab ). - Note that only internet-accessible GitLab instances are supported, for example https://jihulab.com, https://gitlab.gnome.org, or https://gitlab.com/. -
-` - const labelDocumentation = `
If you want to use multiple labels then please use commas (,) to separate them, e.g. foo,bar.
@@ -243,9 +237,7 @@ export default class GitlabIssues extends GitLabBase {
project
)}/issues_statistics`,
options: labels ? { searchParams: { labels } } : undefined,
- errorMessages: {
- 404: 'project not found',
- },
+ errorMessages: errorMessagesFor('project not found'),
})
}
diff --git a/services/gitlab/gitlab-license.service.js b/services/gitlab/gitlab-license.service.js
index 776d270017..254696121c 100644
--- a/services/gitlab/gitlab-license.service.js
+++ b/services/gitlab/gitlab-license.service.js
@@ -1,6 +1,7 @@
import Joi from 'joi'
import { optionalUrl } from '../validators.js'
import { renderLicenseBadge } from '../licenses.js'
+import { documentation, errorMessagesFor } from './gitlab-helper.js'
import GitLabBase from './gitlab-base.js'
const schema = Joi.object({
@@ -13,19 +14,6 @@ const queryParamSchema = Joi.object({
gitlab_url: optionalUrl,
}).required()
-const documentation = `
-
- You may use your GitLab Project Id (e.g. 278964) or your Project Path (e.g. gitlab-org/gitlab ) -
-` - -const customDocumentation = ` -- Note that only internet-accessible GitLab instances are supported, for example https://jihulab.com, https://gitlab.gnome.org, or https://gitlab.com/. - You may use your GitLab Project Id (e.g. 13953) or your Project Path (e.g. gitlab-cn/gitlab ) in https://jihulab.com -
-` - export default class GitlabLicense extends GitLabBase { static category = 'license' @@ -59,7 +47,7 @@ export default class GitlabLicense extends GitLabBase { message: 'MIT License', color: 'green', }, - documentation: customDocumentation, + documentation, }, ] @@ -79,9 +67,7 @@ export default class GitlabLicense extends GitLabBase { schema, url: `${baseUrl}/api/v4/projects/${encodeURIComponent(project)}`, options: { searchParams: { license: '1' } }, - errorMessages: { - 404: 'repo not found', - }, + errorMessages: errorMessagesFor('project not found'), }) } diff --git a/services/gitlab/gitlab-license.tester.js b/services/gitlab/gitlab-license.tester.js index 10a4e07898..9769a625f3 100644 --- a/services/gitlab/gitlab-license.tester.js +++ b/services/gitlab/gitlab-license.tester.js @@ -34,7 +34,7 @@ t.create('License for unknown repo') .get('/user1/gitlab-does-not-have-this-repo.json') .expectBadge({ label: 'license', - message: 'repo not found', + message: 'project not found', color: 'red', }) diff --git a/services/gitlab/gitlab-merge-requests.service.js b/services/gitlab/gitlab-merge-requests.service.js index 1cc353a222..bc7f7b88a1 100644 --- a/services/gitlab/gitlab-merge-requests.service.js +++ b/services/gitlab/gitlab-merge-requests.service.js @@ -1,6 +1,7 @@ import Joi from 'joi' import { optionalUrl, nonNegativeInteger } from '../validators.js' import { metric } from '../text-formatters.js' +import { documentation, errorMessagesFor } from './gitlab-helper.js' import GitLabBase from './gitlab-base.js' // The total number of MR is in the `x-total` field in the headers. @@ -15,20 +16,22 @@ const queryParamSchema = Joi.object({ gitlab_url: optionalUrl, }).required() -const documentation = ` +const more = `- You may use your GitLab Project Id (e.g. 278964) or your Project Path (e.g. gitlab-org/gitlab ). - Note that only internet-accessible GitLab instances are supported, for example https://jihulab.com, https://gitlab.gnome.org, or https://gitlab.com/. GitLab's API only reports up to 10k Merge Requests, so badges for projects that have more than 10k will not have an exact count.
` -const labelDocumentation = ` +const labelText = `
If you want to use multiple labels then please use commas (,) to separate them, e.g. foo,bar.
Important: You must use the Project Path, not the Project Id. Additionally, if your project is publicly visible, but the badge is like this:
@@ -51,14 +52,14 @@ class GitlabPipelineStatus extends BaseSvgScrapingService {
namedParams: { project: 'gitlab-org/gitlab' },
queryParams: { branch: 'master' },
staticPreview: this.render({ status: 'passed' }),
- documentation,
+ documentation: documentation + moreDocs,
},
{
title: 'Gitlab pipeline status (self-managed)',
namedParams: { project: 'GNOME/pango' },
queryParams: { gitlab_url: 'https://gitlab.gnome.org', branch: 'master' },
staticPreview: this.render({ status: 'passed' }),
- documentation,
+ documentation: documentation + moreDocs,
},
]
@@ -72,10 +73,7 @@ class GitlabPipelineStatus extends BaseSvgScrapingService {
url: `${baseUrl}/${decodeURIComponent(
project
)}/badges/${branch}/pipeline.svg`,
- errorMessages: {
- 401: 'repo not found',
- 404: 'repo not found',
- },
+ errorMessages: errorMessagesFor('project not found'),
})
}
diff --git a/services/gitlab/gitlab-release.service.js b/services/gitlab/gitlab-release.service.js
index 10f50420a7..51f3c37291 100644
--- a/services/gitlab/gitlab-release.service.js
+++ b/services/gitlab/gitlab-release.service.js
@@ -2,6 +2,7 @@ import Joi from 'joi'
import { optionalUrl } from '../validators.js'
import { latest, renderVersionBadge } from '../version.js'
import { NotFound } from '../index.js'
+import { documentation, errorMessagesFor } from './gitlab-helper.js'
import GitLabBase from './gitlab-base.js'
const schema = Joi.array().items(
@@ -21,11 +22,6 @@ const queryParamSchema = Joi.object({
.default('created_at'),
}).required()
-const documentation = `
-
- You may use your GitLab Project Id (e.g. 25813592) or your Project Path (e.g. megabyte-labs/dockerfile/ci-pipeline/ansible-lint) -
-` const commonProps = { namedParams: { project: 'shields-ops-group/tag-test', @@ -102,9 +98,7 @@ export default class GitLabRelease extends GitLabBase { return this.fetchPaginatedArrayData({ schema, url: `${baseUrl}/api/v4/projects/${encodeURIComponent(project)}/releases`, - errorMessages: { - 404: 'project not found', - }, + errorMessages: errorMessagesFor('project not found'), options: { searchParams: { order_by: orderBy }, }, diff --git a/services/gitlab/gitlab-tag.service.js b/services/gitlab/gitlab-tag.service.js index ce5aa084f7..534d371972 100644 --- a/services/gitlab/gitlab-tag.service.js +++ b/services/gitlab/gitlab-tag.service.js @@ -4,6 +4,7 @@ import { optionalUrl } from '../validators.js' import { latest } from '../version.js' import { addv } from '../text-formatters.js' import { NotFound } from '../index.js' +import { documentation, errorMessagesFor } from './gitlab-helper.js' import GitLabBase from './gitlab-base.js' const schema = Joi.array().items( @@ -18,11 +19,6 @@ const queryParamSchema = Joi.object({ sort: Joi.string().valid('date', 'semver').default('date'), }).required() -const documentation = ` -- You may use your GitLab Project Id (e.g. 25813592) or your Project Path (e.g. megabyte-labs/dockerfile/ci-pipeline/ansible-lint) -
-` const commonProps = { namedParams: { project: 'shields-ops-group/tag-test', @@ -96,9 +92,7 @@ export default class GitlabTag extends GitLabBase { project )}/repository/tags`, options: { searchParams: { order_by: 'updated' } }, - errorMessages: { - 404: 'repo not found', - }, + errorMessages: errorMessagesFor('project not found'), }) } diff --git a/services/gitlab/gitlab-tag.tester.js b/services/gitlab/gitlab-tag.tester.js index 8cd9a008bf..f3d78bf249 100644 --- a/services/gitlab/gitlab-tag.tester.js +++ b/services/gitlab/gitlab-tag.tester.js @@ -28,7 +28,7 @@ t.create('Tag (custom instance)') t.create('Tag (repo not found)') .get('/fdroid/nonexistant.json') - .expectBadge({ label: 'tag', message: 'repo not found' }) + .expectBadge({ label: 'tag', message: 'project not found' }) t.create('Tag (no tags)') .get('/fdroid/fdroiddata.json')