Skip to content

Commit a685015

Browse files
committed
💪 Refacotr codes to find fetchURL
1 parent f341154 commit a685015

File tree

4 files changed

+21
-31
lines changed

4 files changed

+21
-31
lines changed

commit_url.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ export async function getCommitURL(
1111
commitish: string,
1212
options: Options = {},
1313
): Promise<URL> {
14-
if (!options.remote) {
15-
const remote = await getRemoteContains(commitish, options);
16-
return getCommitURL(commitish, { ...options, remote: remote ?? "origin" });
17-
}
18-
const fetchURL = await getRemoteFetchURL(options.remote, options);
14+
const remote = options.remote ??
15+
await getRemoteContains(commitish, options) ??
16+
"origin";
17+
const fetchURL = await getRemoteFetchURL(remote, options);
1918
if (!fetchURL) {
20-
throw new Error(`Remote '${options.remote}' has no fetch URL`);
19+
throw new Error(`No remote '${remote}' found`);
2120
}
2221
const hostingService = await getHostingService(fetchURL, options);
2322
return hostingService.getCommitURL(fetchURL, commitish);

home_url.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ export type Options = ExecuteOptions & {
1010
export async function getHomeURL(
1111
options: Options = {},
1212
): Promise<URL> {
13-
if (!options.remote) {
14-
const remote = await getRemoteContains("HEAD", options);
15-
return getHomeURL({ ...options, remote: remote ?? "origin" });
16-
}
17-
const fetchURL = await getRemoteFetchURL(options.remote, options);
13+
const remote = options.remote ??
14+
await getRemoteContains("HEAD", options) ??
15+
"origin";
16+
const fetchURL = await getRemoteFetchURL(remote, options);
1817
if (!fetchURL) {
19-
throw new Error(`Remote '${options.remote}' has no fetch URL`);
18+
throw new Error(`No remote '${remote}' found or failed to get fetch URL.`);
2019
}
2120
const hostingService = await getHostingService(fetchURL, options);
2221
return hostingService.getHomeURL(fetchURL);

object_url.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,12 @@ export async function getObjectURL(
1313
path: string,
1414
options: Options = {},
1515
): Promise<URL> {
16-
if (!options.remote) {
17-
const remote = await getRemoteContains(commitish, options);
18-
return getObjectURL(commitish, path, {
19-
...options,
20-
remote: remote ?? "origin",
21-
});
22-
}
23-
const fetchURL = await getRemoteFetchURL(options.remote, options);
16+
const remote = options.remote ??
17+
await getRemoteContains(commitish, options) ??
18+
"origin";
19+
const fetchURL = await getRemoteFetchURL(remote, options);
2420
if (!fetchURL) {
25-
throw new Error(`Remote '${options.remote}' has no fetch URL`);
21+
throw new Error(`No remote '${remote}' found`);
2622
}
2723
const hostingService = await getHostingService(fetchURL, options);
2824
const [normPath, range] = parsePath(path);

pull_request_url.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,12 @@ export async function getPullRequestURL(
1616
commitish: string,
1717
options: Options = {},
1818
): Promise<URL> {
19-
if (!options.remote) {
20-
const remote = await getRemoteContains(commitish, options);
21-
return getPullRequestURL(commitish, {
22-
...options,
23-
remote: remote ?? "origin",
24-
});
25-
}
26-
const fetchURL = await getRemoteFetchURL(options.remote, options);
19+
const remote = options.remote ??
20+
await getRemoteContains(commitish, options) ??
21+
"origin";
22+
const fetchURL = await getRemoteFetchURL(remote, options);
2723
if (!fetchURL) {
28-
throw new Error(`Remote '${options.remote}' has no fetch URL`);
24+
throw new Error(`No remote '${remote}' found`);
2925
}
3026
const hostingService = await getHostingService(fetchURL, options);
3127
if (!hostingService.getPullRequestURL) {
@@ -35,7 +31,7 @@ export async function getPullRequestURL(
3531
}
3632
const pr = await getPullRequestContains(
3733
commitish,
38-
options.remote,
34+
remote,
3935
options,
4036
);
4137
if (!pr) {

0 commit comments

Comments
 (0)