From 710c50448f79d7145f524948ddd7a5e9f548fa42 Mon Sep 17 00:00:00 2001 From: Wojtek Siudzinski Date: Wed, 11 Dec 2019 18:44:41 +0100 Subject: Add Codefresh support --- lib/getOptions.js | 10 ++++++++++ test/getOptions.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/lib/getOptions.js b/lib/getOptions.js index 8a0305f..ac12fc6 100644 --- a/lib/getOptions.js +++ b/lib/getOptions.js @@ -131,6 +131,16 @@ const getBaseOptions = cb => { git_branch = process.env.BUILD_SOURCEBRANCHNAME; } + if (process.env.CF_BRANCH) { + options.service_name = 'Codefresh'; + options.service_job_id = process.env.CF_BUILD_ID; + options.service_pull_request = process.env.CF_PULL_REQUEST_ID; + git_commit = process.env.CF_REVISION; + git_branch = process.env.CF_BRANCH; + git_committer_name = process.env.CF_COMMIT_AUTHOR; + git_message = process.env.CF_COMMIT_MESSAGE; + } + options.run_at = process.env.COVERALLS_RUN_AT || JSON.stringify(new Date()).slice(1, -1); if (process.env.COVERALLS_SERVICE_NAME) { options.service_name = process.env.COVERALLS_SERVICE_NAME; diff --git a/test/getOptions.js b/test/getOptions.js index ba6ca7d..becb31f 100644 --- a/test/getOptions.js +++ b/test/getOptions.js @@ -170,6 +170,9 @@ describe('getOptions', () => { it('should set service_name and service_job_id if it\'s running via Azure Pipelines', done => { testAzurePipelines(getOptions, done); }); + it('should set service_name and service_job_id if it\'s running via CodeFresh', done => { + testCodefresh(getOptions, done); + }); it('should override set options with user options', done => { const userOptions = { service_name: 'OVERRIDDEN_SERVICE_NAME' }; process.env.COVERALLS_SERVICE_NAME = 'SERVICE_NAME'; @@ -665,6 +668,37 @@ const testAzurePipelines = (sut, done) => { }); }; +const testCodefresh = (sut, done) => { + process.env.CF_BRANCH = 'hotfix'; + process.env.CF_REVISION = 'e3e3e3e3e3e3e3e3e'; + process.env.CF_BUILD_ID = '1234'; + process.env.CF_COMMIT_AUTHOR = 'john doe'; + process.env.CF_COMMIT_MESSAGE = 'msgmsgmsg'; + process.env.CF_PULL_REQUEST_ID = '3'; + + const git = { + head: { + id: 'e3e3e3e3e3e3e3e3e', + author_name: 'Unknown Author', + author_email: '', + committer_name: 'john doe', + committer_email: '', + message: 'msgmsgmsg' + }, + branch: 'hotfix', + remotes: [] + }; + + sut((err, options) => { + should.not.exist(err); + options.service_name.should.equal('Codefresh'); + options.service_job_id.should.equal('1234'); + options.service_pull_request.should.equal('3'); + options.git.should.eql(git); + done(); + }); +}; + function ensureLocalGitContext(options) { const baseDir = process.cwd(); let dir = baseDir; -- cgit v1.2.3