screwdriver-coverage-sonar 4.0.0 → 4.1.1

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 (3) hide show
  1. package/commands.txt +5 -2
  2. package/index.js +29 -16
  3. package/package.json +1 -1
package/commands.txt CHANGED
@@ -10,8 +10,11 @@ if echo $SCM_URL | grep git@ > /dev/null 2>&1; then export SONAR_SCM_URL=`echo $
10
10
  if [ ! -z "$SD_SELF_SONAR_HOST" ]; then SCANNER_OPTION='"-Dsonar.host.url=$SD_SELF_SONAR_HOST" "-Dsonar.login=$SONAR_TOKEN" "-Dsonar.projectKey=$SD_SONAR_PROJECT_KEY" "-Dsonar.projectName=$SD_SONAR_PROJECT_NAME" "-Dsonar.projectVersion=$PROJECT_VERSION" "-Dsonar.links.scm=$SONAR_SCM_URL" "-Dsonar.links.ci=$SD_UI_URL/pipelines/$SD_PIPELINE_ID" "-Dsonar.scm.revision=$SD_BUILD_SHA" $SONAR_OPTIONS'; else SCANNER_OPTION='"-Dsonar.host.url=$SD_SONAR_HOST" "-Dsonar.login=$SONAR_TOKEN" "-Dsonar.projectKey=$SD_SONAR_PROJECT_KEY" "-Dsonar.projectName=$SD_SONAR_PROJECT_NAME" "-Dsonar.projectVersion=$PROJECT_VERSION" "-Dsonar.links.scm=$SONAR_SCM_URL" "-Dsonar.links.ci=$SD_UI_URL/pipelines/$SD_PIPELINE_ID" "-Dsonar.scm.revision=$SD_BUILD_SHA" $SONAR_OPTIONS'; fi
11
11
  SCANNER_PATH="/opt/sd/sonar-scanner/bin/sonar-scanner"
12
12
  if [ -s ${SCANNER_PATH} ] && [ -x ${SCANNER_PATH} ]; then eval $SCANNER_PATH $SCANNER_OPTION || true; exit 0; fi
13
- if [ `uname` = 'Darwin' ]; then TARGET_OS='macosx'; else TARGET_OS='linux'; fi
14
- SCANNER_PATH="/opt/sd/sonarscanner-cli-${TARGET_OS}/bin/sonar-scanner"
13
+ OS="$(uname)"
14
+ ARCH="$(uname -m)"
15
+ if [ "$OS" = 'Darwin' ]; then TARGET_OS='macosx'; else TARGET_OS='linux'; fi
16
+ if [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then TARGET_ARCH='-arm64'; else TARGET_ARCH=''; fi
17
+ SCANNER_PATH="/opt/sd/sonarscanner-cli-${TARGET_OS}${TARGET_ARCH}/bin/sonar-scanner"
15
18
  if [ -s ${SCANNER_PATH} ] && [ -x ${SCANNER_PATH} ]; then eval $SCANNER_PATH $SCANNER_OPTION || true; exit 0; fi
16
19
  if unzip -version > /dev/null 2>&1; then SD_UNZIP_CMD_WRAPPER="eval"; else SD_UNZIP_CMD_WRAPPER="sd-step exec --pkg-version 6.0 core/unzip"; fi
17
20
  export SD_UNZIP_CMD_WRAPPER
package/index.js CHANGED
@@ -116,27 +116,40 @@ class CoverageSonar extends CoverageBase {
116
116
  method: 'GET',
117
117
  url: `${this.sonarHost}/api/alm_settings/get_binding?project=${componentId}`,
118
118
  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`);
119
+ })
120
+ .then(result => {
121
+ // if project name has been changed, update it
122
+ if (projectName && (!result.repository || result.repository !== projectName)) {
123
+ throw new Error(`Repository name has been changed from ${result.repository} to ${projectName}!`);
124
+ }
122
125
 
123
- if (!this.sonarEnterprise || !projectName) {
124
- return Promise.resolve();
125
- }
126
+ return result;
127
+ })
128
+ .catch(() => {
129
+ // if binding does not exist, add it
130
+ logger.info(`Binding does not exist for Sonar project ${projectKey}, adding`);
131
+
132
+ if (!this.sonarEnterprise || !projectName) {
133
+ return Promise.resolve();
134
+ }
135
+
136
+ const parameters = `almSetting=${gitAppEncoded}&project=${componentId}&repository=${projectName}&summaryCommentEnabled=true&monorepo=false`;
126
137
 
127
- const parameters = `almSetting=${gitAppEncoded}&project=${componentId}&repository=${projectName}&summaryCommentEnabled=true&monorepo=false`;
138
+ logger.info(`Configuring git app with following parameters, ${parameters}`);
128
139
 
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}`);
140
+ return request({
141
+ method: 'POST',
142
+ url: `${this.sonarHost}/api/alm_settings/set_github_binding?${parameters}`,
143
+ username: this.adminToken
144
+ }).catch(error => {
145
+ // if cannot configure app, do not throw err
146
+ logger.error(
147
+ `Failed to configure Git App ${gitApp} for Sonar project ${projectKey}: ${error.message}`
148
+ );
136
149
 
137
- return Promise.resolve();
150
+ return Promise.resolve();
151
+ });
138
152
  });
139
- });
140
153
  }
141
154
 
142
155
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screwdriver-coverage-sonar",
3
- "version": "4.0.0",
3
+ "version": "4.1.1",
4
4
  "description": "SonarQube implementation of the coverage-base class",
5
5
  "main": "index.js",
6
6
  "scripts": {