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.
Files changed (2) hide show
  1. package/index.js +36 -22
  2. 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.sdCoverageAuthUrl = `${config.sdApiUrl}/v4/coverage/token`;
49
- this.adminToken = config.adminToken;
50
- this.sonarHost = config.sonarHost;
51
- this.sonarEnterprise = config.sonarEnterprise;
52
- this.sonarGitAppName = config.sonarGitAppName;
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
- }).catch(() => {
120
- // if binding does not exist, add it
121
- logger.info(`Binding does not exist for Sonar project ${projectKey}, adding`);
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
- if (!this.sonarEnterprise || !projectName) {
124
- return Promise.resolve();
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
- const parameters = `almSetting=${gitAppEncoded}&project=${componentId}&repository=${projectName}&summaryCommentEnabled=true&monorepo=false`;
139
+ logger.info(`Configuring git app with following parameters, ${parameters}`);
128
140
 
129
- return request({
130
- method: 'POST',
131
- url: `${this.sonarHost}/api/alm_settings/set_github_binding?${parameters}`,
132
- username: this.adminToken
133
- }).catch(error => {
134
- // if cannot configure app, do not throw err
135
- logger.error(`Failed to configure Git App ${gitApp} for Sonar project ${projectKey}: ${error.message}`);
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
- return Promise.resolve();
151
+ return Promise.resolve();
152
+ });
138
153
  });
139
- });
140
154
  }
141
155
 
142
156
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-coverage-sonar",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "description": "SonarQube implementation of the coverage-base class",
5
5
  "main": "index.js",
6
6
  "scripts": {