Skip to content
Snippets Groups Projects
Commit 517dad74 authored by michael.minelli's avatar michael.minelli
Browse files

Sonar => Resolve issues

parent 937081e6
No related branches found
No related tags found
No related merge requests found
......@@ -11,14 +11,14 @@ class SharedConfig {
enabled: boolean
url: string
token: string
}
};
constructor() {
this.production = process.env.NODE_ENV === 'production';
this.sonar = {
enabled: ['yes', 'true', '1', 'on'].includes(process.env.SONAR_ENABLED?.trim()?.toLowerCase() ?? ''),
url: process.env.SONAR_URL || '',
token: process.env.SONAR_TOKEN || ''
enabled: [ 'yes', 'true', '1', 'on' ].includes(process.env.SONAR_ENABLED?.trim()?.toLowerCase() ?? ''),
url : process.env.SONAR_URL ?? '',
token : process.env.SONAR_TOKEN ?? ''
};
this.logsFolder = process.env.LOGS_FOLDER ?? '';
......
......@@ -4,7 +4,7 @@ import path from 'path';
class Toolbox {
public urlToPath(url: string): string {
return url.replace(/^([a-z]{3,5}:\/{2})?[a-z.@]+(:[0-9]{1,5})?.(.*)/, '$3').replace('.git', '');
return url.replace(/^([a-z]{3,5}:\/{2})?[a-z.@]+(:\d{1,5})?.(.*)/, '$3').replace('.git', '');
}
/*
......
......@@ -64,7 +64,7 @@ function registerStringCapitalizeName() {
function registerStringConvertWithEnvVars() {
String.prototype.convertWithEnvVars = function (this: string): string {
return this.replace(/\${?([a-zA-Z0-9_]+)}?/g, (_match: string, p1: string) => process.env[p1] || '');
return this.replace(/\${?(\w+)}?/g, (_match: string, p1: string) => process.env[p1] ?? '');
};
}
......
......@@ -57,10 +57,10 @@ class RecursiveFilesStats {
name: file,
path: path.join(rootPath, file)
})).filter(item => {
if ( options.include && options.include.test(item.path) ) {
if ( options.include?.test(item.path) ) {
return true;
}
if ( options.exclude && options.exclude.test(item.path) ) {
if ( options.exclude?.test(item.path) ) {
return false;
}
if ( options.ignored ) {
......
......@@ -10,9 +10,7 @@ class SharedGitlabManager {
private readonly refreshTokenFunction?: () => Promise<string>;
setToken(token: string) {
this.api = new Gitlab(Object.assign({
host: this.gitlabUrl ?? ''
}, this.refreshTokenFunction ? { oauthToken: token } : { token: token }));
this.api = new Gitlab({ host: this.gitlabUrl ?? '', ...(this.refreshTokenFunction ? { oauthToken: token } : { token: token }) });
}
constructor(public gitlabUrl: string, token: string, public clientId?: string, public urlRedirect?: string, public urlToken?: string, refreshTokenFunction?: () => Promise<string>) {
......
......@@ -4,19 +4,19 @@ import SharedConfig from '../config/SharedConfig';
class SharedSonarManager {
// Use custom instance to allow self-signed certificates
private instance = axios.create({
httpsAgent: new https.Agent({
rejectUnauthorized: false
})
});
private readonly axiosInstance = axios.create({
httpsAgent: new https.Agent({
rejectUnauthorized: false
})
});
async isSonarSupported(): Promise<boolean> {
if (!SharedConfig.sonar.enabled) {
if ( !SharedConfig.sonar.enabled ) {
return false;
}
try {
const sonar = await this.instance.get(SharedConfig.sonar.url);
const sonar = await this.axiosInstance.get(SharedConfig.sonar.url);
return sonar.status == 200;
} catch ( error ) {
return false;
......@@ -29,15 +29,16 @@ class SharedSonarManager {
* @param language
*/
mapLanguage(language: string): string {
switch (language) {
case "csharp":
return "cs";
case "python":
return "py";
switch ( language ) {
case 'csharp':
return 'cs';
case 'python':
return 'py';
default:
return language;
}
}
}
export default new SharedSonarManager();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment