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

[GithubRelease],[GithubTag] filter by prefix #8205

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
feedback updates
  • Loading branch information
mvndaai committed Aug 4, 2022
commit a66c588b20001bd4e78b1369cd2e110b4cd208c0
12 changes: 5 additions & 7 deletions services/github/github-common-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ async function fetchReleases(serviceInstance, { user, repo }) {

function getLatestRelease({ releases, sort, includePrereleases, prefix }) {
if (prefix) {
const releasesWithPrefix = releases.filter(release =>
release.tag_name.startsWith(prefix)
)
if (releasesWithPrefix.length > 0) {
releases = releasesWithPrefix
releases = releases.filter(r => r.tag_name.startsWith(prefix))
if (releases.length === 0) {
throw new NotFound({ prettyMessage: 'no tags found' })
}
}
if (sort === 'semver') {
Expand All @@ -76,8 +74,8 @@ function getLatestRelease({ releases, sort, includePrereleases, prefix }) {
const queryParamSchema = Joi.object({
include_prereleases: Joi.equal(''),
sort: Joi.string().valid('date', 'semver').default('date'),
prefix: Joi.any(),
subpackage: Joi.any(),
prefix: Joi.alternatives().try(Joi.string(), Joi.number()),
subpackage: Joi.alternatives().try(Joi.string(), Joi.number()),
}).required()

// Fetch the latest release as defined by query params
Expand Down
6 changes: 3 additions & 3 deletions services/github/github-tag.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ class GithubTag extends GithubAuthV4Service {

static getLatestTag({ tags, sort, includePrereleases, prefix }) {
if (prefix) {
const tagsWithPrefix = tags.filter(tag => tag.startsWith(prefix))
if (tagsWithPrefix.length > 0) {
tags = tagsWithPrefix
tags = tags.filter(tag => tag.startsWith(prefix))
if (tags.length === 0) {
throw new NotFound({ prettyMessage: 'no tags found' })
}
}
if (sort === 'semver') {
Expand Down
6 changes: 3 additions & 3 deletions services/github/github-tag.tester.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Joi from 'joi'
import { isSemver, isKebabYearMonthDay } from '../test-validators.js'
import { isSemver } from '../test-validators.js'
import { ServiceTester } from '../tester.js'

export const t = new ServiceTester({
Expand Down Expand Up @@ -28,9 +28,9 @@ t.create('Tag (repo not found)')
.get('/v/tag/badges/helmets.json')
.expectBadge({ label: 'tag', message: 'repo not found' })

t.create('Tag (filter by prefix')
t.create('Tag (filter by subpackage)')
.get('/v/tag/ros/rosdistro.json?subpackage=galactic')
.expectBadge({ label: 'tag', message: isKebabYearMonthDay })
.expectBadge({ label: 'tag', message: Joi.date().required() })

// redirects
t.create('Tag (legacy route: tag)')
Expand Down
3 changes: 0 additions & 3 deletions services/test-validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ const isCustomCompactTestTotals = makeCompactTestTotalsValidator({
skipped: '🤷',
})

const isKebabYearMonthDay = Joi.string().regex(/^\d{4}-\d{2}-\d{2}$/)

export {
isSemver,
isVPlusTripleDottedVersion,
Expand Down Expand Up @@ -189,5 +187,4 @@ export {
isCustomCompactTestTotals,
makeTestTotalsValidator,
makeCompactTestTotalsValidator,
isKebabYearMonthDay,
}