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

Add [galaxytoolshed] services #8114

Merged
merged 5 commits into from
Jul 2, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions services/galaxytoolshed/galaxytoolshed-base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Joi from 'joi'
import { nonNegativeInteger } from '../validators.js'
import { NotFound, BaseJsonService } from '../index.js'

const orderedInstallableRevisionsSchema = Joi.array()
.items(Joi.string())
.required()

const repositoryRevisionInstallInfoSchema = Joi.array()
.ordered(
Joi.object({
times_downloaded: nonNegativeInteger,
}).required()
)
.items(Joi.any())

export default class BaseGalaxyToolshedService extends BaseJsonService {
static defaultBadgeData = { label: 'galaxytoolshed' }
static baseUrl = 'https://toolshed.g2.bx.psu.edu'

async fetchOrderedInstallableRevisionsSchema({ repository, owner }) {
return this._requestJson({
schema: orderedInstallableRevisionsSchema,
url: `${this.constructor.baseUrl}/api/repositories/get_ordered_installable_revisions?name=${repository}&owner=${owner}`,
})
}

async fetchRepositoryRevisionInstallInfoSchema({
repository,
owner,
changesetRevision,
}) {
return this._requestJson({
schema: repositoryRevisionInstallInfoSchema,
url: `${this.constructor.baseUrl}/api/repositories/get_repository_revision_install_info?name=${repository}&owner=${owner}&changeset_revision=${changesetRevision}`,
})
}

async fetchLastOrderedInstallableRevisionsSchema({ repository, owner }) {
const changesetRevisions =
await this.fetchOrderedInstallableRevisionsSchema({
repository,
owner,
})
if (!Array.isArray(changesetRevisions) || !changesetRevisions.length) {
throw new NotFound({ prettyMessage: 'changesetRevision not found' })
}
return this.fetchRepositoryRevisionInstallInfoSchema({
repository,
owner,
changesetRevision: changesetRevisions[0],
})
}
}
34 changes: 34 additions & 0 deletions services/galaxytoolshed/galaxytoolshed-downloads.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { renderDownloadsBadge } from '../downloads.js'
import BaseGalaxyToolshedService from './galaxytoolshed-base.js'

export default class GalaxyToolshedDownloads extends BaseGalaxyToolshedService {
static category = 'downloads'
static route = {
base: 'galaxytoolshed/downloads',
pattern: ':repository/:owner',
}

static examples = [
{
title: 'Galaxy Toolshed - Downloads',
namedParams: {
repository: 'sra_tools',
owner: 'iuc',
},
staticPreview: renderDownloadsBadge({ downloads: 10000 }),
},
]

static defaultBadgeData = {
label: 'downloads',
}

async handle({ repository, owner }) {
const response = await this.fetchLastOrderedInstallableRevisionsSchema({
repository,
owner,
})
const { times_downloaded: downloads } = response[0]
return renderDownloadsBadge({ downloads })
}
}
28 changes: 28 additions & 0 deletions services/galaxytoolshed/galaxytoolshed-downloads.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { isMetric } from '../test-validators.js'
import { createServiceTester } from '../tester.js'

export const t = await createServiceTester()

t.create('downloads - raw').get('/sra_tools/iuc.json').expectBadge({
label: 'downloads',
message: isMetric,
})

t.create('downloads - repository not found')
.get('/sra_tool/iuc.json')
.expectBadge({
label: 'downloads',
message: 'not found',
})

t.create('downloads - owner not found').get('/sra_tools/iu.json').expectBadge({
label: 'downloads',
message: 'not found',
})

t.create('downloads - changesetRevision not found')
.get('/bioqc/badilla.json')
.expectBadge({
label: 'downloads',
message: 'changesetRevision not found',
})