Skip to content

Commit

Permalink
remove trailing slash
Browse files Browse the repository at this point in the history
Signed-off-by: Chalenge Masekera <[email protected]>
  • Loading branch information
chalenge committed Feb 6, 2025
1 parent 429df30 commit abc3352
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions sources/azure-workitems-source/src/azure-workitems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class AzureWorkitems {

AzureWorkitems.validateConfig(config);

const apiUrl = config.api_url ?? DEFAULT_API_URL;
const apiUrl = AzureWorkitems.cleanUrl(config.api_url) ?? DEFAULT_API_URL;
const version = config.api_version ?? DEFAULT_API_VERSION;
const accessToken = base64Encode(`:${config.access_token}`);

Expand All @@ -91,7 +91,8 @@ export class AzureWorkitems {
1000
);

const graphApiUrl = config.graph_api_url ?? DEFAULT_GRAPH_API_URL;
const graphApiUrl =
AzureWorkitems.cleanUrl(config.graph_api_url) ?? DEFAULT_GRAPH_API_URL;

const graphClient = axios.create({
baseURL: `${graphApiUrl}/${config.organization}/_apis/graph`,
Expand Down Expand Up @@ -146,11 +147,9 @@ export class AzureWorkitems {
}

// If using a custom API URL for Server, a custom Graph API URL must also be provided
const apiUrl =
config.api_url?.trimEnd().replace(/\/$/, '').trim() ?? DEFAULT_API_URL;
const apiUrl = AzureWorkitems.cleanUrl(config.api_url) ?? DEFAULT_API_URL;
const graphApiUrl =
config.graph_api_url?.trimEnd().replace(/\/$/, '').trim() ??
DEFAULT_GRAPH_API_URL;
AzureWorkitems.cleanUrl(config.graph_api_url) ?? DEFAULT_GRAPH_API_URL;

if (apiUrl !== DEFAULT_API_URL && graphApiUrl === DEFAULT_GRAPH_API_URL) {
throw new VError(
Expand All @@ -159,6 +158,10 @@ export class AzureWorkitems {
}
}

static cleanUrl(url?: string): string | undefined {
return url?.trim().endsWith('/') ? url.trim().slice(0, -1) : url?.trim();
}

async checkConnection(): Promise<void> {
try {
const iter = this.getUsers();
Expand Down

0 comments on commit abc3352

Please sign in to comment.