From 105f767a6bb89848393adcb7114f5f124a1ca3ef Mon Sep 17 00:00:00 2001 From: Florian Greinacher Date: Wed, 22 May 2024 07:49:01 +0000 Subject: [PATCH] fix: normalize GitHub API URL --- lib/octokit.js | 3 ++- test/to-octokit-options.test.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/octokit.js b/lib/octokit.js index d1d1baa9..6bb6db1c 100644 --- a/lib/octokit.js +++ b/lib/octokit.js @@ -55,7 +55,8 @@ export const SemanticReleaseOctokit = Octokit.plugin( export function toOctokitOptions(options) { const baseUrl = "githubApiUrl" in options && options.githubApiUrl - ? options.githubApiUrl + ? // Use `urljoin` to normalize the provided URL + urljoin(options.githubApiUrl, "") : "githubUrl" in options && options.githubUrl ? urljoin(options.githubUrl, options.githubApiPathPrefix) : undefined; diff --git a/test/to-octokit-options.test.js b/test/to-octokit-options.test.js index 30e88973..38c3a4b8 100644 --- a/test/to-octokit-options.test.js +++ b/test/to-octokit-options.test.js @@ -52,3 +52,18 @@ test("Do not use a proxy if set to false", async (t) => { }); t.is(request.agent, undefined); }); + +test("githubUrl with trailing slash", async (t) => { + const options = toOctokitOptions({ + githubUrl: "http://localhost:10001/", + githubApiPathPrefix: "", + }); + t.is(options.baseUrl, "http://localhost:10001"); +}); + +test("githubApiUrl with trailing slash", async (t) => { + const options = toOctokitOptions({ + githubApiUrl: "http://api.localhost:10001/", + }); + t.is(options.baseUrl, "http://api.localhost:10001"); +});