Fixed [Jitpack] Badges According to Shields Convention (#3257)

* added fixed jitpack badge

* removing accidental pasted file

* updated transformPath for jitpack-version-redirector service

* refactored jitpack.*.js to jitpack-version.*.js
This commit is contained in:
Eray Erdin
2019-04-02 01:25:39 +03:00
committed by Caleb Cartwright
parent 1421d3a950
commit c7b37a5de8
4 changed files with 45 additions and 10 deletions

View File

@@ -0,0 +1,16 @@
'use strict'
const { redirector } = require('..')
module.exports = [
redirector({
category: 'version',
route: {
base: 'jitpack/v',
pattern: ':groupId/:artifactId',
},
transformPath: ({ groupId, artifactId }) =>
`/jitpack/v/github/${groupId}/${artifactId}`,
dateAdded: new Date('2019-03-31'),
}),
]

View File

@@ -0,0 +1,16 @@
'use strict'
const { ServiceTester } = require('../tester')
const t = (module.exports = new ServiceTester({
id: 'JitpackVersionRedirect',
title: 'JitpackVersionRedirect',
pathPrefix: '/jitpack/v',
}))
t.create('jitpack version redirect')
.get('/jitpack/maven-simple.svg', {
followRedirect: false,
})
.expectStatus(301)
.expectHeader('Location', '/jitpack/v/github/jitpack/maven-simple.svg')

View File

@@ -19,7 +19,7 @@ module.exports = class JitPackVersion extends BaseJsonService {
static get route() {
return {
base: 'jitpack/v',
pattern: ':groupId/:artifactId',
pattern: ':vcs(github|bitbucket|gitlab)/:user/:repo',
}
}
@@ -28,8 +28,9 @@ module.exports = class JitPackVersion extends BaseJsonService {
{
title: 'JitPack',
namedParams: {
groupId: 'jitpack',
artifactId: 'maven-simple',
vcs: 'github',
user: 'jitpack',
repo: 'maven-simple',
},
staticPreview: renderVersionBadge({ version: 'v1.1' }),
keywords: ['java', 'maven'],
@@ -41,16 +42,18 @@ module.exports = class JitPackVersion extends BaseJsonService {
return { label: 'jitpack' }
}
async fetch({ groupId, artifactId }) {
async fetch({ vcs, user, repo }) {
const url = `https://jitpack.io/api/builds/com.${vcs}.${user}/${repo}/latest`
return this._requestJson({
schema,
url: `https://jitpack.io/api/builds/com.github.${groupId}/${artifactId}/latest`,
url,
errorMessages: { 401: 'project not found or private' },
})
}
async handle({ groupId, artifactId }) {
const { version } = await this.fetch({ groupId, artifactId })
async handle({ vcs, user, repo }) {
const { version } = await this.fetch({ vcs, user, repo })
return renderVersionBadge({ version })
}
}

View File

@@ -6,10 +6,10 @@ const t = (module.exports = require('../tester').createServiceTester())
// Github allows versions with chars, etc.
const isAnyV = Joi.string().regex(/^v.+$/)
t.create('version')
.get('/jitpack/maven-simple.json')
t.create('version (groupId)')
.get('/github/erayerdin/kappdirs.json')
.expectBadge({ label: 'jitpack', message: isAnyV })
t.create('unknown package')
.get('/some-bogus-user/project.json')
.get('/github/some-bogus-user/project.json')
.expectBadge({ label: 'jitpack', message: 'project not found or private' })