This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move [Jenkins] job url to query parameter (badges#4390)
- Loading branch information
Showing
15 changed files
with
317 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,29 @@ | ||
'use strict' | ||
|
||
const Joi = require('@hapi/joi') | ||
const { optionalUrl } = require('../validators') | ||
|
||
const queryParamSchema = Joi.object({ | ||
disableStrictSSL: Joi.equal(''), | ||
jobUrl: optionalUrl, | ||
}).required() | ||
|
||
const buildUrl = ({ | ||
protocol, | ||
host, | ||
job, | ||
lastCompletedBuild = true, | ||
plugin, | ||
}) => { | ||
const buildRedirectUrl = ({ protocol, host, job }) => { | ||
const jobPrefix = job.indexOf('/') > -1 ? '' : 'job/' | ||
return `${protocol}://${host}/${jobPrefix}${job}/${ | ||
lastCompletedBuild ? 'lastCompletedBuild/' : '' | ||
}${plugin ? `${plugin}/` : ''}api/json` | ||
return `${protocol}://${host}/${jobPrefix}${job}` | ||
} | ||
|
||
const buildUrl = ({ jobUrl, lastCompletedBuild = true, plugin }) => { | ||
const lastCompletedBuildElement = lastCompletedBuild | ||
? 'lastCompletedBuild/' | ||
: '' | ||
const pluginElement = plugin ? `${plugin}/` : '' | ||
return `${jobUrl}/${lastCompletedBuildElement}${pluginElement}api/json` | ||
} | ||
|
||
module.exports = { | ||
queryParamSchema, | ||
buildTreeParamQueryString: tree => ({ tree }), | ||
buildUrl, | ||
buildRedirectUrl, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
'use strict' | ||
const { expect } = require('chai') | ||
const { buildRedirectUrl, buildUrl } = require('./jenkins-common') | ||
|
||
describe('jenkins-common', function() { | ||
describe('buildUrl', function() { | ||
it('returns the json api url', function() { | ||
const actualResult = buildUrl({ | ||
jobUrl: 'https://ci.eclipse.org/jgit/job/jgit', | ||
}) | ||
|
||
expect(actualResult).to.equal( | ||
'https://ci.eclipse.org/jgit/job/jgit/lastCompletedBuild/api/json' | ||
) | ||
}) | ||
|
||
it('returns the json api url including a plugin name', function() { | ||
const actualResult = buildUrl({ | ||
jobUrl: 'https://ci.eclipse.org/jgit/job/jgit', | ||
plugin: 'cobertura', | ||
}) | ||
|
||
expect(actualResult).to.equal( | ||
'https://ci.eclipse.org/jgit/job/jgit/lastCompletedBuild/cobertura/api/json' | ||
) | ||
}) | ||
|
||
it('returns the json api url without the lastCompletedBuild element', function() { | ||
const actualResult = buildUrl({ | ||
jobUrl: 'https://ci.eclipse.org/jgit/job/jgit', | ||
lastCompletedBuild: false, | ||
}) | ||
|
||
expect(actualResult).to.equal( | ||
'https://ci.eclipse.org/jgit/job/jgit/api/json' | ||
) | ||
}) | ||
}) | ||
|
||
describe('buildRedirectUrl', function() { | ||
it('returns the job url', function() { | ||
const actualResult = buildRedirectUrl({ | ||
protocol: 'https', | ||
host: 'jenkins.sqlalchemy.org', | ||
job: 'job/alembic_coverage', | ||
}) | ||
|
||
expect(actualResult).to.equal( | ||
'https://jenkins.sqlalchemy.org/job/alembic_coverage' | ||
) | ||
}) | ||
|
||
it('returns the job url and adds missing /job prefixes', function() { | ||
const actualResult = buildRedirectUrl({ | ||
protocol: 'https', | ||
host: 'jenkins.sqlalchemy.org', | ||
job: 'alembic_coverage', | ||
}) | ||
|
||
expect(actualResult).to.equal( | ||
'https://jenkins.sqlalchemy.org/job/alembic_coverage' | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,35 @@ | ||
'use strict' | ||
|
||
const { buildRedirectUrl } = require('./jenkins-common') | ||
const { redirector } = require('..') | ||
|
||
module.exports = redirector({ | ||
const commonProps = { | ||
category: 'coverage', | ||
route: { | ||
base: 'jenkins', | ||
pattern: ':coverageFormat(j|c)/:protocol(http|https)/:host/:job+', | ||
}, | ||
transformPath: ({ coverageFormat, protocol, host, job }) => | ||
`/jenkins/coverage/${ | ||
coverageFormat === 'j' ? 'jacoco' : 'cobertura' | ||
}/${protocol}/${host}/${job}`, | ||
dateAdded: new Date('2019-04-20'), | ||
}) | ||
transformQueryParams: ({ protocol, host, job }) => ({ | ||
jobUrl: buildRedirectUrl({ protocol, host, job }), | ||
}), | ||
} | ||
|
||
module.exports = [ | ||
redirector({ | ||
route: { | ||
base: 'jenkins', | ||
pattern: ':coverageFormat(j|c)/:protocol(http|https)/:host/:job+', | ||
}, | ||
transformPath: ({ coverageFormat }) => | ||
`/jenkins/coverage/${coverageFormat === 'j' ? 'jacoco' : 'cobertura'}`, | ||
dateAdded: new Date('2019-04-20'), | ||
...commonProps, | ||
}), | ||
redirector({ | ||
route: { | ||
base: 'jenkins/coverage', | ||
pattern: | ||
':coverageFormat(jacoco|cobertura|api)/:protocol(http|https)/:host/:job+', | ||
}, | ||
transformPath: ({ coverageFormat }) => | ||
`/jenkins/coverage/${coverageFormat}`, | ||
dateAdded: new Date('2019-11-29'), | ||
...commonProps, | ||
}), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.