Skip to content

Commit

Permalink
Merge branch 'master' into jenkins-version
Browse files Browse the repository at this point in the history
  • Loading branch information
PyvesB committed Apr 17, 2019
2 parents 60c7a9e + cffa29d commit 5341eed
Show file tree
Hide file tree
Showing 46 changed files with 2,074 additions and 621 deletions.
1 change: 1 addition & 0 deletions config/custom-environment-variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private:
azure_devops_token: 'AZURE_DEVOPS_TOKEN'
bintray_user: 'BINTRAY_USER'
bintray_apikey: 'BINTRAY_API_KEY'
drone_token: 'DRONE_TOKEN'
gh_client_id: 'GH_CLIENT_ID'
gh_client_secret: 'GH_CLIENT_SECRET'
gh_token: 'GH_TOKEN'
Expand Down
12 changes: 9 additions & 3 deletions core/base-service/redirector.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const { isValidRoute, prepareRoute, namedParamsForMatch } = require('./route')
const trace = require('./trace')

const attrSchema = Joi.object({
name: Joi.string().min(3),
category: isValidCategory,
route: isValidRoute,
transformPath: Joi.func()
Expand All @@ -30,6 +31,7 @@ const attrSchema = Joi.object({

module.exports = function redirector(attrs) {
const {
name,
category,
route,
transformPath,
Expand All @@ -51,9 +53,13 @@ module.exports = function redirector(attrs) {
}

static get name() {
return `${camelcase(route.base.replace(/\//g, '_'), {
pascalCase: true,
})}Redirect`
if (name) {
return name
} else {
return `${camelcase(route.base.replace(/\//g, '_'), {
pascalCase: true,
})}Redirect`
}
}

static register({ camp, requestCounter }) {
Expand Down
9 changes: 9 additions & 0 deletions core/base-service/redirector.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ describe('Redirector', function() {
expect(redirector(attrs).name).to.equal('VeryOldServiceRedirect')
})

it('overrides the name', function() {
expect(
redirector({
...attrs,
name: 'ShinyRedirect',
}).name
).to.equal('ShinyRedirect')
})

it('sets specified route', function() {
expect(redirector(attrs).route).to.deep.equal(route)
})
Expand Down
7 changes: 7 additions & 0 deletions doc/server-secrets.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ An Azure DevOps Token (PAT) is required for accessing [private Azure DevOps proj
The bintray API [requires authentication](https://bintray.com/docs/api/#_authentication)
Create an account and obtain a token from the user profile page.

## Drone

- `DRONE_TOKEN` (yml: `drone_token`)

The self-hosted Drone API [requires authentication](https://0-8-0.docs.drone.io/api-authentication/)
Login to your Drone instance and obtain a token from the user profile page.

## GitHub

- `GH_TOKEN` (yml: `gh_token`)
Expand Down
42 changes: 28 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"chalk": "^2.4.2",
"check-node-version": "^3.1.0",
"chrome-web-store-item-property": "~1.1.2",
"config": "^3.0.1",
"config": "^3.1.0",
"cross-env": "^5.2.0",
"decamelize": "^3.2.0",
"dotenv": "^7.0.0",
Expand Down Expand Up @@ -215,7 +215,7 @@
"sazerac": "^0.4.2",
"sinon": "^7.3.1",
"sinon-chai": "^3.3.0",
"snap-shot-it": "^6.2.10",
"snap-shot-it": "^6.3.3",
"start-server-and-test": "^1.7.12",
"styled-components": "^4.2.0",
"tmp": "0.1.0",
Expand Down
8 changes: 7 additions & 1 deletion services/build-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ const greenStatuses = [

const orangeStatuses = ['partially succeeded', 'unstable', 'timeout']

const redStatuses = ['error', 'failed', 'failing', 'infrastructure_failure']
const redStatuses = [
'error',
'failed',
'failing',
'failure',
'infrastructure_failure',
]

const otherStatuses = [
'building',
Expand Down
1 change: 1 addition & 0 deletions services/build-status.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ test(renderBuildStatusBadge, () => {
given({ status: 'error' }),
given({ status: 'failed' }),
given({ status: 'failing' }),
given({ status: 'failure' }),
given({ status: 'infrastructure_failure' }),
]).assert('should be red', b => expect(b).to.include({ color: 'red' }))
})
Expand Down
48 changes: 48 additions & 0 deletions services/codeclimate/codeclimate-common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
'use strict'

const Joi = require('joi')
const { NotFound } = require('..')

const keywords = ['codeclimate']

const repoSchema = Joi.object({
data: Joi.array()
.max(1)
.items(
Joi.object({
id: Joi.string().required(),
relationships: Joi.object({
latest_default_branch_snapshot: Joi.object({
data: Joi.object({
id: Joi.string().required(),
}).allow(null),
}).required(),
latest_default_branch_test_report: Joi.object({
data: Joi.object({
id: Joi.string().required(),
}).allow(null),
}).required(),
}).required(),
})
)
.required(),
}).required()

async function fetchRepo(serviceInstance, { user, repo }) {
const {
data: [repoInfo],
} = await serviceInstance._requestJson({
schema: repoSchema,
url: 'https://api.codeclimate.com/v1/repos',
options: { qs: { github_slug: `${user}/${repo}` } },
})
if (repoInfo === undefined) {
throw new NotFound({ prettyMessage: 'repo not found' })
}
return repoInfo
}

module.exports = {
keywords,
fetchRepo,
}
39 changes: 39 additions & 0 deletions services/codeclimate/codeclimate-coverage-redirector.service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict'

const { redirector } = require('..')

module.exports = [
// http://github.com/badges/shields/issues/1387
// https://github.com/badges/shields/pull/3320#issuecomment-483795000
redirector({
name: 'CodeclimateCoveragePercentageRedirect',
category: 'coverage',
route: {
base: 'codeclimate',
pattern: ':which(c|coverage-percentage)/:user/:repo',
},
transformPath: ({ user, repo }) => `/codeclimate/coverage/${user}/${repo}`,
dateAdded: new Date('2019-04-15'),
}),
redirector({
name: 'CodeclimateCoverageLetterRedirect',
category: 'coverage',
route: {
base: 'codeclimate/c-letter',
pattern: ':user/:repo',
},
transformPath: ({ user, repo }) =>
`/codeclimate/coverage-letter/${user}/${repo}`,
dateAdded: new Date('2019-04-15'),
}),
redirector({
name: 'CodeclimateTopLevelCoverageRedirect',
category: 'coverage',
route: {
base: 'codeclimate',
pattern: ':user/:repo',
},
transformPath: ({ user, repo }) => `/codeclimate/coverage/${user}/${repo}`,
dateAdded: new Date('2019-04-15'),
}),
]
37 changes: 37 additions & 0 deletions services/codeclimate/codeclimate-coverage-redirector.tester.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict'

const { ServiceTester } = require('../tester')

const t = (module.exports = new ServiceTester({
id: 'CodeclimateCoverageRedirector',
title: 'Code Climate Coverage Redirector',
pathPrefix: '/codeclimate',
}))

t.create('Top-level coverage shortcut')
.get('/jekyll/jekyll.svg', {
followRedirect: false,
})
.expectStatus(301)
.expectHeader('Location', '/codeclimate/coverage/jekyll/jekyll.svg')

t.create('Coverage shortcut')
.get('/c/jekyll/jekyll.svg', {
followRedirect: false,
})
.expectStatus(301)
.expectHeader('Location', '/codeclimate/coverage/jekyll/jekyll.svg')

t.create('Coverage letter shortcut')
.get('/c-letter/jekyll/jekyll.svg', {
followRedirect: false,
})
.expectStatus(301)
.expectHeader('Location', '/codeclimate/coverage-letter/jekyll/jekyll.svg')

t.create('Coverage percentage shortcut')
.get('/coverage-percentage/jekyll/jekyll.svg', {
followRedirect: false,
})
.expectStatus(301)
.expectHeader('Location', '/codeclimate/coverage/jekyll/jekyll.svg')
Loading

0 comments on commit 5341eed

Please sign in to comment.