Skip to content

feat: Add rulesync fetch command to fetch configurations from GitHub#924

Merged
dyoshikawa merged 5 commits intomainfrom
feat/add-fetch-command
Feb 4, 2026
Merged

feat: Add rulesync fetch command to fetch configurations from GitHub#924
dyoshikawa merged 5 commits intomainfrom
feat/add-fetch-command

Conversation

@dyoshikawa
Copy link
Owner

@dyoshikawa dyoshikawa commented Feb 4, 2026

Summary

  • Add new rulesync fetch command to fetch rulesync configuration files directly from GitHub repositories
  • Implement GitHub API client using @octokit/rest SDK with authentication support (CLI option, GITHUB_TOKEN, GH_TOKEN)
  • Support multiple source formats: full URL, owner/repo, owner/repo@ref, owner/repo:path
  • Feature-based filtering (rules, commands, subagents, skills, ignore, mcp, hooks)
  • Conflict resolution strategies: skip (preserve existing) and overwrite (default)
  • Dry-run mode for previewing changes before writing

Security Measures

  • HTTPS enforcement for custom base URLs to prevent token exposure
  • Path traversal protection via checkPathTraversal() for both file paths and output directory
  • File size limit (10MB max) to prevent resource exhaustion
  • Input validation for empty ref/path after delimiters
  • Proper URL encoding handled by Octokit SDK

Code Quality Improvements

  • Use official GitHub SDK (@octokit/rest) for API interactions
  • Extract MAX_FILE_SIZE constant to shared rulesync-paths.ts (eliminates duplication)
  • Add RULESYNC_MCP_FILE_NAME and RULESYNC_HOOKS_FILE_NAME constants for consistency
  • Remove unused validateRef method from GitHubClient
  • Add comprehensive documentation for fetch command in README.md

Test plan

  • Unit tests for GitHub client (authentication, API calls, error handling)
  • Unit tests for source parsing (URL formats, shorthand formats)
  • Unit tests for fetch logic (filtering, conflict resolution, file writing)
  • Unit tests for CLI command handler
  • Unit tests for security measures (path traversal, file size limits, HTTPS validation)
  • Unit tests for output directory path traversal validation
  • All 3547 tests pass
  • pnpm cicheck:code passes

🤖 Generated with Claude Code

dyoshikawa and others added 5 commits February 3, 2026 20:41
Add a new `rulesync fetch` command that allows fetching rulesync configuration
files directly from GitHub repositories. This enables teams to share and reuse
rulesync configurations across projects.

Features:
- Fetch from public and private GitHub repositories
- Support multiple source formats (URL, owner/repo, owner/repo@ref:path)
- Filter by features (rules, commands, subagents, skills, ignore, mcp, hooks)
- Conflict resolution strategies (skip, overwrite)
- Dry-run mode for previewing changes
- Authentication via --token, GITHUB_TOKEN, or GH_TOKEN

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Extract buildContentsUrl helper to eliminate code duplication (DRY)
- Add HTTPS validation for custom base URLs to prevent token exposure
- Add path traversal protection using checkPathTraversal
- Add file size limit check during fetch (10MB max)
- Add validation for empty ref/path after delimiters
- Add comprehensive tests for security measures
- Remove duplicate try-catch wrapper in CLI (handled in fetchCommand)
- Improve formatFetchSummary output format

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Extract MAX_FILE_SIZE constant to shared rulesync-paths.ts (DRY violation)
- Add path traversal validation for --output directory option (security)
- Add URL encoding for owner/repo in GitHub API calls (security)
- Remove unused validateRef method and its tests
- Add RULESYNC_MCP_FILE_NAME and RULESYNC_HOOKS_FILE_NAME constants
- Add comprehensive fetch command documentation to README.md

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace template literal string concatenation with the URL API for
safer and more maintainable URL construction. Add buildRepoUrl helper
method that uses new URL() for proper URL handling.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace manual fetch API calls with the official GitHub SDK (@octokit/rest)
for safer, more maintainable API interactions:
- Use Octokit for all GitHub API calls
- Automatic URL construction and encoding handled by SDK
- Better error handling with RequestError
- Consistent authentication management

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@dyoshikawa dyoshikawa merged commit 8c486fb into main Feb 4, 2026
10 checks passed
@dyoshikawa dyoshikawa deleted the feat/add-fetch-command branch February 4, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant