This webhook automatically clones any git repository and updates the "lifehub" val with its contents whenever accessed via HTTP. Uses isomorphic-git for pure JavaScript git operations.
-
Set the environment variable
repoto any Git repository URL (HTTPS format):repo=https://github.com/username/repository-name repo=https://gitlab.com/username/repository-name repo=https://git.sr.ht/~username/repository-name repo=https://your-git-server.com/username/repository-name -
The webhook is automatically triggered when this val receives an HTTP request.
- ✅ GitHub - Full API support (all files, recursive directories)
- ✅ GitLab - Full API support (all files, recursive directories)
- ⚠️ SourceHut - Limited support (common files only, no API)
- ⚠️ Self-hosted Git - Limited support (common files only)
- ⚠️ Other Git hosts - Limited support (common files only)
Full Support: Uses official APIs to recursively fetch all files from the repository.
Limited Support: Attempts to fetch common files (README, LICENSE, package.json, etc.) using standard URL patterns. May not capture all repository content.
- Repository Parsing: Automatically detects the Git hosting service from the URL
- Content Fetching:
- GitHub/GitLab: Uses official APIs for complete repository access
- SourceHut/Others: Attempts to fetch common files using standard URL patterns
- File Processing: Processes all successfully fetched text files
- Content Filtering: Automatically skips binary files and .git directory
- Lifehub Generation: Creates a comprehensive val containing all repository content
{ "success": true, "message": "Successfully updated lifehub val with X files from repository-name", "files": ["file1.js", "file2.md", ...], "repository": "https://github.com/username/repository-name.git" }
{ "error": "Failed to clone repository", "details": "Detailed error message", "repository": "https://github.com/username/repository-name.git" }
The generated lifehub val includes:
- File Access: Get specific files via
?file=filenamequery parameter - File Listing: GET request without parameters returns all files and metadata
- Helper Functions:
getFile(filename): Get content of a specific filelistFiles(): Get array of all file namessearchFiles(pattern): Search files by regex patterngetFilesByExtension(ext): Get files by extension
# Regular webhook (uses 'repo' environment variable) curl https://your-val-url.web.val.run # Test with sample repository curl https://your-val-url.web.val.run/test
# Get file list and metadata curl https://lifehub-val-url.web.val.run # Get specific file curl https://lifehub-val-url.web.val.run?file=README_md
import { getFile, listFiles, searchFiles, getFilesByExtension } from "./lifehub";
// Get a specific file
const readme = getFile("README.md");
// List all files
const allFiles = listFiles();
// Search for files
const jsFiles = searchFiles("\\.js$");
// Get files by extension
const markdownFiles = getFilesByExtension("md");
- Universal Git Support: Works with any Git repository accessible via HTTPS
- Smart Service Detection: Automatically detects GitHub, GitLab, SourceHut, and generic Git hosts
- API-First Approach: Uses official APIs when available for complete repository access
- Fallback Strategy: Attempts to fetch common files when APIs aren't available
- Binary File Filtering: Automatically skips binary files
- Text File Processing: Processes all text-based files
- Comprehensive API: Rich set of helper functions for accessing content
- Error Handling: Graceful handling of different repository types and access issues
- SourceHut/Generic Git: Limited to common files due to lack of public APIs
- Private Repositories: Requires authentication (see Authentication section)
- Binary Files: Automatically skipped for security and performance
- Large Repositories: GitHub/GitLab APIs may have rate limits
- File Names: Sanitized for Val Town compatibility
For private repositories, you can add authentication by setting environment variables:
# Set in Val Town environment GITHUB_TOKEN=your_github_personal_access_token
# Set in Val Town environment GITLAB_TOKEN=your_gitlab_access_token
The webhook will automatically use these tokens when accessing private repositories.
repo: Git repository URL in HTTPS format (required)GITHUB_TOKEN: GitHub personal access token for private repositories (optional)GITLAB_TOKEN: GitLab access token for private repositories (optional)
- Generated vals are set to "unlisted" privacy by default
- No authentication required for webhook trigger (add if needed)
- Repository must be accessible via the provided URL
- Binary files are automatically filtered out for security
- Tokens are only used for authentication, never logged or exposed
- GitHub/GitLab: Uses efficient API calls with recursive directory fetching
- SourceHut/Generic: Limited to common files to avoid excessive requests
- Memory Efficient: Processes files individually to reduce memory usage
- Rate Limit Aware: Handles API rate limits gracefully
- Suitable for: Repositories up to several hundred files (with full API support)