private guessBaseUrls()

in src/package.ts [804:847]


	private guessBaseUrls(
		githostBranch: string | undefined
	): { content: string; images: string; repository: string } | undefined {
		let repository = null;

		if (typeof this.manifest.repository === 'string') {
			repository = this.manifest.repository;
		} else if (this.manifest.repository && typeof this.manifest.repository['url'] === 'string') {
			repository = this.manifest.repository['url'];
		}

		if (!repository) {
			return undefined;
		}

		const gitHubRegex = /(?<domain>github(\.com\/|:))(?<project>(?:[^/]+)\/(?:[^/]+))(\/|$)/;
		const gitLabRegex = /(?<domain>gitlab(\.com\/|:))(?<project>(?:[^/]+)(\/(?:[^/]+))+)(\/|$)/;
		const match = ((gitHubRegex.exec(repository) || gitLabRegex.exec(repository)) as unknown) as {
			groups: Record<string, string>;
		};

		if (!match) {
			return undefined;
		}

		const project = match.groups.project.replace(/\.git$/i, '');
		const branchName = githostBranch ? githostBranch : 'HEAD';

		if (/^github/.test(match.groups.domain)) {
			return {
				content: `https://github.com/${project}/blob/${branchName}`,
				images: `https://github.com/${project}/raw/${branchName}`,
				repository: `https://github.com/${project}`,
			};
		} else if (/^gitlab/.test(match.groups.domain)) {
			return {
				content: `https://gitlab.com/${project}/-/blob/${branchName}`,
				images: `https://gitlab.com/${project}/-/raw/${branchName}`,
				repository: `https://gitlab.com/${project}`,
			};
		}

		return undefined;
	}