1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
var fs = require('fs');
var path = require('path');
var yaml = require('js-yaml');
var logger = require('./logger')();
var fetchGitData = require('./fetchGitData');
var getBaseOptions = function(cb){
var options = {};
var git_commit = process.env.COVERALLS_GIT_COMMIT;
var git_branch = process.env.COVERALLS_GIT_BRANCH;
if (process.env.TRAVIS){
options.service_name = 'travis-ci';
options.service_job_id = process.env.TRAVIS_JOB_ID;
git_commit = process.env.TRAVIS_COMMIT;
git_branch = process.env.TRAVIS_BRANCH;
}
/*
if (process.env.DRONE){
options.service_name = 'drone';
options.service_job_id = process.env.DRONE_BUILD_NUMBER;
git_commit = process.env.DRONE_COMMIT;
git_branch = process.env.DRONE_BRANCH;
}
*/
if (process.env.JENKINS_URL){
options.service_name = 'jenkins';
options.service_job_id = process.env.BUILD_ID;
options.service_pull_request = process.env.ghprbPullId;
git_commit = process.env.GIT_COMMIT;
git_branch = process.env.GIT_BRANCH;
}
if (process.env.CIRCLECI){
options.service_name = 'circleci';
options.service_job_id = process.env.CIRCLE_BUILD_NUM;
git_commit = process.env.CIRCLE_SHA1;
git_branch = process.env.CIRCLE_BRANCH;
}
if (process.env.CI_NAME && process.env.CI_NAME === 'codeship'){
options.service_name = 'codeship';
options.service_job_id = process.env.CI_BUILD_NUMBER;
git_commit = process.env.CI_COMMIT_ID;
git_branch = process.env.CI_BRANCH;
}
if (process.env.WERCKER){
options.service_name = 'wercker';
options.service_job_id = process.env.WERCKER_BUILD_ID;
git_commit = process.env.WERCKER_GIT_COMMIT;
git_branch = process.env.WERCKER_GIT_BRANCH;
}
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;
}
if (!git_commit || !git_branch) {
var data = require('./detectLocalGit')(git_commit, git_branch);
if (data) {
git_commit = git_commit || data.git_commit;
git_branch = git_branch || data.git_branch;
}
}
// 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
var yml = path.join(process.cwd(), '.coveralls.yml');
try {
if (fs.statSync(yml).isFile()) {
var 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;
}
}
} catch(ex){
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.");
}
}
if (git_commit){
fetchGitData({
head: {
id: git_commit
},
branch: git_branch
}, function(err, git){
if (err){
logger.warn('there was an error getting git data: ', err);
} else {
options.git = git;
}
return cb(err, options);
});
} else {
return cb(null, options);
}
};
var getOptions = function(cb){
if (!cb){
throw new Error('getOptions requires a callback');
}
getBaseOptions(function(err, options){
// try to get filepath from the command-line
if (process.argv[2]) {
if (~['-v', '--verbose'].indexOf(process.argv[2])) {
if (process.argv[3]) {
options.filepath = process.argv[3];
}
} else {
options.filepath = process.argv[2];
}
}
cb(err, options);
});
};
module.exports.getBaseOptions = getBaseOptions;
module.exports.getOptions = getOptions;
|