Skip to content

Commit

Permalink
fix: don't require .git suffix to open file on github
Browse files Browse the repository at this point in the history
close #753
  • Loading branch information
Vinzent03 committed Jul 23, 2024
1 parent 15436e6 commit 9b264bf
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/openInGitHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,23 @@ async function getData(
};
}
}
// TODO: This process always causes a runtime error if the remote url is not github.com, so it should be fixed.
// However, this runtime error does not have a fatal negative impact, so we temporary ignore.
// @ts-ignore
const [isGitHub, httpsUser, httpsRepo, sshUser, sshRepo] = remoteUrl.match(
/(?:^https:\/\/github\.com\/(.*)\/(.*)\.git$)|(?:^[a-zA-Z]+@github\.com:(.*)\/(.*)\.git$)/
const res = remoteUrl.match(
/(?:^https:\/\/github\.com\/(.+)\/(.+?)(?:\.git)?$)|(?:^[a-zA-Z]+@github\.com:(.+)\/(.+?)(?:\.git)?$)/
);
return {
result: "success",
isGitHub: !!isGitHub,
repo: httpsRepo || sshRepo,
user: httpsUser || sshUser,
branch: branch,
filePath: filePath,
};
if (res == null) {
return {
result: "failure",
reason: "Could not parse remote url",
};
} else {
const [isGitHub, httpsUser, httpsRepo, sshUser, sshRepo] = res;
return {
result: "success",
isGitHub: !!isGitHub,
repo: httpsRepo || sshRepo,
user: httpsUser || sshUser,
branch: branch,
filePath: filePath,
};
}
}

0 comments on commit 9b264bf

Please sign in to comment.