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

Deprecate [JenkinsPluginInstalls] per version #10747

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 1 addition & 4 deletions services/downloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import { metric } from './text-formatters.js'
* value instead of the color being based on the count of downloads
* @param {string} [attrs.messageSuffixOverride] If provided then the badge message will
* will have this value added to the download count, separated with a space
* @param {string} [attrs.versionedLabelPrefix] If provided then the badge label will use
* this value as the prefix for versioned badges, e.g. `[email protected]`. Defaults to 'downloads'
* @returns {object} Badge
*/
function renderDownloadsBadge({
Expand All @@ -33,7 +31,6 @@ function renderDownloadsBadge({
labelOverride,
colorOverride,
messageSuffixOverride,
versionedLabelPrefix = 'downloads',
}) {
let messageSuffix = ''
if (messageSuffixOverride) {
Expand All @@ -46,7 +43,7 @@ function renderDownloadsBadge({
if (labelOverride) {
label = labelOverride
} else if (version) {
label = `${versionedLabelPrefix}@${version}`
label = `downloads@${version}`
}

return {
Expand Down
9 changes: 0 additions & 9 deletions services/downloads.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ describe('downloads', function () {
color,
message,
})
given({
downloads,
versionedLabelPrefix: 'installs',
version: 'v1.0.0',
}).expect({
label: '[email protected]',
color,
message,
})
given({
downloads,
messageSuffixOverride: '[foo.tar.gz]',
Expand Down
66 changes: 17 additions & 49 deletions services/jenkins/jenkins-plugin-installs.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Joi from 'joi'
import { renderDownloadsBadge } from '../downloads.js'
import { nonNegativeInteger } from '../validators.js'
import { BaseJsonService, NotFound, pathParams } from '../index.js'
import { BaseJsonService, pathParams } from '../index.js'

const schemaInstallations = Joi.object()
.keys({
Expand All @@ -12,15 +12,6 @@ const schemaInstallations = Joi.object()
})
.required()

const schemaInstallationsPerVersion = Joi.object()
.keys({
installationsPerVersion: Joi.object()
.required()
.pattern(Joi.string(), nonNegativeInteger)
.min(1),
})
.required()

export default class JenkinsPluginInstalls extends BaseJsonService {
static category = 'downloads'

Expand All @@ -39,61 +30,38 @@ export default class JenkinsPluginInstalls extends BaseJsonService {
}),
},
},
'/jenkins/plugin/i/{plugin}/{version}': {
get: {
summary: 'Jenkins Plugin installs (version)',
parameters: pathParams(
{
name: 'plugin',
example: 'view-job-filters',
},
{
name: 'version',
example: '1.26',
},
),
},
},
}

static defaultBadgeData = { label: 'installs' }

static render({ installs: downloads, version }) {
return renderDownloadsBadge({
downloads,
versionedLabelPrefix: 'installs',
version,
})
static render({ installs: downloads }) {
return renderDownloadsBadge({ downloads })
}

async fetch({ plugin, version }) {
async fetch({ plugin }) {
return this._requestJson({
url: `https://stats.jenkins.io/plugin-installation-trend/${plugin}.stats.json`,
schema: version ? schemaInstallationsPerVersion : schemaInstallations,
schema: schemaInstallations,
httpErrors: {
404: 'plugin not found',
},
})
}

static transform({ json, version }) {
if (!version) {
const latestDate = Object.keys(json.installations).sort().slice(-1)[0]
return { installs: json.installations[latestDate] }
}

const installs = json.installationsPerVersion[version]
if (!installs) {
throw new NotFound({
prettyMessage: 'version not found',
})
}
return { installs }
static transform({ json }) {
const latestDate = Object.keys(json.installations).sort().slice(-1)[0]
return { installs: json.installations[latestDate] }
}

async handle({ plugin, version }) {
const json = await this.fetch({ plugin, version })
const { installs } = this.constructor.transform({ json, version })
return this.constructor.render({ installs, version })
if (version) {
return {
message: 'no longer available per version',
color: 'lightgrey',
}
}
const json = await this.fetch({ plugin })
const { installs } = this.constructor.transform({ json })
return this.constructor.render({ installs })
}
}
22 changes: 4 additions & 18 deletions services/jenkins/jenkins-plugin-installs.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,10 @@ t.create('total installs | not found')

// version installs

t.create('version installs | valid: numeric version')
t.create('version installs | no longer available')
.get('/view-job-filters/1.26.json')
.expectBadge({
label: '[email protected]',
message: isMetric,
label: 'installs',
message: 'no longer available per version',
color: 'lightgrey',
})

t.create('version installs | valid: alphanumeric version')
.get('/build-failure-analyzer/1.17.2-DRE3.21.json')
.expectBadge({
label: '[email protected]',
message: isMetric,
})

t.create('version installs | not found: non-existent plugin')
.get('/not-a-plugin/1.26.json')
.expectBadge({ label: 'installs', message: 'plugin not found' })

t.create('version installs | not found: non-existent version')
.get('/view-job-filters/1.1-NOT-FOUND.json')
.expectBadge({ label: 'installs', message: 'version not found' })
Loading