Add [galaxytoolshed] Version (#8249)
* feat(services): galaxytoolshed, add version and update base schema * fix(services): galaxytoolshed, update schema * fix(services): galaxytoolshed, preview updated * fix(services): galaxytoolshed, enable openApi for version * fix(services): galaxytoolshed, version labels
This commit is contained in:
107
services/galaxytoolshed/galaxytoolshed-version.service.js
Normal file
107
services/galaxytoolshed/galaxytoolshed-version.service.js
Normal file
@@ -0,0 +1,107 @@
|
||||
import { NotFound, pathParams } from '../index.js'
|
||||
import { renderVersionBadge } from '../version.js'
|
||||
import GalaxyToolshedService from './galaxytoolshed-base.js'
|
||||
|
||||
export class GalaxyToolshedVersion extends GalaxyToolshedService {
|
||||
static category = 'version'
|
||||
static route = {
|
||||
base: 'galaxytoolshed/v',
|
||||
pattern: ':repository/:owner/:tool?/:requirement?',
|
||||
}
|
||||
|
||||
static openApi = {
|
||||
'/galaxytoolshed/v/{repository}/{owner}': {
|
||||
get: {
|
||||
summary: 'Galaxy Toolshed - Repository Version',
|
||||
parameters: pathParams(
|
||||
{
|
||||
name: 'repository',
|
||||
example: 'sra_tools',
|
||||
},
|
||||
{
|
||||
name: 'owner',
|
||||
example: 'iuc',
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
'/galaxytoolshed/v/{repository}/{owner}/{tool}': {
|
||||
get: {
|
||||
summary: 'Galaxy Toolshed - Tool Version',
|
||||
parameters: pathParams(
|
||||
{
|
||||
name: 'repository',
|
||||
example: 'sra_tools',
|
||||
},
|
||||
{
|
||||
name: 'owner',
|
||||
example: 'iuc',
|
||||
},
|
||||
{
|
||||
name: 'tool',
|
||||
example: 'fastq_dump',
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
'/galaxytoolshed/v/{repository}/{owner}/{tool}/{requirement}': {
|
||||
get: {
|
||||
summary: 'Galaxy Toolshed - Tool Requirement Version',
|
||||
parameters: pathParams(
|
||||
{
|
||||
name: 'repository',
|
||||
example: 'sra_tools',
|
||||
},
|
||||
{
|
||||
name: 'owner',
|
||||
example: 'iuc',
|
||||
},
|
||||
{
|
||||
name: 'tool',
|
||||
example: 'fastq_dump',
|
||||
},
|
||||
{
|
||||
name: 'requirement',
|
||||
example: 'perl',
|
||||
},
|
||||
),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
static transform({ response, tool, requirement }) {
|
||||
if (tool !== undefined) {
|
||||
const dataTool = response[1].valid_tools.find(x => x.id === tool)
|
||||
if (dataTool === undefined) {
|
||||
throw new NotFound({ prettyMessage: 'tool not found' })
|
||||
}
|
||||
// Requirement version
|
||||
if (requirement !== undefined) {
|
||||
const dataRequirement = dataTool.requirements.find(
|
||||
x => x.name === requirement,
|
||||
)
|
||||
if (dataRequirement === undefined) {
|
||||
throw new NotFound({ prettyMessage: 'requirement not found' })
|
||||
}
|
||||
return dataRequirement.version
|
||||
}
|
||||
// Tool version
|
||||
return dataTool.version
|
||||
}
|
||||
// Repository version
|
||||
return response[1].changeset_revision
|
||||
}
|
||||
|
||||
async handle({ repository, owner, tool, requirement }) {
|
||||
const response = await this.fetchLastOrderedInstallableRevisionsSchema({
|
||||
repository,
|
||||
owner,
|
||||
})
|
||||
const version = this.constructor.transform({
|
||||
response,
|
||||
tool,
|
||||
requirement,
|
||||
})
|
||||
return renderVersionBadge({ version })
|
||||
}
|
||||
}
|
||||
51
services/galaxytoolshed/galaxytoolshed-version.tester.js
Normal file
51
services/galaxytoolshed/galaxytoolshed-version.tester.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import { withRegex, isVPlusTripleDottedVersion } from '../test-validators.js'
|
||||
import { createServiceTester } from '../tester.js'
|
||||
|
||||
export const t = await createServiceTester()
|
||||
|
||||
t.create('version - repository')
|
||||
.get('/sra_tools/iuc.json')
|
||||
.expectBadge({
|
||||
label: 'galaxytoolshed',
|
||||
message: withRegex(/^([\w\d]+)$/),
|
||||
})
|
||||
t.create('version - tool').get('/sra_tools/iuc/fastq_dump.json').expectBadge({
|
||||
label: 'galaxytoolshed',
|
||||
message: isVPlusTripleDottedVersion,
|
||||
})
|
||||
t.create('version - requirement')
|
||||
.get('/sra_tools/iuc/fastq_dump/perl.json')
|
||||
.expectBadge({
|
||||
label: 'galaxytoolshed',
|
||||
message: isVPlusTripleDottedVersion,
|
||||
})
|
||||
|
||||
// Not found
|
||||
t.create('version - changesetRevision not found')
|
||||
.get('/bioqc/badilla.json')
|
||||
.expectBadge({
|
||||
label: 'galaxytoolshed',
|
||||
message: 'changesetRevision not found',
|
||||
})
|
||||
t.create('version - repository not found')
|
||||
.get('/sra_too/iuc.json')
|
||||
.expectBadge({
|
||||
label: 'galaxytoolshed',
|
||||
message: 'not found',
|
||||
})
|
||||
t.create('version - owner not found').get('/sra_tool/iu.json').expectBadge({
|
||||
label: 'galaxytoolshed',
|
||||
message: 'not found',
|
||||
})
|
||||
t.create('version - tool not found')
|
||||
.get('/sra_tools/iuc/fastq_dum.json')
|
||||
.expectBadge({
|
||||
label: 'galaxytoolshed',
|
||||
message: 'tool not found',
|
||||
})
|
||||
t.create('version - requirement not found')
|
||||
.get('/sra_tools/iuc/fastq_dump/per.json')
|
||||
.expectBadge({
|
||||
label: 'galaxytoolshed',
|
||||
message: 'requirement not found',
|
||||
})
|
||||
Reference in New Issue
Block a user