aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Petty <[email protected]>2020-03-19 10:06:13 -0700
committerGitHub <[email protected]>2020-03-19 10:06:13 -0700
commit3d83b4f29f2dbf6f4a642ba24976d4ecbd5d56b1 (patch)
tree8f44a790f35e34c1145664001217976bf0e08b3a
parent710c50448f79d7145f524948ddd7a5e9f548fa42 (diff)
downloadnode-coveralls-3d83b4f29f2dbf6f4a642ba24976d4ecbd5d56b1.tar.xz
node-coveralls-3d83b4f29f2dbf6f4a642ba24976d4ecbd5d56b1.zip
Set service_name and/or repo_token from .coveralls.yml regardless of if $COVERALLS_REPO_TOKEN is set (#272)
* using TRAVIS_COMMIT environment variable for git_commit * Setting repo token and service name from .coveralls.yml regardless of if $COVERALLS_REPO_TOKEN * only set options.repo_token from coveralls_yaml_conf if set in .coveralls.yml * Update lib/getOptions.js Co-Authored-By: Derek Herman <[email protected]>
-rw-r--r--lib/getOptions.js46
-rw-r--r--test/getOptions.js23
2 files changed, 53 insertions, 16 deletions
diff --git a/lib/getOptions.js b/lib/getOptions.js
index ac12fc6..c4a3e31 100644
--- a/lib/getOptions.js
+++ b/lib/getOptions.js
@@ -26,7 +26,7 @@ const getBaseOptions = cb => {
options.service_name = 'travis-ci';
options.service_job_id = process.env.TRAVIS_JOB_ID;
options.service_pull_request = process.env.TRAVIS_PULL_REQUEST;
- git_commit = 'HEAD';
+ git_commit = process.env.TRAVIS_COMMIT || 'HEAD';
git_branch = process.env.TRAVIS_BRANCH;
}
@@ -142,9 +142,6 @@ const getBaseOptions = cb => {
}
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;
- }
if (process.env.COVERALLS_SERVICE_JOB_ID) {
options.service_job_id = process.env.COVERALLS_SERVICE_JOB_ID;
@@ -162,24 +159,41 @@ const getBaseOptions = cb => {
options.parallel = true;
}
- // try to get the repo token as an environment variable
- if (process.env.COVERALLS_REPO_TOKEN) {
- options.repo_token = process.env.COVERALLS_REPO_TOKEN;
- } else {
- // try to get the repo token from a .coveralls.yml file
+ // load a .coveralls.yml file
+ const coveralls_yaml_conf = (() => {
const yml = path.join(process.cwd(), '.coveralls.yml');
try {
if (fs.statSync(yml).isFile()) {
- const coveralls_yaml_conf = yaml.safeLoad(fs.readFileSync(yml, 'utf8'));
- options.repo_token = coveralls_yaml_conf.repo_token;
- if (coveralls_yaml_conf.service_name) {
- options.service_name = coveralls_yaml_conf.service_name;
- }
+ return yaml.safeLoad(fs.readFileSync(yml, 'utf8'));
}
} catch (_) {
- logger.warn('Repo token could not be determined. Continuing without it. ' +
- 'This is necessary for private repos only, so may not be an issue at all.');
+ logger.debug('No valid .coveralls.yml file found');
+ }
+ })();
+
+ // try to get repo token and service name from .coveralls.yml file
+ if (coveralls_yaml_conf) {
+ if (coveralls_yaml_conf.repo_token) {
+ options.repo_token = coveralls_yaml_conf.repo_token;
}
+ if (coveralls_yaml_conf.service_name) {
+ options.service_name = coveralls_yaml_conf.service_name;
+ }
+ }
+
+ // try to get the repo token as an environment variable
+ if (process.env.COVERALLS_REPO_TOKEN) {
+ options.repo_token = process.env.COVERALLS_REPO_TOKEN;
+ }
+
+ if ('travis-pro' === options.service_name && !options.repo_token) {
+ logger.warn('Repo token could not be determined. Continuing without it. ' +
+ 'This is necessary for private repos only, so may not be an issue at all.');
+ }
+
+ // try to get the service name as an environment variable
+ if (process.env.COVERALLS_SERVICE_NAME) {
+ options.service_name = process.env.COVERALLS_SERVICE_NAME;
}
if (process.env.COVERALLS_FLAG_NAME) {
diff --git a/test/getOptions.js b/test/getOptions.js
index becb31f..5850dc2 100644
--- a/test/getOptions.js
+++ b/test/getOptions.js
@@ -45,6 +45,9 @@ describe('getBaseOptions', () => {
it('should set service_name and service_job_id if it\'s running on travis-ci', done => {
testTravisCi(getBaseOptions, done);
});
+ it('should set service_name and service_job_id if it\'s running on travis-pro', done => {
+ testTravisPro(getBaseOptions, done);
+ });
it('should set service_name and service_job_id if it\'s running on jenkins', done => {
testJenkins(getBaseOptions, done);
});
@@ -137,6 +140,9 @@ describe('getOptions', () => {
it('should set service_name and service_job_id if it\'s running on travis-ci', done => {
testTravisCi(getOptions, done);
});
+ it('should set service_name and service_job_id if it\'s running on travis-pro', done => {
+ testTravisPro(getOptions, done);
+ });
it('should set service_name and service_job_id if it\'s running on jenkins', done => {
testJenkins(getOptions, done);
});
@@ -350,6 +356,23 @@ const testTravisCi = (sut, done) => {
});
};
+const testTravisPro = (sut, done) => {
+ const file = path.join(process.cwd(), '.coveralls.yml');
+ const service_name = 'travis-pro';
+ fs.writeFileSync(file, `service_name: ${service_name}`);
+ process.env.TRAVIS = 'TRUE';
+ process.env.TRAVIS_JOB_ID = '1234';
+ process.env.TRAVIS_COMMIT = 'a12s2d3df4f435g45g45g67h5g6';
+ sut((err, options) => {
+ should.not.exist(err);
+ options.service_name.should.equal(service_name);
+ options.service_job_id.should.equal('1234');
+ options.git.head.id.should.equal('a12s2d3df4f435g45g45g67h5g6');
+ fs.unlinkSync(file);
+ done();
+ });
+};
+
const testJenkins = (sut, done) => {
process.env.JENKINS_URL = 'something';
process.env.BUILD_ID = '1234';