Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-github-url-extension.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@asyncapi/cli": patch
---

Fix GitHub URL parsing for branches with slashes and file extension detection for multi-dot filenames
2 changes: 1 addition & 1 deletion src/apps/cli/commands/new/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export default class NewFile extends Command {
if (!fileName.includes('.')) {
fileNameToWriteToDisk = `${fileName}.yaml`;
} else {
const extension = fileName.split('.')[1];
const extension = fileName.split('.').pop();

if (extension === 'yml' || extension === 'yaml' || extension === 'json') {
fileNameToWriteToDisk = fileName;
Expand Down
2 changes: 1 addition & 1 deletion src/domains/models/SpecificationFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export async function fileExists(name: string): Promise<boolean> {
return true;
}

const extension = name.split('.')[1];
const extension = name.split('.').pop();

const allowedExtenstion = ['yml', 'yaml', 'json'];

Expand Down
23 changes: 20 additions & 3 deletions src/domains/services/validation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,29 @@ const convertGitHubWebUrl = (url: string): string => {
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\/([^\/]+)\/(.+)$/;
// Branch names can contain slashes (e.g., feature/new-validation)
// We match owner/repo then greedily capture everything after /blob/
// and split on the last occurrence that yields a valid file path
const githubWebPattern = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/blob\/(.+)$/;
const match = urlWithoutFragment.match(githubWebPattern);

if (match) {
const [, owner, repo, branch, filePath] = match;
const [, owner, repo, branchAndPath] = match;
// The branch/path boundary is ambiguous for branches with slashes.
// Use the GitHub Contents API which accepts the full path and ref separately.
// Strategy: find the last segment that looks like a file (has extension or is the shortest valid split)
const segments = branchAndPath.split('/');
// Try progressively longer branch names until we find one where the remainder looks like a file path
for (let i = 1; i < segments.length; i++) {
const possiblePath = segments.slice(i).join('/');
if (possiblePath.includes('.') || i === segments.length - 1) {
const branch = segments.slice(0, i).join('/');
return `https://api.github.com/repos/${owner}/${repo}/contents/${possiblePath}?ref=${branch}`;
}
}
// Fallback: assume first segment is branch
const branch = segments[0];
const filePath = segments.slice(1).join('/');
return `https://api.github.com/repos/${owner}/${repo}/contents/${filePath}?ref=${branch}`;
}

Expand Down
Loading