Skip to content
Merged
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
31 changes: 30 additions & 1 deletion src/utils/github.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
import axios from 'axios';
import { logWarning } from './errors.js';

// Default documentation files to exclude from command installation
const DEFAULT_EXCLUDED_FILES = [
'readme',
'claude'
];

/**
* Check if a markdown file should be excluded from command installation
* @param {string} fileName - File name without extension
* @returns {boolean} True if file should be excluded
*/
export function shouldExcludeFile(fileName) {
// Handle invalid inputs
if (typeof fileName !== 'string' || !fileName) {
return false;
}

// Simple case-insensitive check
const normalizedName = fileName.toLowerCase();
return DEFAULT_EXCLUDED_FILES.includes(normalizedName);
}

export function parseRepositoryPath(repoPath) {
const parts = repoPath.split('/');

Expand Down Expand Up @@ -74,10 +96,17 @@ export async function findMarkdownFiles(user, repo, basePath = '', branch = 'mai

for (const item of contents) {
if (item.type === 'file' && item.name.endsWith('.md')) {
const fileName = item.name.replace('.md', '');

// Skip documentation files
if (shouldExcludeFile(fileName)) {
continue;
}

const relativePath = basePath ? `${basePath}/${item.name}` : item.name;
files.push({
path: relativePath,
name: item.name.replace('.md', ''),
name: fileName,
fullPath: item.path
});
} else if (item.type === 'dir') {
Expand Down
21 changes: 20 additions & 1 deletion tests/utils/github-simple.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, test, expect } from 'vitest';
import { parseRepositoryPath } from '../../src/utils/github.js';
import { parseRepositoryPath, shouldExcludeFile } from '../../src/utils/github.js';

describe('GitHub Utils - Simple Tests', () => {
describe('parseRepositoryPath', () => {
Expand Down Expand Up @@ -35,4 +35,23 @@ describe('GitHub Utils - Simple Tests', () => {
expect(() => parseRepositoryPath('')).toThrow('Invalid repository path format. Expected user/repo or user/repo/command');
});
});

describe('shouldExcludeFile', () => {
test('should exclude README and CLAUDE files', () => {
expect(shouldExcludeFile('README')).toBe(true);
expect(shouldExcludeFile('readme')).toBe(true);
expect(shouldExcludeFile('CLAUDE')).toBe(true);
expect(shouldExcludeFile('claude')).toBe(true);
});

test('should not exclude command files', () => {
expect(shouldExcludeFile('NOT_TO_INCLUDE_FILE')).toBe(false);
});

test('should handle invalid input', () => {
expect(shouldExcludeFile('')).toBe(false);
expect(shouldExcludeFile(null)).toBe(false);
expect(shouldExcludeFile(undefined)).toBe(false);
});
});
});