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.
- package/commands.txt +5 -2
- package/index.js +29 -16
- 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
|
-
|
|
14
|
-
|
|
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
|
-
})
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
124
|
-
|
|
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
|
-
|
|
138
|
+
logger.info(`Configuring git app with following parameters, ${parameters}`);
|
|
128
139
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
150
|
+
return Promise.resolve();
|
|
151
|
+
});
|
|
138
152
|
});
|
|
139
|
-
});
|
|
140
153
|
}
|
|
141
154
|
|
|
142
155
|
/**
|