diff --git a/ci-services/teamcity.js b/ci-services/teamcity.js new file mode 100644 index 00000000..bdff1dd4 --- /dev/null +++ b/ci-services/teamcity.js @@ -0,0 +1,35 @@ +const gitHelpers = require('../lib/git-helpers') + +const env = process.env + +/** + * In order for this to work with Team City, the build configuration needs to set + * the following environment variables: + * + * - VCS_ROOT_URL from the vcsroot..url parameter + * - VCS_ROOT_BRANCH from the teamcity.build.branch parameter + */ + +/** + * Is the current branch a pull request + */ +function isPullRequest () { + return /.+\/merge|head/.test(env.VCS_ROOT_BRANCH) +} + +/** + * Should the lockfile be uploaded + */ +function shouldUpload () { + const re = /^(chore|fix)\(package\): update lockfile|([^ ]+ to version).*$/mi + const lastCommitMessage = gitHelpers.getLastCommitMessage() + return re.test(lastCommitMessage) +} + +module.exports = { + repoSlug: gitHelpers.getRepoSlug(env.VCS_ROOT_URL), + branchName: env.VCS_ROOT_BRANCH, + firstPush: shouldUpload(), + correctBuild: !isPullRequest(), + uploadBuild: shouldUpload() +} diff --git a/ci-services/tests.js b/ci-services/tests.js index 561ea8a0..da3add0f 100644 --- a/ci-services/tests.js +++ b/ci-services/tests.js @@ -10,5 +10,6 @@ module.exports = { wercker: () => env.WERCKER === 'true', codeship: () => env.CI_NAME === 'codeship', bitrise: () => env.CI === 'true' && env.BITRISE_BUILD_NUMBER !== undefined, - semaphoreci: () => env.SEMAPHORE === 'true' + semaphoreci: () => env.SEMAPHORE === 'true', + teamcity: () => env.TEAMCITY_VERSION !== undefined } diff --git a/lib/git-helpers.js b/lib/git-helpers.js index 49636219..0b49c2d2 100644 --- a/lib/git-helpers.js +++ b/lib/git-helpers.js @@ -14,6 +14,9 @@ module.exports = { ).toString() ) }, + getLastCommitMessage: function getLastCommitMessage () { + return exec('git log --format=%B -1').toString() + }, getRepoSlug: function getRepoSlug (githubUrl) { var ghRegex = /\S+[:|/](\w+(?:[-]\w+)*)\/(\w+(?:[-]\w+)*)/g var parsed = ghRegex.exec(githubUrl)