screwdriver-coverage-sonar 5.1.1 → 5.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 +27 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -147,6 +147,28 @@ class CoverageSonar extends CoverageBase {
|
|
|
147
147
|
return gitAppSetting.key;
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
/**
|
|
151
|
+
* Normalize the repository name expected by Sonar's Git binding API.
|
|
152
|
+
* Upstream callers may pass a broader project name like "org/repo:checkout-root" specific to SD pipelines, but Sonar expects just "org/repo".
|
|
153
|
+
* @param {String} projectName Sonar project name
|
|
154
|
+
* @returns {String} Repository slug in org/repo format when available
|
|
155
|
+
*/
|
|
156
|
+
_getRepositoryName(projectName) {
|
|
157
|
+
if (!projectName) {
|
|
158
|
+
return projectName;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const [organization, repositoryWithSuffix] = projectName.split('/');
|
|
162
|
+
|
|
163
|
+
if (!organization || !repositoryWithSuffix) {
|
|
164
|
+
return projectName;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const repository = repositoryWithSuffix.split(':')[0];
|
|
168
|
+
|
|
169
|
+
return `${organization}/${repository}`;
|
|
170
|
+
}
|
|
171
|
+
|
|
150
172
|
/**
|
|
151
173
|
* Configure Git App in SonarQube
|
|
152
174
|
* @param {String} projectKey Sonar project key
|
|
@@ -158,6 +180,7 @@ class CoverageSonar extends CoverageBase {
|
|
|
158
180
|
const gitApp = await this._getGitApp(scmContext);
|
|
159
181
|
const gitAppEncoded = encodeURIComponent(gitApp);
|
|
160
182
|
const componentId = encodeURIComponent(projectKey);
|
|
183
|
+
const repositoryName = this._getRepositoryName(projectName);
|
|
161
184
|
|
|
162
185
|
// Check if binding exists
|
|
163
186
|
return request({
|
|
@@ -167,8 +190,8 @@ class CoverageSonar extends CoverageBase {
|
|
|
167
190
|
})
|
|
168
191
|
.then(result => {
|
|
169
192
|
// if project name has been changed, update it
|
|
170
|
-
if (
|
|
171
|
-
throw new Error(`Repository name has been changed from ${result.repository} to ${
|
|
193
|
+
if (repositoryName && (!result.repository || result.repository !== repositoryName)) {
|
|
194
|
+
throw new Error(`Repository name has been changed from ${result.repository} to ${repositoryName}!`);
|
|
172
195
|
}
|
|
173
196
|
|
|
174
197
|
return result;
|
|
@@ -177,11 +200,11 @@ class CoverageSonar extends CoverageBase {
|
|
|
177
200
|
// if binding does not exist, add it
|
|
178
201
|
logger.info(`Binding does not exist for Sonar project ${projectKey}, adding`);
|
|
179
202
|
|
|
180
|
-
if (!this.sonarEnterprise || !
|
|
203
|
+
if (!this.sonarEnterprise || !repositoryName) {
|
|
181
204
|
return Promise.resolve();
|
|
182
205
|
}
|
|
183
206
|
|
|
184
|
-
const parameters = `almSetting=${gitAppEncoded}&project=${componentId}&repository=${
|
|
207
|
+
const parameters = `almSetting=${gitAppEncoded}&project=${componentId}&repository=${repositoryName}&summaryCommentEnabled=true&monorepo=false`;
|
|
185
208
|
|
|
186
209
|
logger.info(`Configuring git app with following parameters, ${parameters}`);
|
|
187
210
|
|