screwdriver-coverage-sonar 4.1.0 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +36 -22
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -45,14 +45,15 @@ class CoverageSonar extends CoverageBase {
|
|
|
45
45
|
'Invalid config for sonar coverage plugin'
|
|
46
46
|
);
|
|
47
47
|
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
48
|
+
// use this.config for default values
|
|
49
|
+
this.sdCoverageAuthUrl = `${this.config.sdApiUrl}/v4/coverage/token`;
|
|
50
|
+
this.adminToken = this.config.adminToken;
|
|
51
|
+
this.sonarHost = this.config.sonarHost;
|
|
52
|
+
this.sonarEnterprise = this.config.sonarEnterprise;
|
|
53
|
+
this.sonarGitAppName = this.config.sonarGitAppName;
|
|
53
54
|
|
|
54
55
|
this.uploadCommands = COMMANDS.replace('$SD_SONAR_HOST', this.sonarHost)
|
|
55
|
-
.replace('$SD_UI_URL', config.sdUiUrl)
|
|
56
|
+
.replace('$SD_UI_URL', this.config.sdUiUrl)
|
|
56
57
|
.replace('$SD_SONAR_ENTERPRISE', this.sonarEnterprise)
|
|
57
58
|
.split('\n');
|
|
58
59
|
|
|
@@ -116,27 +117,40 @@ class CoverageSonar extends CoverageBase {
|
|
|
116
117
|
method: 'GET',
|
|
117
118
|
url: `${this.sonarHost}/api/alm_settings/get_binding?project=${componentId}`,
|
|
118
119
|
username: this.adminToken
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
})
|
|
121
|
+
.then(result => {
|
|
122
|
+
// if project name has been changed, update it
|
|
123
|
+
if (projectName && (!result.repository || result.repository !== projectName)) {
|
|
124
|
+
throw new Error(`Repository name has been changed from ${result.repository} to ${projectName}!`);
|
|
125
|
+
}
|
|
122
126
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
return result;
|
|
128
|
+
})
|
|
129
|
+
.catch(() => {
|
|
130
|
+
// if binding does not exist, add it
|
|
131
|
+
logger.info(`Binding does not exist for Sonar project ${projectKey}, adding`);
|
|
132
|
+
|
|
133
|
+
if (!this.sonarEnterprise || !projectName) {
|
|
134
|
+
return Promise.resolve();
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const parameters = `almSetting=${gitAppEncoded}&project=${componentId}&repository=${projectName}&summaryCommentEnabled=true&monorepo=false`;
|
|
126
138
|
|
|
127
|
-
|
|
139
|
+
logger.info(`Configuring git app with following parameters, ${parameters}`);
|
|
128
140
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
141
|
+
return request({
|
|
142
|
+
method: 'POST',
|
|
143
|
+
url: `${this.sonarHost}/api/alm_settings/set_github_binding?${parameters}`,
|
|
144
|
+
username: this.adminToken
|
|
145
|
+
}).catch(error => {
|
|
146
|
+
// if cannot configure app, do not throw err
|
|
147
|
+
logger.error(
|
|
148
|
+
`Failed to configure Git App ${gitApp} for Sonar project ${projectKey}: ${error.message}`
|
|
149
|
+
);
|
|
136
150
|
|
|
137
|
-
|
|
151
|
+
return Promise.resolve();
|
|
152
|
+
});
|
|
138
153
|
});
|
|
139
|
-
});
|
|
140
154
|
}
|
|
141
155
|
|
|
142
156
|
/**
|