extensions/github/src/links.ts/getPermalink
export function getPermalink(gitAPI: GitAPI, hostPrefix?: string): string | undefined {
	hostPrefix = hostPrefix ?? 'https://github.com';
	const { uri, range } = getFileAndPosition();
	if (!uri) {
		return;
	}
	const gitRepo = getRepositoryForFile(gitAPI, uri);
	if (!gitRepo) {
		return;
	}
	let repo: { owner: string; repo: string } | undefined;
	gitRepo.state.remotes.find(remote => {
		if (remote.fetchUrl) {
			const foundRepo = getRepositoryFromUrl(remote.fetchUrl);
			if (foundRepo && (remote.name === gitRepo.state.HEAD?.upstream?.remote)) {
				repo = foundRepo;
				return;
			} else if (foundRepo && !repo) {
				repo = foundRepo;
			}
		}
		return;
	});
	if (!repo) {
		return;
	}

	const commitHash = gitRepo.state.HEAD?.commit;
	const pathSegment = uri.path.substring(gitRepo.rootUri.path.length);

	return `${hostPrefix}/${repo.owner}/${repo.repo}/blob/${commitHash
		}${pathSegment}${rangeString(range)}`;
}