Skip to content

Commit 1e66974

Browse files
authored
fix: normalize GitHub API URL (#839)
1 parent 2bc11bc commit 1e66974

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/octokit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export const SemanticReleaseOctokit = Octokit.plugin(
5555
export function toOctokitOptions(options) {
5656
const baseUrl =
5757
"githubApiUrl" in options && options.githubApiUrl
58-
? options.githubApiUrl
58+
? // Use `urljoin` to normalize the provided URL
59+
urljoin(options.githubApiUrl, "")
5960
: "githubUrl" in options && options.githubUrl
6061
? urljoin(options.githubUrl, options.githubApiPathPrefix)
6162
: undefined;

test/to-octokit-options.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,18 @@ test("Do not use a proxy if set to false", async (t) => {
5252
});
5353
t.is(request.agent, undefined);
5454
});
55+
56+
test("githubUrl with trailing slash", async (t) => {
57+
const options = toOctokitOptions({
58+
githubUrl: "http://localhost:10001/",
59+
githubApiPathPrefix: "",
60+
});
61+
t.is(options.baseUrl, "http://localhost:10001");
62+
});
63+
64+
test("githubApiUrl with trailing slash", async (t) => {
65+
const options = toOctokitOptions({
66+
githubApiUrl: "http://api.localhost:10001/",
67+
});
68+
t.is(options.baseUrl, "http://api.localhost:10001");
69+
});

0 commit comments

Comments
 (0)