Skip to content

Commit

Permalink
Custom domains for [JitPack] artifacts (#8333)
Browse files Browse the repository at this point in the history
* Custom domains for JitPack artifacts

* FIx jitpack-version test

* style: missing comma

* fix: name for both jitpack-version redirectors

* chore: comment explaining endpoint change

* use more conventional names for redirectors

Co-authored-by: chris48s <[email protected]>
  • Loading branch information
DadiBit and chris48s authored Aug 22, 2022
1 parent 104aa30 commit 9daae0c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 17 deletions.
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({
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')
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',
}

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' })

0 comments on commit 9daae0c

Please sign in to comment.