-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from codecov/azure-provider
feat: Azure, GitLab, Appveyor providers
- Loading branch information
Showing
20 changed files
with
1,116 additions
and
104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
function detect (envs) { | ||
return (envs.CI == 'true' || envs.CI == 'True') && (envs.APPVEYOR == 'true' || envs.APPVEYOR == 'True') | ||
} | ||
|
||
function _getBuild (inputs) { | ||
const { args, envs } = inputs | ||
return args.build || encodeURIComponent(envs.APPVEYOR_JOB_ID) | ||
} | ||
|
||
function _getBuildURL (inputs) { | ||
const { envs } = inputs | ||
if (envs.APPVEYOR_URL && envs.APPVEYOR_REPO_NAME && envs.APPVEYOR_BUILD_ID && envs.APPVEYOR_JOB_ID) { | ||
return encodeURIComponent( | ||
`${envs.APPVEYOR_URL}/project/${envs.APPVEYOR_REPO_NAME}/builds/${envs.APPVEYOR_BUILD_ID}/job/${envs.APPVEYOR_JOB_ID}` | ||
) | ||
} | ||
return '' | ||
} | ||
|
||
function _getBranch (inputs) { | ||
const { args, envs } = inputs | ||
return args.branch || envs.APPVEYOR_REPO_BRANCH || '' | ||
} | ||
|
||
function _getJob (envs) { | ||
if (envs.APPVEYOR_ACCOUNT_NAME && envs.APPVEYOR_PROJECT_SLUG && envs.APPVEYOR_BUILD_VERSION) { | ||
return `${envs.APPVEYOR_ACCOUNT_NAME}%2F${envs.APPVEYOR_PROJECT_SLUG}%2F${envs.APPVEYOR_BUILD_VERSION}` | ||
} | ||
return '' | ||
} | ||
|
||
function _getPR (inputs) { | ||
const { args, envs } = inputs | ||
return args.pr || envs.APPVEYOR_PULL_REQUEST_NUMBER || '' | ||
} | ||
|
||
function _getService () { | ||
return 'appveyor' | ||
} | ||
|
||
function getServiceName () { | ||
return 'Appveyor CI' | ||
} | ||
|
||
function _getSHA (inputs) { | ||
const { args, envs } = inputs | ||
return args.sha || envs.APPVEYOR_REPO_COMMIT || '' | ||
} | ||
|
||
function _getSlug (inputs) { | ||
const { args, envs } = inputs | ||
return args.slug || envs.APPVEYOR_REPO_NAME || '' | ||
} | ||
|
||
function getServiceParams (inputs) { | ||
return { | ||
branch: _getBranch(inputs), | ||
build: _getBuild(inputs), | ||
buildURL: _getBuildURL(inputs), | ||
commit: _getSHA(inputs), | ||
job: _getJob(inputs.envs), | ||
pr: _getPR(inputs), | ||
service: _getService(), | ||
slug: _getSlug(inputs) | ||
} | ||
} | ||
|
||
module.exports = { | ||
detect, | ||
getServiceName, | ||
getServiceParams | ||
} |
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,105 @@ | ||
var childProcess = require('child_process') | ||
var { log } = require('../helpers/logger') | ||
|
||
function detect (envs) { | ||
return !!envs.SYSTEM_TEAMFOUNDATIONSERVERURI | ||
} | ||
|
||
function _getBuild (inputs) { | ||
const { args, envs } = inputs | ||
return args.build || envs.BUILD_BUILDNUMBER || '' | ||
} | ||
|
||
function _getBuildURL (inputs) { | ||
const { args, envs } = inputs | ||
if (envs.SYSTEM_TEAMPROJECT && envs.BUILD_BUILDID) { | ||
return encodeURIComponent(`${envs.SYSTEM_TEAMFOUNDATIONSERVERURI}${envs.SYSTEM_TEAMPROJECT}/_build/results?buildId=${envs.BUILD_BUILDID}`) | ||
} | ||
return '' | ||
} | ||
|
||
function _getBranch (inputs) { | ||
const { args, envs } = inputs | ||
let branch = '' | ||
if (envs.BUILD_SOURCEBRANCH) { | ||
branch = envs.BUILD_SOURCEBRANCH.replace('refs/heads/', '') | ||
} | ||
return args.branch || branch | ||
} | ||
|
||
function _getJob (envs) { | ||
return envs.BUILD_BUILDID || '' | ||
} | ||
|
||
function _getPR (inputs) { | ||
const { args, envs } = inputs | ||
return args.pr || envs.SYSTEM_PULLREQUEST_PULLREQUESTNUMBER || envs.SYSTEM_PULLREQUEST_PULLREQUESTID || '' | ||
} | ||
|
||
function _getService () { | ||
return 'azure_pipelines' | ||
} | ||
|
||
function getServiceName () { | ||
return 'Azure Pipelines' | ||
} | ||
|
||
function _getSHA (inputs) { | ||
const { args, envs } = inputs | ||
let commit = envs.BUILD_SOURCEVERSION | ||
|
||
if (_getPR(inputs)) { | ||
const mergeCommitRegex = /^[a-z0-9]{40} [a-z0-9]{40}$/ | ||
const mergeCommitMessage = childProcess.execSync( | ||
`git show --no-patch --format="%P"` | ||
) | ||
if (mergeCommitRegex.exec(mergeCommitMessage)) { | ||
const mergeCommit = mergeCommitMessage.split(" ")[1] | ||
log(` Fixing merge commit SHA ${commit} -> ${mergeCommit}`) | ||
commit = mergeCommit | ||
} | ||
} | ||
|
||
return args.sha || commit || '' | ||
} | ||
|
||
function _getProject (inputs) { | ||
const { envs } = inputs | ||
return envs.SYSTEM_TEAMPROJECT || '' | ||
} | ||
|
||
function _getServerURI (inputs) { | ||
const { envs } = inputs | ||
return envs.SYSTEM_TEAMFOUNDATIONSERVERURI | ||
} | ||
|
||
function _getSlug (inputs) { | ||
const { args } = inputs | ||
return args.slug || '' | ||
} | ||
/** | ||
* Generates and return the serviceParams object | ||
* | ||
* @param {args: {}, envs: {}} inputs an object of arguments and enviromental variable key/value pairs | ||
* @returns { branch: String, build: String, buildURL: String, commit: String, job: String, pr: String, service: String, slug: String} | ||
*/ | ||
function getServiceParams (inputs) { | ||
return { | ||
branch: _getBranch(inputs), | ||
build: _getBuild(inputs), | ||
buildURL: _getBuildURL(inputs), | ||
commit: _getSHA(inputs), | ||
job: _getJob(inputs.envs), | ||
pr: _getPR(inputs), | ||
project: _getProject(inputs), | ||
server_uri: _getServerURI(inputs), | ||
service: _getService(), | ||
slug: _getSlug(inputs) | ||
} | ||
} | ||
|
||
module.exports = { | ||
detect, | ||
getServiceName, | ||
getServiceParams | ||
} |
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,66 @@ | ||
const { parseSlugFromRemoteAddr } = require('../helpers/git') | ||
|
||
function detect (envs) { | ||
return envs.GITLAB_CI | ||
} | ||
|
||
function _getBuild (inputs) { | ||
const { args, envs } = inputs | ||
return args.build || envs.CI_BUILD_ID || envs.CI_JOB_ID || '' | ||
} | ||
|
||
function _getBuildURL (inputs) { | ||
return '' | ||
} | ||
|
||
function _getBranch (inputs) { | ||
const { args, envs } = inputs | ||
return args.branch || envs.CI_BUILD_REF_NAME || envs.CI_COMMIT_REF_NAME || '' | ||
} | ||
|
||
function _getJob (envs) { | ||
return '' | ||
} | ||
|
||
function _getPR (inputs) { | ||
const { args } = inputs | ||
return args.pr || '' | ||
} | ||
|
||
function _getService () { | ||
return 'gitlab' | ||
} | ||
|
||
function getServiceName () { | ||
return 'GitLab CI' | ||
} | ||
|
||
function _getSHA (inputs) { | ||
const { args, envs } = inputs | ||
return args.sha || envs.CI_BUILD_REF || envs.CI_COMMIT_SHA || '' | ||
} | ||
|
||
function _getSlug (inputs) { | ||
const { args, envs } = inputs | ||
const remoteAddr = envs.CI_BUILD_REPO || envs.CI_REPOSITORY_URL | ||
return args.slug || envs.CI_PROJECT_PATH || parseSlugFromRemoteAddr(remoteAddr) || '' | ||
} | ||
|
||
function getServiceParams (inputs) { | ||
return { | ||
branch: _getBranch(inputs), | ||
build: _getBuild(inputs), | ||
buildURL: _getBuildURL(inputs), | ||
commit: _getSHA(inputs), | ||
job: _getJob(inputs.envs), | ||
pr: _getPR(inputs), | ||
service: _getService(), | ||
slug: _getSlug(inputs) | ||
} | ||
} | ||
|
||
module.exports = { | ||
detect, | ||
getServiceName, | ||
getServiceParams | ||
} |
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,4 +1,5 @@ | ||
const childprocess = require('child_process') | ||
const { parseSlug } = require('../helpers/git') | ||
|
||
function detect (envs) { | ||
return !envs.CI | ||
|
@@ -36,7 +37,8 @@ function _getJob (envs) { | |
|
||
// eslint-disable-next-line no-unused-vars | ||
function _getPR (inputs) { | ||
return '' | ||
const { args } = inputs | ||
return args.pr || '' | ||
} | ||
|
||
// This is the value that gets passed to the Codecov uploader | ||
|
@@ -64,33 +66,14 @@ function _getSHA (inputs) { | |
} | ||
} | ||
|
||
function _parseSlug (slug) { | ||
// origin https://github.com/torvalds/linux.git (fetch) | ||
|
||
// [email protected]: codecov / uploader.git | ||
|
||
if (slug.match('http')) { | ||
// Type is http(s) | ||
const phaseOne = slug.split('//')[1].replace('.git', '') | ||
const phaseTwo = phaseOne.split('/') | ||
const cleanSlug = `${phaseTwo[1]}/${phaseTwo[2]}` | ||
return cleanSlug | ||
} else if (slug.match('@')) { | ||
// Type is git | ||
const cleanSlug = slug.split(':')[1].replace('.git', '') | ||
return cleanSlug | ||
} | ||
throw new Error(`Unable to parse slug URL: ${slug}`) | ||
} | ||
|
||
function _getSlug (inputs) { | ||
const { args } = inputs | ||
try { | ||
const slug = childprocess | ||
.spawnSync('git', ['config', '--get', 'remote.origin.url']) | ||
.stdout.toString() | ||
.trimRight() | ||
return args.slug || _parseSlug(slug) | ||
return args.slug || parseSlug(slug) | ||
} catch (error) { | ||
throw new Error(`There was an error getting the slug from git: ${error}`) | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
var childProcess = require('child_process') | ||
|
||
function parseSlug (slug) { | ||
// origin https://github.com/torvalds/linux.git (fetch) | ||
// [email protected]: codecov / uploader.git | ||
if (typeof slug != 'string') { | ||
return '' | ||
} | ||
|
||
if (slug.match('http')) { | ||
// Type is http(s) | ||
const phaseOne = slug.split('//')[1].replace('.git', '') | ||
const phaseTwo = phaseOne.split('/') | ||
const cleanSlug = `${phaseTwo[1]}/${phaseTwo[2]}` | ||
return cleanSlug | ||
} else if (slug.match('@')) { | ||
// Type is git | ||
const cleanSlug = slug.split(':')[1].replace('.git', '') | ||
return cleanSlug | ||
} | ||
throw new Error(`Unable to parse slug URL: ${slug}`) | ||
} | ||
|
||
function parseSlugFromRemoteAddr (remoteAddr) { | ||
let slug = "" | ||
if (!remoteAddr) { | ||
remoteAddr = childProcess.execSync( | ||
`git config --get remote.origin.url || hg paths default || echo ''` | ||
) | ||
} | ||
if (remoteAddr) { | ||
slug = parseSlug(remoteAddr) | ||
} | ||
if (slug == "/") { | ||
slug = "" | ||
} | ||
return slug | ||
} | ||
|
||
module.exports = { | ||
parseSlug, | ||
parseSlugFromRemoteAddr, | ||
} |
Oops, something went wrong.