-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
101 lines (88 loc) · 3.76 KB
/
index.js
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
'use strict';
/* eslint-disable no-underscore-dangle */
class CoverageBase {
/** Constructor for Coverage plugin
* @method Constructor
* @param {Object} config Configuration
* @return {CoverageBase}
*/
constructor(config) {
this.config = config;
}
/**
* Return an access token that build can use to talk to coverage server
* @method getAccessToken
* @param {Object} config
* @param {Object} [config.annotations] Job annotations
* @param {Object} config.buildCredentials Information stored in a build JWT
* @return {Promise} An access token that builds can use to talk to coverage server
*/
getAccessToken(config) {
return this._getAccessToken(config);
}
_getAccessToken() {
return Promise.reject(new Error('Not implemented'));
}
/**
* Return coverage metadata, such as links to the project and coverage percentage
* @method getInfo
* @param {Object} config
* @param {String} [config.annotations] Job annotations
* @param {String} config.jobId Screwdriver job ID
* @param {String} [config.jobName] Screwdriver job name
* @param {String} [config.pipelineId] Screwdriver pipeline ID (if enterprise is enabled)
* @param {String} [config.pipelineName] Screwdriver pipeline name
* @param {String} [config.prNum] Pull request number
* @param {String} config.startTime Time the job started
* @param {String} config.endTime Time the job ended
* @param {String} [config.coverageProjectKey] Project key
* @return {Promise} An object with coverage metadata
*/
getInfo(config) {
return this._getInfo(config);
}
_getInfo() {
return Promise.reject(new Error('Not implemented'));
}
/**
* Get shell command to upload coverage to server
* @method getUploadCoverageCmd
* @param {Object} config
* @param {Object} config.build Build configuration
* @param {Object} config.job Job configuration
* @param {Object} config.pipeline Pipeline configuration
* @return {Promise} Shell commands to upload coverage
*/
getUploadCoverageCmd(config) {
const { build } = config;
if (this.isCoverageEnabled(this.config, build) === 'false') {
const skipMessage =
'Coverage feature is skipped. ' +
'Set SD_COVERAGE_PLUGIN_ENABLED environment variable true, ' +
'if you want to get coverages.';
return Promise.resolve(`echo ${skipMessage}`);
}
return this._getUploadCoverageCmd();
}
_getUploadCoverageCmd() {
return Promise.reject(new Error('Not implemented'));
}
/**
* Verify to run coverage plugin or not
* @method isCoverageEnabled
* @param {Object} clusterConfig Default coverage plugin setting at cluster level.
* @param {Object} buildConfig Configurations in each builds.
* @param {String} buildConfig.environment.SD_COVERAGE_PLUGIN_ENABLED
* Coverage plugin enable setting by user. It should be 'true' or 'false'.
* @return {String} 'true' or 'false'
*/
isCoverageEnabled(clusterConfig, buildConfig) {
// if user has the configuration, use it
if (buildConfig.environment && buildConfig.environment.SD_COVERAGE_PLUGIN_ENABLED) {
return buildConfig.environment.SD_COVERAGE_PLUGIN_ENABLED;
}
// if not, use cluster wide default
return clusterConfig.default;
}
}
module.exports = CoverageBase;