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] Get releases using semver (similar logic to tags) #3144

Closed
wants to merge 1 commit into from
Closed
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
41 changes: 25 additions & 16 deletions services/github/github-release.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

const Joi = require('joi')
const { addv } = require('../text-formatters')
const { latest: latestVersion } = require('../version')
const { version: versionColor } = require('../color-formatters')
const { GithubAuthService } = require('./github-auth-service')
const { errorMessagesFor, documentation } = require('./github-helpers')

Expand All @@ -21,7 +23,7 @@ module.exports = class GithubRelease extends GithubAuthService {
static get route() {
return {
base: 'github',
pattern: ':which(release|release-pre)/:user/:repo',
pattern: ':which(release|release-pre|release-latest)/:user/:repo',
}
}

Expand All @@ -34,27 +36,29 @@ module.exports = class GithubRelease extends GithubAuthService {
user: 'qubyte',
repo: 'rubidium',
},
staticPreview: this.render({ version: '2.0.2', isPrerelease: false }),
staticPreview: this.render('2.0.2'),
documentation,
},
]
}

async fetch({ user, repo, includePre }) {
async fetch({ user, repo, which }) {
const commonAttrs = {
errorMessages: errorMessagesFor('no releases or repo not found'),
}
if (includePre) {
const [releaseInfo] = await this._requestJson({
schema: releaseInfoArraySchema,
url: `/repos/${user}/${repo}/releases`,
...commonAttrs,
})
if (which.endsWith('latest')) {
const releaseInfo = [
await this._requestJson({
schema: releaseInfoSchema,
url: `/repos/${user}/${repo}/releases/latest`,
...commonAttrs,
}),
]
return releaseInfo
} else {
const releaseInfo = await this._requestJson({
schema: releaseInfoSchema,
url: `/repos/${user}/${repo}/releases/latest`,
schema: releaseInfoArraySchema,
url: `/repos/${user}/${repo}/releases`,
...commonAttrs,
})
return releaseInfo
Expand All @@ -68,19 +72,24 @@ module.exports = class GithubRelease extends GithubAuthService {
}
}

static render({ version, isPrerelease }) {
static render(version) {
return {
message: addv(version),
color: isPrerelease ? 'orange' : 'blue',
color: versionColor(version),
}
}

async handle({ which, user, repo }) {
const { tag_name: version, prerelease: isPrerelease } = await this.fetch({
const releaseInfo = await this.fetch({
user,
repo,
includePre: which === 'release-pre',
which,
})
return this.constructor.render({ version, isPrerelease })

const versions = releaseInfo.map(e => e.tag_name)
const version = latestVersion(versions, { pre: which.endsWith('pre') })

console.log('version:', version)
return this.constructor.render(version)
}
}
13 changes: 9 additions & 4 deletions services/github/github-release.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ t.create('Prerelease (repo not found)')
.get('/release-pre/badges/helmets.json')
.expectBadge({ label: 'release', message: 'no releases or repo not found' })

t.create('Latest Release')
.get('/release-latest/photonstorm/phaser.json')
.expectBadge({ label: 'release', message: isVPlusTripleDottedVersion })

t.create('Latest Release (repo not found)')
.get('/release-latest/badges/helmets.json')
.expectBadge({ label: 'release', message: 'no releases or repo not found' })

t.create('No releases')
.get('/release/badges/daily-tests.json')
.expectBadge({
label: 'release',
message: 'no releases or repo not found',
})
.expectBadge({ label: 'release', message: 'no releases or repo not found' })