Replace slash stripping regexp with trimEnd
Signed-off-by: Johan Haals <johan.haals@gmail.com>
This commit is contained in:
@@ -35,7 +35,8 @@
|
||||
"git-url-parse": "^11.6.0",
|
||||
"@octokit/rest": "^18.5.3",
|
||||
"@octokit/auth-app": "^3.4.0",
|
||||
"luxon": "^2.0.2"
|
||||
"luxon": "^2.0.2",
|
||||
"lodash": "^4.17.21"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@backstage/cli": "^0.7.14",
|
||||
|
||||
@@ -83,7 +83,7 @@ export function readBitbucketIntegrationConfig(
|
||||
}
|
||||
|
||||
if (apiBaseUrl) {
|
||||
apiBaseUrl = apiBaseUrl.replace(/\/+$/, '');
|
||||
apiBaseUrl = trimEnd(apiBaseUrl, '/');
|
||||
} else if (host === BITBUCKET_HOST) {
|
||||
apiBaseUrl = BITBUCKET_API_BASE_URL;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import { Config } from '@backstage/config';
|
||||
import { trimEnd } from 'lodash';
|
||||
import { isValidHost } from '../helpers';
|
||||
|
||||
const GITHUB_HOST = 'github.com';
|
||||
@@ -133,13 +134,13 @@ export function readGitHubIntegrationConfig(
|
||||
}
|
||||
|
||||
if (apiBaseUrl) {
|
||||
apiBaseUrl = apiBaseUrl.replace(/\/+$/, '');
|
||||
apiBaseUrl = trimEnd(apiBaseUrl, '/');
|
||||
} else if (host === GITHUB_HOST) {
|
||||
apiBaseUrl = GITHUB_API_BASE_URL;
|
||||
}
|
||||
|
||||
if (rawBaseUrl) {
|
||||
rawBaseUrl = rawBaseUrl.replace(/\/+$/, '');
|
||||
rawBaseUrl = trimEnd(rawBaseUrl, '/');
|
||||
} else if (host === GITHUB_HOST) {
|
||||
rawBaseUrl = GITHUB_RAW_BASE_URL;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import { Config } from '@backstage/config';
|
||||
import { trimEnd } from 'lodash';
|
||||
import { isValidHost, isValidUrl } from '../helpers';
|
||||
|
||||
const GITLAB_HOST = 'gitlab.com';
|
||||
@@ -67,13 +68,13 @@ export function readGitLabIntegrationConfig(
|
||||
let baseUrl = config.getOptionalString('baseUrl');
|
||||
|
||||
if (apiBaseUrl) {
|
||||
apiBaseUrl = apiBaseUrl.replace(/\/+$/, '');
|
||||
apiBaseUrl = trimEnd(apiBaseUrl, '/');
|
||||
} else if (host === GITLAB_HOST) {
|
||||
apiBaseUrl = GITLAB_API_BASE_URL;
|
||||
}
|
||||
|
||||
if (baseUrl) {
|
||||
baseUrl = baseUrl.replace(/\/+$/, '');
|
||||
baseUrl = trimEnd(baseUrl, '/');
|
||||
} else {
|
||||
baseUrl = `https://${host}`;
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
import parseGitUrl from 'git-url-parse';
|
||||
import { trimEnd } from 'lodash';
|
||||
import { ScmIntegration, ScmIntegrationsGroup } from './types';
|
||||
|
||||
/** Checks whether the given argument is a valid URL hostname */
|
||||
@@ -83,9 +84,10 @@ export function defaultScmResolveUrl(options: {
|
||||
// If it is an absolute path, move relative to the repo root
|
||||
const { filepath } = parseGitUrl(base);
|
||||
updated = new URL(base);
|
||||
const repoRootPath = updated.pathname
|
||||
.substring(0, updated.pathname.length - filepath.length)
|
||||
.replace(/\/+$/, '');
|
||||
const repoRootPath = trimEnd(
|
||||
updated.pathname.substring(0, updated.pathname.length - filepath.length),
|
||||
'/',
|
||||
);
|
||||
updated.pathname = `${repoRootPath}${url}`;
|
||||
} else {
|
||||
// For relative URLs, just let the default URL constructor handle the
|
||||
|
||||
Reference in New Issue
Block a user