Allow [GitHub] tag badge to sort by date (#2157)

* add test for tag-pre
* support /releases-pre (but also allow /all for BC)
* allow GH tags to be sorted by date instead of semver
* fix license badge
This commit is contained in:
chris48s
2018-10-08 18:29:02 +01:00
committed by GitHub
parent 7ea540d3c6
commit a74db34853
5 changed files with 73 additions and 13 deletions

View File

@@ -13,13 +13,13 @@ const {
module.exports = class GithubRelease extends LegacyService {
static registerLegacyRouteHandler({ camp, cache, githubApiProvider }) {
camp.route(
/^\/github\/release\/([^/]+\/[^/]+)(?:\/(all))?\.(svg|png|gif|jpg|json)$/,
/^\/github\/release(-pre)?\/([^/]+\/[^/]+)(?:\/(all))?\.(svg|png|gif|jpg|json)$/,
cache((data, match, sendBadge, request) => {
const userRepo = match[1] // eg, qubyte/rubidium
const allReleases = match[2]
const format = match[3]
const includePre = Boolean(match[1]) || match[3] === 'all'
const userRepo = match[2] // eg, qubyte/rubidium
const format = match[4]
let apiUrl = `/repos/${userRepo}/releases`
if (allReleases === undefined) {
if (!includePre) {
apiUrl = apiUrl + '/latest'
}
const badgeData = getBadgeData('release', data)
@@ -33,7 +33,7 @@ module.exports = class GithubRelease extends LegacyService {
}
try {
let data = JSON.parse(buffer)
if (allReleases === 'all') {
if (includePre) {
data = data[0]
}
const version = data.tag_name