diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS deleted file mode 100644 index 16be10c..0000000 --- a/.github/CODEOWNERS +++ /dev/null @@ -1,12 +0,0 @@ -# CODEOWNERS file indicates code owners for certain files -# -# Code owners will automatically be added as a reviewer for PRs that touch -# the owned files. -# - -# Default owners for everything in the repo -# -# Unless a later match takes precedence, these owners will be requested for -# review when someone opens a pull request. - -* @Excoriate diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index ffb6ed8..0000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,93 +0,0 @@ ---- -name: 🐞 Bug Report -about: Create a detailed bug report to help improve the MCP Server -title: "bug: " -labels: ["bug"] -assignees: ["Excoriate"] # Adjust if needed ---- - -## 🔍 Bug Description - -> [!WARNING] -> Provide a clear and concise description of the bug you encountered with the -> MCP server. - -### Expected Behavior - -> [!NOTE] -> Describe what you expected to happen: -> -> - What was the intended outcome when interacting with the server? -> - How should the server have responded or behaved? - -### Actual Behavior - -> [!IMPORTANT] -> Describe what actually happened: -> -> - What went wrong? -> - What unexpected results, errors, or responses did you observe? - -## 🔬 Steps to Reproduce - -> [!TIP] -> Provide detailed steps to reproduce the bug: - -1. Start the server using `deno task dev` or relevant command... -2. Connect using MCP client '....' (e.g., Claude Desktop, MCP Inspector) -3. Send request / Perform action '....' -4. Observe the error/unexpected behavior '....' - -### Minimal Reproducible Example - -> [!WARNING] -> If applicable, include a minimal code snippet (TypeScript) or configuration -> that demonstrates the issue: - -```typescript -// Your minimal reproducible TypeScript code snippet (if applicable) -// or relevant configuration details -``` - -## 🌍 Environment Details - -> [!IMPORTANT] -> Provide context about your environment: - -- **Deno Version**: (e.g., `deno --version`) -- **MCP SDK Version**: (from `deno.lock` or `deno.json`, e.g., - `npm:@modelcontextprotocol/sdk@1.8.0`) -- **Operating System**: (e.g., macOS Sonoma 14.1, Windows 11, Ubuntu 22.04) -- **MCP Client Used**: (e.g., Claude Desktop vX.Y.Z, MCP Inspector, Custom - Client) -- **Relevant `deno.json` / `deno.lock` sections**: (if applicable) - -## 📋 Diagnostic Information - -> [!TIP] -> Include any relevant diagnostic information: - -- Full error messages from the server console -- Full error messages or unexpected responses from the MCP client -- Screenshots of the error or unexpected behavior -- Relevant logs (please ensure no sensitive data is included) - -## 🖼️ Additional Context - -> [!NOTE] -> Add any other context about the problem: -> -> - When did you first notice this issue? -> - Does it happen consistently or intermittently? -> - Any recent changes (e.g., dependency updates, code changes) that might have -> introduced the bug? - -### Checklist - -- [ ] I've checked existing issues for duplicates -- [ ] I've provided a clear description of the bug -- [ ] I've included steps to reproduce -- [ ] I've shared relevant environment details -- [ ] I've added diagnostic information (if applicable) - -**Thank you for helping improve the `mcp-terragrunt-docs` server!** 🐛 diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 244e455..0000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,62 +0,0 @@ ---- -name: 🚀 Feature Request -about: Suggest an idea to improve the mcp-terragrunt-docs server -title: "feat: " -labels: ["feature"] # Changed from enhancement to match settings.yml -assignees: ["Excoriate"] # Adjust if needed ---- - -## 🌟 Feature Description - -> [!TIP] -> Provide a clear and concise description of the feature you're proposing for -> the MCP server. - -### Problem Statement - -> [!NOTE] -> Is your feature request related to a problem? Describe the pain point. -> -> Example: "I'm always frustrated when I cannot get X context from the -> server..." - -### Proposed Solution - -> [!IMPORTANT] -> Describe the solution you'd like to see implemented. -> -> - What specific functionality are you suggesting? -> - How would this improve the server or its interactions? - -## 🎯 Use Case and Value - -> [!TIP] -> Explain the specific use case and the value this feature would bring: - -- How would this feature be used? -- What benefits would it provide (e.g., better context, new capabilities, - improved developer experience)? - -## 🔍 Alternatives Considered - -> [!NOTE] -> Have you explored alternative solutions or workarounds? -> -> - Describe other approaches you've considered -> - Why weren't they sufficient? - -## 🖼️ Additional Context - -> [!TIP] -> Add any other context, screenshots, examples, or references that might help -> explain the feature request. - -### Checklist - -- [ ] I've checked that a similar feature doesn't already exist in open/closed - issues -- [ ] I've provided a clear problem statement (if applicable) -- [ ] I've described the proposed solution -- [ ] I've explained the use case and value - -**Thank you for helping improve the `mcp-terragrunt-docs` server!** 🎉 diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ceb521c..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,33 +0,0 @@ -## 🎯 What - -Provide a concise description of the changes: - -- ❓ What changes have you made? (High-level overview) -- 🎉 What does it mean to the user? (In plain English) - -Example: - -- 🚀 Added new MCP tool `get_terragrunt_config`. -- 🎉 This allows clients to request specific Terragrunt configuration details - via the MCP server. - -## 🤔 Why - -Explain why the changes are necessary: - -- 💡 Why were these changes made? -- 🎯 What's the benefit? - -Example: - -- 💡 This tool was added to provide necessary context for an AI agent analyzing - Terragrunt setups. -- 🎯 This enables more accurate and context-aware interactions related to - Terragrunt documentation and state. - -## 📚 References - -Link any supporting context or documentation: - -- 🔗 Github issues, documentation, helpful links. -- ✅ Use `closes #123`, if this PR closes a GitHub issue `#123` diff --git a/.github/auto-comment.yml b/.github/auto-comment.yml deleted file mode 100644 index f0933c1..0000000 --- a/.github/auto-comment.yml +++ /dev/null @@ -1,18 +0,0 @@ ---- -pullRequestOpened: | - :wave: Thanks for creating a PR! - - Before we can merge this PR, please make sure that all the following items have been - checked off. If any of the checklist items are not applicable, please leave them but - write a little note why. - - - [ ] Wrote tests - - [ ] Check the CONTRIBUTING guide for other ways to contribute - - [ ] Linked to Github issue with discussion and accepted design OR link to spec that - describes this work. - - [ ] Updated relevant documentation (`docs/`) and code comments - - [ ] Re-reviewed `Files changed` in the Github PR explorer - - [ ] Applied Appropriate Labels - - - Thank you for your contribution! :rocket: diff --git a/.github/config.yml b/.github/config.yml deleted file mode 100644 index caae853..0000000 --- a/.github/config.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -# Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome -# Comment to be posted to on first time issues -newIssueWelcomeComment: > - Thanks for opening your first issue here! 👍 Be sure to follow the issue template. #magic___^_^___line -# Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome -# Comment to be posted to on PRs from first time contributors in your repository -newPRWelcomeComment: > - Thanks for opening this pull request! 👍 Please check out our contributing guidelines. #magic___^_^___line -# Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge -# Comment to be posted to on pull requests merged by a first time user -firstPRMergeComment: > - Congrats on merging your first pull request! 🎉 We here at `mcp-terragrunt-docs` are proud of you. diff --git a/.github/labeler.yml b/.github/labeler.yml deleted file mode 100644 index bc54947..0000000 --- a/.github/labeler.yml +++ /dev/null @@ -1,32 +0,0 @@ -# .github/labeler.yml - Config for actions/labeler action -# Defines labels based on files modified in a PR - -# Label for CI/CD changes -ci/cd: - - .github/workflows/* - -# Label for documentation changes -documentation: - - README.md - - docs/**/*.md # Updated path for all docs - - "*.md" # Root level markdown files - -# Label for source code changes -source: - - main.ts - - "**/*.ts" # All TypeScript files - -# Label for configuration changes / patches -patch: - - LICENSE - - justfile # Added - - deno.json # Added - - deno.lock # Added - - .github/labeler.yml - - .github/settings.yml - - .github/dependabot.yml # Keep if dependabot is used - - .github/ISSUE_TEMPLATE/* # Added - - .github/CODEOWNERS # Added - - .github/*.yml # Other root .github YAML configs - - .gitignore - - .gitattributes diff --git a/.github/no-response.yml b/.github/no-response.yml deleted file mode 100644 index 36183b6..0000000 --- a/.github/no-response.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -# Configuration for probot-no-response - https://github.com/probot/no-response - -# Number of days of inactivity before an Issue is closed for lack of response -daysUntilClose: 30 -# Label requiring a response -responseRequiredLabel: more-information-needed -# Comment to post when closing an Issue for lack of response. Set to `false` to disable -closeComment: >- - This issue has been automatically closed because there has been no response to our request for more information from the - original author. With only the information that is currently in the issue, we don't have enough information to take action. - Please feel free to reach out if you have or find the answers we need so that we can investigate further. Thank you! diff --git a/.github/settings.yml b/.github/settings.yml deleted file mode 100644 index 97920b1..0000000 --- a/.github/settings.yml +++ /dev/null @@ -1,102 +0,0 @@ -# Repository settings are managed by the settings app (https://github.com/apps/settings) -# Documentation: https://github.com/repository-settings/app#configuration ---- -repository: - # Updated repository name - name: mcp-terragrunt-docs - # Updated repository description - description: Deno/TypeScript MCP Server providing context related to Terragrunt documentation. - - # This is not a template repository - is_template: false - - # Updated topics relevant to this project - topics: - - mcp - - typescript - - deno - - terragrunt - - documentation - - language-server # Assuming it might act like one - - # Merge Strategy (Kept defaults from original) - default_branch: main - allow_squash_merge: true - allow_merge_commit: false - allow_rebase_merge: true - delete_branch_on_merge: true - - # Repository Features (Kept defaults from original) - has_projects: true - has_wiki: false - has_discussions: true - - # Security Enhancements (Kept defaults from original) - enable_vulnerability_alerts: true - enable_automated_security_fixes: true - - # Team Access (Kept defaults - ADJUST IF NEEDED) - teams: - - name: maintainers - permission: admin - - name: contributors - permission: push - # - name: template-users # Removed template-specific team - # permission: pull - -# Updated Label Strategy (Removed template labels, added project-specific) -labels: - - name: bug - color: "#CC0000" - description: Something is not working fine 🐛 - - name: feature - color: "#336699" - description: New functionality or enhancement 🚀 - - name: documentation - color: "#0075ca" - description: Improvements or additions to documentation 📚 - - name: help-wanted - color: "#008672" - description: Community contributions welcome 🤝 - - name: mcp - color: "#5DADE2" # Example color - description: Related to the Model Context Protocol - - name: typescript - color: "#3178C6" # Official TS color - description: Related to TypeScript code - - name: deno - color: "#000000" # Deno logo color - description: Related to the Deno runtime or configuration - # Add other relevant labels as needed, e.g., 'terragrunt', 'refactor', 'testing' - -# Branch Protection (Updated status checks - PLACEHOLDERS, ADJUST TO ACTUAL CI JOB NAMES) -branches: - - name: main - protection: - required_pull_request_reviews: - required_approving_review_count: 1 - dismiss_stale_reviews: true - require_code_owner_reviews: true # Requires CODEOWNERS file - dismissal_restrictions: {} - # code_owner_approval: true # Note: require_code_owner_reviews implies this - required_conversation_resolution: true - - required_status_checks: - strict: true # Require branches to be up to date before merging - contexts: # ADJUST THESE TO MATCH YOUR ACTUAL GITHUB ACTIONS JOB NAMES - - "Lint" - - "Test" - # - "Format Check" # Often done locally or via pre-commit, but can be added - # Add other required checks like build steps if applicable - - enforce_admins: false # Admins are not exempt from protection rules - required_linear_history: true # Enforce linear history - restrictions: # Restrict who can push to main (ADJUST AS NEEDED) - users: [Excoriate] - teams: [maintainers] - -# Removed Template-Specific Repository Metadata -# repository_config: -# template_generation_date: 2024-01-15 -# template_version: "1.0.0" -# recommended_terraform_version: ">= 1.5.0" diff --git a/.github/stale.yml b/.github/stale.yml deleted file mode 100644 index 5ff37ba..0000000 --- a/.github/stale.yml +++ /dev/null @@ -1,19 +0,0 @@ ---- -# Number of days of inactivity before an issue becomes stale -daysUntilStale: 10 -# Number of days of inactivity before a stale issue is closed -daysUntilClose: 3 -# Issues with these labels will never be considered stale -exemptLabels: - - pinned - - security -# Label to use when marking an issue as stale -staleLabel: wontfix -# Comment to post when marking an issue as stale. Set to `false` to disable -markComment: > - 👋 Hello. Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? #magic___^_^___line - > This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further - activity occurs. #magic___^_^___line Thank you for your contributions. #magic___^_^___line -# Comment to post when closing a stale Issue or Pull Request. Set to `false` to disable -closeComment: > - ⚡️ This issue has been automatically closed because it has not had recent activity. diff --git a/.github/workflows/issue-comment-created.yml b/.github/workflows/issue-comment-created.yml deleted file mode 100644 index 31a6345..0000000 --- a/.github/workflows/issue-comment-created.yml +++ /dev/null @@ -1,47 +0,0 @@ ---- -name: Remove outdated labels -on: - pull_request_target: - types: - - closed - issues: - types: - - closed -jobs: - remove-merged-pr-labels: - name: Remove merged pull request labels - if: github.event.pull_request.merged - runs-on: ubuntu-latest - steps: - - uses: mondeja/remove-labels-gh-action@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - labels: | - awaiting reply - changes requested - duplicate - in discussion - invalid - out of scope - pending - won't add - remove-closed-pr-labels: - name: Remove closed pull request labels - if: github.event_name == 'pull_request_target' && (! github.event.pull_request.merged) - runs-on: ubuntu-latest - steps: - - uses: mondeja/remove-labels-gh-action@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - labels: in discussion - remove-closed-issue-labels: - name: Remove closed issue labels - if: github.event.issue.state == 'closed' - runs-on: ubuntu-latest - steps: - - uses: mondeja/remove-labels-gh-action@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - labels: | - in discussion - pending diff --git a/.github/workflows/jsr-publish.yml b/.github/workflows/jsr-publish.yml deleted file mode 100644 index 8de8421..0000000 --- a/.github/workflows/jsr-publish.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: Publish -on: - push: - branches: - - main - - master - -jobs: - publish: - runs-on: ubuntu-latest - - permissions: - contents: read - id-token: write - - steps: - - uses: actions/checkout@v4 - - - name: Publish package - run: npx jsr publish diff --git a/.github/workflows/labels-assigner.yml b/.github/workflows/labels-assigner.yml deleted file mode 100644 index cac61f9..0000000 --- a/.github/workflows/labels-assigner.yml +++ /dev/null @@ -1,34 +0,0 @@ ---- -name: Assign labels on PR -on: - pull_request: - types: [opened, labeled, unlabeled, synchronize] -defaults: - run: - shell: bash -permissions: - contents: write - pull-requests: write -jobs: - triage: - runs-on: ubuntu-latest - steps: - - uses: actions/labeler@v3 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - size-label: - runs-on: ubuntu-latest - steps: - - name: size-label - uses: pascalgn/size-label-action@v0.4.3 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - sizes: > - { - "0": "XS", - "15": "S", - "30": "M", - "50": "L", - "250": "Too Large" - } diff --git a/.github/workflows/lock-threads.yml b/.github/workflows/lock-threads.yml deleted file mode 100644 index 652424b..0000000 --- a/.github/workflows/lock-threads.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -name: Lock Threads -on: - schedule: - - cron: 50 1 * * * -jobs: - lock: - runs-on: ubuntu-latest - steps: - - uses: dessant/lock-threads@v4 - with: - github-token: ${{ github.token }} - issue-lock-comment: > - I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus - on the active issues. #magic___^_^___line If you have found a problem that seems similar to this, please open - a new issue and complete the issue template so we can capture all the details necessary to investigate further. - - issue-lock-inactive-days: "30" - pr-lock-comment: > - I'm going to lock this pull request because it has been closed for _30 days_ ⏳. This helps our maintainers find - and focus on the active contributions. #magic___^_^___line If you have found a problem that seems related to this - change, please open a new issue and complete the issue template so we can capture all the details necessary to - investigate further. #magic___^_^___line - pr-lock-inactive-days: "30" diff --git a/.github/workflows/stale-actions.yaml b/.github/workflows/stale-actions.yaml deleted file mode 100644 index 1fdc743..0000000 --- a/.github/workflows/stale-actions.yaml +++ /dev/null @@ -1,33 +0,0 @@ ---- -name: "Mark or close stale issues and PRs" -on: - schedule: - - cron: "0 0 * * *" - -jobs: - stale: - runs-on: ubuntu-latest - steps: - - uses: actions/stale@v9 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - # Staling issues and PR's - days-before-stale: 30 - stale-issue-label: wontfix # Use label consistent with .github/stale.yml - stale-pr-label: wontfix # Use label consistent with .github/stale.yml - stale-issue-message: | - This issue has been automatically marked as stale because it has been open 30 days - with no activity. Remove stale label or comment or this issue will be closed in 10 days - stale-pr-message: | - This PR has been automatically marked as stale because it has been open 30 days - with no activity. Remove stale label or comment or this PR will be closed in 10 days - # Not stale if have this labels or part of milestone - exempt-issue-labels: bug,wip,on-hold - exempt-pr-labels: bug,wip,on-hold - exempt-all-milestones: true - # Close issue operations - # Label will be automatically removed if the issues are no longer closed nor locked. - days-before-close: 10 - delete-branch: true - close-issue-message: This issue was automatically closed because of stale in 10 days - close-pr-message: This PR was automatically closed because of stale in 10 days diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 099db50..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,33 +0,0 @@ ---- -repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 # Updated rev for potentially newer hooks - hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - exclude: &readme_excludes > - (?x)^( - README\.md| - CHANGELOG\.md| - repomix-output\.xml - )$ - - id: check-yaml - - id: check-added-large-files - - id: check-merge-conflict - - id: check-executables-have-shebangs - - id: check-shebang-scripts-are-executable - - id: check-symlinks - - id: check-json - exclude: &json_excludes > - (?x)^( - \.vscode/.*\.json| - deno\.json| - biome\.json - )$ - - id: pretty-format-json - exclude: *json_excludes - - - repo: https://github.com/gruntwork-io/pre-commit - rev: v0.1.28 # Keep existing or update if needed - hooks: - - id: shellcheck diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 9222639..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "workbench.colorCustomizations": { - "editor.lineHighlightBackground": "#0004072d", - "editor.lineHighlightBorder": "#4ac3081f", - "terminal.background": "#010d13f0", - "activityBar.background": "#292E35", - "titleBar.activeBackground": "#39404A", - "titleBar.activeForeground": "#F9FAFB" - }, - "deno.enable": true -} diff --git a/LICENSE b/LICENSE deleted file mode 100644 index c8de1c6..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2024 Excoriate - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index a48d319..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,31 +0,0 @@ -# Security Policy - -## Project Scope -This repository implements a Model Context Protocol (MCP) server in Deno/TypeScript, providing contextual information and tools for Terragrunt documentation and GitHub issues. It is intended for use by AI agents, IDE integrations, and developers working with Terragrunt. - -## Supported Versions -- Only the `main` branch is officially supported. Please report vulnerabilities found in the latest code on this branch. - -## Reporting a Vulnerability -If you discover a security vulnerability in this project, **please do not create a public GitHub issue**. Instead, follow these steps: - -1. **Preferred:** [Open a private security advisory on GitHub](https://github.com/Excoriate/mcp-terragrunt-docs/security/advisories/new) (recommended for confidential reporting). -2. **Alternative:** Email the maintainer at [security@excoriate.io] with details of the vulnerability. - -We will respond as quickly as possible and coordinate a fix and disclosure process. - -## Responsible Disclosure -- Please provide as much detail as possible to help us understand and reproduce the issue. -- We ask that you give us a reasonable amount of time to address the vulnerability before any public disclosure. -- We are committed to transparent and responsible handling of all security reports. - -## Exclusions -- This policy does not cover vulnerabilities in third-party dependencies (report those upstream). -- Do not use automated tools to perform denial-of-service or destructive testing. - -## Further Reading -- [GitHub Security Policy Documentation](https://docs.github.com/en/code-security/getting-started/adding-a-security-policy-to-your-repository) - ---- - -Thank you for helping keep this project and its users secure! diff --git a/scripts/hooks/pre-commit-init.sh b/scripts/hooks/pre-commit-init.sh deleted file mode 100755 index 71160a3..0000000 --- a/scripts/hooks/pre-commit-init.sh +++ /dev/null @@ -1,146 +0,0 @@ -#!/usr/bin/env bash -# shellcheck disable=SC2317 - -# Pre-Commit Hook Management Script -# -# This script provides functionality to manage pre-commit hooks for the repository. -# It follows Google's Bash Style Guide and provides reliable hook management. - -# Strict error handling -set -euo pipefail - -# Logging function with timestamp and color -log() { - local -r level="${1}" - local -r message="${2}" - local -r timestamp=$(date "+%Y-%m-%d %H:%M:%S") - local color="" - - case "${level}" in - INFO) color="\033[0;32m" ;; # Green - WARNING) color="\033[0;33m" ;; # Yellow - ERROR) color="\033[0;31m" ;; # Red - *) color="\033[0m" ;; # Default - esac - - # shellcheck disable=SC2059 - printf "${color}[${level}] ${timestamp}: ${message}\033[0m\n" >&2 -} - -# Ensure pre-commit is installed -ensure_pre_commit_installed() { - if ! command -v pre-commit &> /dev/null; then - log ERROR "pre-commit is not installed. Installing via pip..." - if ! pip3 install pre-commit; then - log ERROR "Failed to install pre-commit. Please install manually." - return 1 - fi - fi - log INFO "pre-commit is installed and ready." -} - -# Verify hook installation -verify_hook_installation() { - local hook_types=("pre-commit" "pre-push") - local git_dir - git_dir=$(git rev-parse --git-dir) - - for hook_type in "${hook_types[@]}"; do - if [ ! -f "${git_dir}/hooks/${hook_type}" ]; then - log ERROR "Hook ${hook_type} not installed correctly" - return 1 - fi - done - - log INFO "All Git hooks verified successfully" -} - -# Check if core.hooksPath is set (locally or globally) -check_hooks_path() { - local hooks_path_local hooks_path_global - hooks_path_local=$(git config --get core.hooksPath || true) - hooks_path_global=$(git config --global --get core.hooksPath || true) - if [[ -n "$hooks_path_local" ]] || [[ -n "$hooks_path_global" ]]; then - log ERROR "Git config 'core.hooksPath' is set (local: '$hooks_path_local', global: '$hooks_path_global')." - log ERROR "pre-commit will refuse to install hooks while this is set." - log ERROR "To proceed, unset it with: git config --unset-all core.hooksPath" - exit 1 - fi -} - -# Install pre-commit hooks -# Exposed function 1: Initialize repository hooks -pc_init() { - ensure_pre_commit_installed - - # Check for custom hooksPath before proceeding - check_hooks_path - - log INFO "Updating pre-commit hooks to the latest version..." - if ! pre-commit autoupdate; then - log WARNING "Failed to update pre-commit hooks to the latest version. Continuing with existing hooks." - fi - - log INFO "Installing pre-commit hooks..." - if ! pre-commit install; then - log ERROR "Failed to install pre-commit hooks" - return 1 - fi - - if ! pre-commit install --hook-type pre-commit; then - log ERROR "Failed to install pre-commit hooks for commit stage" - return 1 - fi - - if ! pre-commit install --hook-type pre-push; then - log ERROR "Failed to install pre-commit hooks for pre-push stage" - return 1 - fi - - # Verify hook installation - if ! verify_hook_installation; then - log ERROR "Hook verification failed. Please check your Git configuration." - return 1 - fi - - # Configure Git to always run hooks - if ! git config --global core.hooksPath .git/hooks; then - log WARNING "Could not set global hooks path. Hooks might not run automatically." - fi - - log INFO "All pre-commit hooks installed and verified successfully" -} - -# Run pre-commit hooks on all files -# Exposed function 2: Run hooks across all files -pc_run() { - log INFO "Running pre-commit hooks on all files..." - if ! pre-commit run --all-files; then - log ERROR "Pre-commit hooks failed on some files" - return 1 - fi - log INFO "Pre-commit hooks completed successfully" -} - -# Main function for script execution -main() { - local command="${1:-}" - - case "${command}" in - init) - pc_init - ;; - run) - pc_run - ;; - *) - log ERROR "Invalid command. Use 'init' or 'run'." - exit 1 - ;; - esac -} - -# Allow sourcing for function access or direct script execution -if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then - main "$@" -fi