Skip to content

Commit

Permalink
Merge branch 'master' into jira
Browse files Browse the repository at this point in the history
  • Loading branch information
calebcartwright authored Dec 18, 2018
2 parents 9fb8817 + b0fbe5f commit 070dec5
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 53 deletions.
5 changes: 3 additions & 2 deletions services/azure-devops/azure-devops-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const latestBuildSchema = Joi.object({
.required(),
}).required()

module.exports = class BaseAzureDevOpsService extends BaseJsonService {
module.exports = class AzureDevOpsBase extends BaseJsonService {
async fetch({ url, options, schema, errorMessages }) {
return this._requestJson({
schema,
Expand All @@ -25,7 +25,7 @@ module.exports = class BaseAzureDevOpsService extends BaseJsonService {
})
}

async getLatestBuildId(
async getLatestCompletedBuildId(
organization,
project,
definitionId,
Expand All @@ -39,6 +39,7 @@ module.exports = class BaseAzureDevOpsService extends BaseJsonService {
qs: {
definitions: definitionId,
$top: 1,
statusFilter: 'completed',
'api-version': '5.0-preview.4',
},
headers,
Expand Down
6 changes: 3 additions & 3 deletions services/azure-devops/azure-devops-coverage.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const Joi = require('joi')
const BaseAzureDevOpsService = require('./azure-devops-base')
const AzureDevOpsBase = require('./azure-devops-base')
const { keywords, getHeaders } = require('./azure-devops-helpers')

const documentation = `
Expand Down Expand Up @@ -47,7 +47,7 @@ const buildCodeCoverageSchema = Joi.object({
.required(),
}).required()

module.exports = class AzureDevOpsCoverage extends BaseAzureDevOpsService {
module.exports = class AzureDevOpsCoverage extends AzureDevOpsBase {
static render({ coverage }) {
return {
message: `${coverage.toFixed(0)}%`,
Expand Down Expand Up @@ -106,7 +106,7 @@ module.exports = class AzureDevOpsCoverage extends BaseAzureDevOpsService {
const errorMessages = {
404: 'build pipeline or coverage not found',
}
const buildId = await this.getLatestBuildId(
const buildId = await this.getLatestCompletedBuildId(
organization,
project,
definitionId,
Expand Down
4 changes: 2 additions & 2 deletions services/azure-devops/azure-devops-coverage.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const buildId = 946
const uriPrefix = `/${org}/${project}`
const azureDevOpsApiBaseUri = `https://dev.azure.com/${org}/${project}/_apis`
const mockBadgeUriPath = `${uriPrefix}/${macDefinitionId}.json`
const mockLatestBuildApiUriPath = `/build/builds?definitions=${macDefinitionId}&%24top=1&api-version=5.0-preview.4`
const mockLatestBuildApiUriPath = `/build/builds?definitions=${macDefinitionId}&%24top=1&statusFilter=completed&api-version=5.0-preview.4`
const mockCodeCoverageApiUriPath = `/test/codecoverage?buildId=${buildId}&api-version=5.0-preview.1`
const latestBuildResponse = {
count: 1,
Expand Down Expand Up @@ -94,7 +94,7 @@ t.create('no build response')
.intercept(nock =>
nock(azureDevOpsApiBaseUri)
.get(
`/build/builds?definitions=${nonExistentDefinitionId}&%24top=1&api-version=5.0-preview.4`
`/build/builds?definitions=${nonExistentDefinitionId}&%24top=1&statusFilter=completed&api-version=5.0-preview.4`
)
.reply(200, {
count: 0,
Expand Down
6 changes: 3 additions & 3 deletions services/azure-devops/azure-devops-tests.service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const Joi = require('joi')
const BaseAzureDevOpsService = require('./azure-devops-base')
const AzureDevOpsBase = require('./azure-devops-base')
const { getHeaders } = require('./azure-devops-helpers')
const { renderTestResultBadge } = require('../../lib/text-formatters')

Expand Down Expand Up @@ -56,7 +56,7 @@ const buildTestResultSummarySchema = Joi.object({
}).required(),
}).required()

module.exports = class AzureDevOpsTests extends BaseAzureDevOpsService {
module.exports = class AzureDevOpsTests extends AzureDevOpsBase {
static render({
passed,
failed,
Expand Down Expand Up @@ -200,7 +200,7 @@ module.exports = class AzureDevOpsTests extends BaseAzureDevOpsService {
const errorMessages = {
404: 'build pipeline or test result summary not found',
}
const buildId = await this.getLatestBuildId(
const buildId = await this.getLatestCompletedBuildId(
organization,
project,
definitionId,
Expand Down
6 changes: 3 additions & 3 deletions services/azure-devops/azure-devops-tests.tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ const azureDevOpsApiBaseUri = `https://dev.azure.com/${org}/${project}/_apis`
const mockBadgeUriPath = `${uriPrefix}/${definitionId}`
const mockBadgeUri = `${mockBadgeUriPath}.json`
const mockBranchBadgeUri = `${mockBadgeUriPath}/master.json`
const mockLatestBuildApiUriPath = `/build/builds?definitions=${definitionId}&%24top=1&api-version=5.0-preview.4`
const mockLatestBranchBuildApiUriPath = `/build/builds?definitions=${definitionId}&%24top=1&api-version=5.0-preview.4&branch=master`
const mockNonExistentBuildApiUriPath = `/build/builds?definitions=${nonExistentDefinitionId}&%24top=1&api-version=5.0-preview.4`
const mockLatestBuildApiUriPath = `/build/builds?definitions=${definitionId}&%24top=1&statusFilter=completed&api-version=5.0-preview.4`
const mockLatestBranchBuildApiUriPath = `/build/builds?definitions=${definitionId}&%24top=1&statusFilter=completed&api-version=5.0-preview.4&branch=master`
const mockNonExistentBuildApiUriPath = `/build/builds?definitions=${nonExistentDefinitionId}&%24top=1&statusFilter=completed&api-version=5.0-preview.4`
const mockTestResultSummaryApiUriPath = `/test/ResultSummaryByBuild?buildId=${buildId}`
const latestBuildResponse = {
count: 1,
Expand Down
86 changes: 52 additions & 34 deletions services/codetally/codetally.service.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,75 @@
'use strict'

const LegacyService = require('../legacy-service')
const { makeBadgeData: getBadgeData } = require('../../lib/badge-data')
const Joi = require('joi')
const BaseJsonService = require('../base-json')

const schema = Joi.object({
currency_sign: Joi.string().required(),
amount: Joi.number().required(),
multiplier: Joi.string()
.allow('')
.required(),
currency_abbreviation: Joi.string().required(),
}).required()

module.exports = class Codetally extends BaseJsonService {
static render({ currency, amount, multiplier }) {
return {
message: `${currency}${amount.toFixed(2)} ${multiplier}`,
}
}

module.exports = class Codetally extends LegacyService {
static get category() {
return 'funding'
}

static get defaultBadgeData() {
return {
label: 'codetally',
color: '#2E8B57',
}
}

static get route() {
return {
base: 'codetally',
pattern: ':owner/:repo',
}
}

static get examples() {
return [
{
title: 'Codetally',
previewUrl: 'triggerman722/colorstrap',
pattern: ':owner/:repo',
namedParams: {
owner: 'triggerman722',
repo: 'colorstrap',
},
staticExample: this.render({
currency: '$',
amount: 4.68,
multiplier: 'K',
}),
},
]
}

static registerLegacyRouteHandler({ camp, cache }) {
camp.route(
/^\/codetally\/(.*)\/(.*)\.(svg|png|gif|jpg|json)$/,
cache((data, match, sendBadge, request) => {
const owner = match[1] // eg, triggerman722.
const repo = match[2] // eg, colorstrap
const format = match[3]
const apiUrl = `http://www.codetally.com/formattedshield/${owner}/${repo}`
const badgeData = getBadgeData('codetally', data)
request(apiUrl, (err, res, buffer) => {
if (err != null) {
badgeData.text[1] = 'inaccessible'
sendBadge(format, badgeData)
return
}
try {
const data = JSON.parse(buffer)
badgeData.text[1] = ` ${data.currency_sign}${data.amount} ${
data.multiplier
}`
badgeData.colorscheme = null
badgeData.colorB = '#2E8B57'
sendBadge(format, badgeData)
} catch (e) {
badgeData.text[1] = 'invalid'
sendBadge(format, badgeData)
}
})
})
)
async handle({ owner, repo }) {
const url = `http://www.codetally.com/formattedshield/${owner}/${repo}`
const json = await this._requestJson({
url,
schema,
errorMessages: {
404: 'repo not found',
503: 'repo not found',
},
})

return this.constructor.render({
currency: json.currency_sign,
amount: json.amount,
multiplier: json.multiplier,
})
}
}
12 changes: 6 additions & 6 deletions services/codetally/codetally.tester.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
'use strict'

const Joi = require('joi')
const ServiceTester = require('../service-tester')

const t = (module.exports = new ServiceTester({
id: 'codetally',
title: 'Codetally',
}))
const t = (module.exports = require('../create-service-tester')())

// This test will extract the currency value from the
// string value response from the server.
Expand Down Expand Up @@ -37,3 +32,8 @@ t.create('Empty')
})
)
.expectJSON({ name: 'codetally', value: '$0.00' })

t.create('Non existent')
.get('/not/real.json')
.timeout(10000)
.expectJSON({ name: 'codetally', value: 'repo not found' })

0 comments on commit 070dec5

Please sign in to comment.