Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom domains for [JitPack] artifacts #8333

Merged
merged 6 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 16 additions & 4 deletions services/jitpack/jitpack-version-redirector.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@ import { redirector } from '../index.js'
export default [
redirector({
category: 'version',
name: 'JitpackVersionGitHubRedirect',
route: {
base: 'jitpack/v',
pattern: ':groupId/:artifactId',
pattern: ':user/:repo',
},
transformPath: ({ groupId, artifactId }) =>
`/jitpack/v/github/${groupId}/${artifactId}`,
dateAdded: new Date('2019-03-31'),
transformPath: ({ user, repo }) =>
`/jitpack/version/com.github.${user}/${repo}`,
dateAdded: new Date('2022-08-21'),
}),
redirector({
Copy link
Member

@chris48s chris48s Aug 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason the tests are failing is:

Error: Duplicate service names found: {
  "JitpackVRedirect": 2
}

we'll need to manually give each of these redirects a unique name when we declare them as the auto-generated names are clashing.

https://github.com/badges/shields/blob/master/core/base-service/redirector.js#L46-L50

You can run npm test locally to run the core tests and liners

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you; I couldn't get npm install to work... I've fixed it and was finally able to test the code.

category: 'version',
name: 'JitpackVersionVcsRedirect',
route: {
base: 'jitpack/v',
pattern: ':vcs(github|bitbucket|gitlab|gitee)/:user/:repo',
},
transformPath: ({ vcs, user, repo }) =>
`/jitpack/version/com.${vcs}.${user}/${repo}`,
dateAdded: new Date('2022-08-21'),
}),
]
8 changes: 6 additions & 2 deletions services/jitpack/jitpack-version-redirector.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ export const t = new ServiceTester({
pathPrefix: '/jitpack/v',
})

t.create('jitpack version redirect')
t.create('jitpack version redirect (no vcs)')
.get('/jitpack/maven-simple.svg')
.expectRedirect('/jitpack/v/github/jitpack/maven-simple.svg')
.expectRedirect('/jitpack/version/com.github.jitpack/maven-simple.svg')

t.create('jitpack version redirect (github)')
.get('/github/jitpack/maven-simple.svg')
.expectRedirect('/jitpack/version/com.github.jitpack/maven-simple.svg')
Comment on lines +13 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

19 changes: 10 additions & 9 deletions services/jitpack/jitpack-version.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@ const schema = Joi.object({
export default class JitPackVersion extends BaseJsonService {
static category = 'version'

// Changed endpoint to allow any groupId, custom domains included
// See: https://github.com/badges/shields/issues/8312
static route = {
base: 'jitpack/v',
pattern: ':vcs(github|bitbucket|gitlab|gitee)/:user/:repo',
base: 'jitpack/version',
pattern: ':groupId/:artifactId',
Comment on lines 15 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets leave a comment linking to #8312 to explain why we're using /version rather than /v here.

}

static examples = [
{
title: 'JitPack',
namedParams: {
vcs: 'github',
user: 'jitpack',
repo: 'maven-simple',
groupId: 'com.github.jitpack',
artifactId: 'maven-simple',
},
staticPreview: renderVersionBadge({ version: 'v1.1' }),
keywords: ['java', 'maven'],
Expand All @@ -30,8 +31,8 @@ export default class JitPackVersion extends BaseJsonService {

static defaultBadgeData = { label: 'jitpack' }

async fetch({ vcs, user, repo }) {
const url = `https://jitpack.io/api/builds/com.${vcs}.${user}/${repo}/latestOk`
async fetch({ groupId, artifactId }) {
const url = `https://jitpack.io/api/builds/${groupId}/${artifactId}/latestOk`

return this._requestJson({
schema,
Expand All @@ -40,8 +41,8 @@ export default class JitPackVersion extends BaseJsonService {
})
}

async handle({ vcs, user, repo }) {
const { version } = await this.fetch({ vcs, user, repo })
async handle({ groupId, artifactId }) {
const { version } = await this.fetch({ groupId, artifactId })
return renderVersionBadge({ version })
}
}
4 changes: 2 additions & 2 deletions services/jitpack/jitpack-version.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ export const t = await createServiceTester()
const isAnyV = Joi.string().regex(/^v.+$/)

t.create('version (groupId)')
.get('/github/erayerdin/kappdirs.json')
.get('/com.github.erayerdin/kappdirs.json')
.expectBadge({ label: 'jitpack', message: isAnyV })

t.create('unknown package')
.get('/github/some-bogus-user/project.json')
.get('/com.github.some-bogus-user/project.json')
.expectBadge({ label: 'jitpack', message: 'project not found or private' })