initial
This commit is contained in:
23 files changed
+2117
No files matched your search
@@ -0,0 +1,106 @@
|
||||
"""
|
||||
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
|
||||
"""
|
||||
return """# Generic .gitignore
|
||||
# Generated by devtools gitignore generator
|
||||
|
||||
# OS generated files
|
||||
.DS_Store
|
||||
.DS_Store?
|
||||
._*
|
||||
.Spotlight-V100
|
||||
.Trashes
|
||||
ehthumbs.db
|
||||
Thumbs.db
|
||||
|
||||
# IDE files
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# Build directories
|
||||
build/
|
||||
dist/
|
||||
out/
|
||||
target/
|
||||
|
||||
# Dependencies
|
||||
node_modules/
|
||||
venv/
|
||||
env/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
logs/
|
||||
|
||||
# Environment variables
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Temporary files
|
||||
*.tmp
|
||||
*.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)
|
||||
Reference in new issue
Block a user