diff --git a/.changeset/tender-tigers-shave.md b/.changeset/tender-tigers-shave.md new file mode 100644 index 00000000..be292d88 --- /dev/null +++ b/.changeset/tender-tigers-shave.md @@ -0,0 +1,5 @@ +--- +'@asyncapi/cli': minor +--- + +CLI fails for GitHub URLs with slash-based branches and multi-dot spec files diff --git a/src/domains/models/SpecificationFile.ts b/src/domains/models/SpecificationFile.ts index a0d19f19..21896d18 100644 --- a/src/domains/models/SpecificationFile.ts +++ b/src/domains/models/SpecificationFile.ts @@ -234,7 +234,7 @@ export async function fileExists(name: string): Promise { return true; } - const extension = name.split('.')[1]; + const extension = path.extname(name).substring(1); const allowedExtenstion = ['yml', 'yaml', 'json']; diff --git a/src/domains/services/validation.service.ts b/src/domains/services/validation.service.ts index 1d0dffcf..4f7eb55b 100644 --- a/src/domains/services/validation.service.ts +++ b/src/domains/services/validation.service.ts @@ -68,17 +68,9 @@ const convertGitHubWebUrl = (url: string): string => { // Remove fragment from URL before processing const urlWithoutFragment = url.split('#')[0]; - // Handle GitHub web URLs like: https://github.com/owner/repo/blob/branch/path - // eslint-disable-next-line no-useless-escape - const githubWebPattern = /^https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/blob\/([^\/]+)\/(.+)$/; - const match = urlWithoutFragment.match(githubWebPattern); - - if (match) { - const [, owner, repo, branch, filePath] = match; - return `https://api.github.com/repos/${owner}/${repo}/contents/${filePath}?ref=${branch}`; - } - - return url; + return urlWithoutFragment + .replace('github.com', 'raw.githubusercontent.com') + .replace('/blob/', '/'); }; /**