Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify that a commit message contains issue number with pre commit hook #245

Open
wants to merge 5 commits into
base: kmp
Choose a base branch
from

Conversation

VahidGarousi
Copy link
Collaborator

Changes Introduced

  1. Commit-Msg Hook:

    • Implements a commit-msg hook to validate commit messages.
    • Ensures all commit messages include an issue number in the format #123 or [ #123 ].
    • Provides clear examples of valid commit messages if validation fails, improving consistency across the team.
  2. Integration with Clean Task:

    • Automatically installs Git hooks (pre-commit, commit-msg, pre-push) during the clean task.
    • Hooks are copied from the git-hooks directory to the .git/hooks directory.
    • Ensures that hooks are always up-to-date and available without requiring manual setup.
  3. Git Hook Registration:

    • Adds the following Gradle functions to register and manage hooks:
      • configureGitHooks()
      • registerCopyPreCommitHookTask()
      • registerCopyPrePushHookTask()
      • registerCopyCommitMsgHookTask()
      • registerCopyGitHooksTask()
      • registerInstallGitHooksTask()

Usage Instructions

  1. Install Git Hooks:

    • Run the clean task to automatically install or update hooks:
      ./gradlew clean
  2. Commit-Msg Hook:

    • Ensures commit messages include an issue number (e.g., #123 or [ #123 ]).
    • Blocks commits with invalid messages.

Examples

Valid Commit Messages:

  • Fix login issue #123
  • [ #456 ] Refactor module

Invalid Commit Messages:

  • Fix login issue (No issue number).
  • Updated README 123 (Missing # prefix).

Why These Changes?

  1. Improving Traceability:

    • The commit-msg hook enforces commit message standards, making it easier to link commits to specific issues.
  2. Automating Hook Installation:

    • Integrating hook installation with the clean task reduces manual steps and ensures hooks are always up-to-date.

Directory Structure

project-root/
├── .git/
│   ├── hooks/
│       ├── pre-commit
│       ├── pre-push
│       ├── commit-msg
├── build.gradle.kts
├── git-hooks/
│   ├── pre-commit-unix.sh
│   ├── pre-commit-windows.sh
│   ├── pre-push-unix.sh
│   ├── pre-push-windows.sh
│   ├── commit-msg-unix.sh
│   ├── commit-msg-windows.sh

@VahidGarousi VahidGarousi requested a review from Kaaveh December 28, 2024 06:18
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