feat(hooks): add git hooks management CLI
This commit is contained in:
24 files changed
+1221
-531
No files matched your search
@@ -1,47 +1,49 @@
|
||||
"""
|
||||
Gitignore generator using gitignore.io API.
|
||||
"""
|
||||
|
||||
import os
|
||||
import requests
|
||||
from typing import List, Dict
|
||||
|
||||
|
||||
class GitignoreGenerator:
|
||||
"""Gitignore generator using gitignore.io API."""
|
||||
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize gitignore generator."""
|
||||
self.api_url = "https://www.toptal.com/developers/gitignore/api"
|
||||
|
||||
|
||||
def generate_gitignore(self, types: List[str]) -> str:
|
||||
"""Generate .gitignore content for specified types.
|
||||
|
||||
|
||||
Args:
|
||||
types: List of project types
|
||||
|
||||
|
||||
Returns:
|
||||
Generated .gitignore content
|
||||
"""
|
||||
if not types:
|
||||
return self._get_generic_gitignore()
|
||||
|
||||
|
||||
try:
|
||||
# Get gitignore content from API
|
||||
response = requests.get(f"{self.api_url}/{','.join(types)}")
|
||||
response.raise_for_status()
|
||||
|
||||
|
||||
# Add header
|
||||
header = "# Generated by devtools gitignore generator\n"
|
||||
header += f"# Types: {', '.join(types)}\n\n"
|
||||
|
||||
|
||||
return header + response.text
|
||||
|
||||
|
||||
except requests.RequestException:
|
||||
# Fallback to generic gitignore if API fails
|
||||
return self._get_generic_gitignore()
|
||||
|
||||
|
||||
def _get_generic_gitignore(self) -> str:
|
||||
"""Get a generic .gitignore template.
|
||||
|
||||
|
||||
Returns:
|
||||
Generic .gitignore content
|
||||
"""
|
||||
@@ -91,16 +93,16 @@ logs/
|
||||
*.temp
|
||||
*.bak
|
||||
"""
|
||||
|
||||
|
||||
def update_gitignore_file(self, types: List[str], output_file: str) -> None:
|
||||
"""Generate and update a .gitignore file.
|
||||
|
||||
|
||||
Args:
|
||||
types: List of project types
|
||||
output_file: Path to the .gitignore file
|
||||
"""
|
||||
content = self.generate_gitignore(types)
|
||||
|
||||
|
||||
# Write to file
|
||||
with open(output_file, "w") as f:
|
||||
f.write(content)
|
||||
f.write(content)
|
||||
Reference in new issue
Block a user