14 KiB
Executable File
Smart Git Commit with Azure DevOps Integration
Create well-formatted commit: $ARGUMENTS
Repository Configuration
- Project: Program Unify
- Repository ID: e030ea00-2f85-4b19-88c3-05a864d7298d
- Repository Name: unify_2_1_dm_synapse_env_d10
- Branch Structure:
feature/* → staging → develop → main - Main Branch: main
Implementation Logic for Claude
When processing this command, Claude should:
-
Detect Repository: Check if current repo is
unify_2_1_dm_synapse_env_d10- Use
git remote -vor check current directory path - Can also use
mcp__ado__repo_get_repo_by_name_or_idto verify
- Use
-
Parse Arguments: Extract flags from
$ARGUMENTS- PR Flags:
--pr-s: Set target =staging--pr-d: Set target =develop--pr-m: Set target =main--pr(no suffix): ERROR if unify_2_1_dm_synapse_env_d10, else target =develop
- PR Flags:
-
Validate Current Branch (if PR flag provided):
- Get current branch:
git branch --show-current - For
--pr-s: Requirefeature/*branch (rejectstaging,develop,main) - For
--pr-d: Requirestagingbranch exactly - For
--pr-m: Requiredevelopbranch exactly - If validation fails: Show clear error and exit
- Get current branch:
-
Execute Commit Workflow:
- Stage changes (
git add .) - Create commit with emoji conventional format
- Run pre-commit hooks (unless
--no-verify) - Push to current branch
- Stage changes (
-
Create Pull Request (if PR flag):
- Call
mcp__ado__repo_create_pull_requestwith:repository_id: e030ea00-2f85-4b19-88c3-05a864d7298dsource_branch: Current branch from step 3target_branch: Target from step 2title: Extract from commit messagedescription: Generate with summary and test plan
- Return PR URL to user
- Call
-
Add Work Item Comments Automatically (if PR was created in step 5):
- Condition Check: Only execute if:
- A PR was created in step 5 (any
--pr-*flag was used) - PR creation was successful and returned a PR ID
- A PR was created in step 5 (any
- Get Work Items from PR:
- Use
mcp__ado__repo_get_pull_request_by_idwith:repositoryId: e030ea00-2f85-4b19-88c3-05a864d7298dpullRequestId: PR ID from step 5includeWorkItemRefs: true
- Extract work item IDs from the PR response
- If no work items found, log info message and skip to next step
- Use
- Add Comments to Each Work Item:
- For each work item ID extracted from PR:
- Use
mcp__ado__wit_get_work_itemto verify work item exists - Generate comment with:
- PR title and number
- Commit message and SHA
- File changes summary from
git diff --stat - Link to PR in Azure DevOps
- Link to commit in Azure DevOps
- IMPORTANT: Do NOT include any footer text like "Automatically added by /local-commit command" or similar attribution
- Call
mcp__ado__wit_add_work_item_commentwith:project: "Program Unify"workItemId: Current work item IDcomment: Generated comment with HTML formattingformat: "html"
- Use
- Log success/failure for each work item
- If ANY work item fails, warn but don't fail the commit
- For each work item ID extracted from PR:
- Condition Check: Only execute if:
Current Repository State
- Git status: !
git status --short - Current branch: !
git branch --show-current - Staged changes: !
git diff --cached --stat - Unstaged changes: !
git diff --stat - Recent commits: !
git log --oneline -5
What This Command Does
- Analyzes current git status and changes
- If no files staged, stages all modified files with
git add - Reviews changes with
git diff - Analyzes for multiple logical changes
- For complex changes, suggests split commits
- Creates commit with emoji conventional format
- Automatically runs pre-commit hooks (ruff lint/format, trailing whitespace, etc.)
- Pre-commit may modify files (auto-fixes)
- If files are modified, they'll be re-staged automatically
- Use
--no-verifyto skip hooks in emergencies only
- NEW: With PR flags, creates Azure DevOps pull request after push
- Uses
mcp__ado__repo_create_pull_requestto create PR - Automatically links work items if commit message contains work item IDs
- IMPORTANT Branch Flow Rules (unify_2_1_dm_synapse_env_d10 ONLY):
--pr-s: Feature branch →staging(standard feature PR)--pr-d:staging→develop(promote staging to develop)--pr-m:develop→main(promote develop to production)--pr: NOT ALLOWED - must specify-s,-d, or-mfor this repository
- For OTHER repositories:
--prcreates PR todevelopbranch (legacy behavior)
- Uses
- NEW: Automatically adds comments to linked work items after PR creation
- Retrieves work items linked to the PR using
mcp__ado__repo_get_pull_request_by_id - Automatically adds comment to each linked work item with:
- PR title and number
- Commit message and SHA
- Summary of file changes
- Direct link to PR in Azure DevOps
- Direct link to commit in Azure DevOps
- IMPORTANT: No footer attribution text (e.g., "Automatically added by /local-commit command")
- Validates work items exist before commenting
- Continues even if some work items fail (warns only)
- Retrieves work items linked to the PR using
Commit Message Format
Type + Emoji Mapping
- ✨
feat: New feature - 🐛
fix: Bug fix - 📝
docs: Documentation - 💄
style: Formatting/style - ♻️
refactor: Code refactoring - ⚡️
perf: Performance improvements - ✅
test: Tests - 🔧
chore: Tooling, configuration - 🚀
ci: CI/CD improvements - ⏪️
revert: Reverting changes - 🚨
fix: Compiler/linter warnings - 🔒️
fix: Security issues - 🩹
fix: Simple non-critical fix - 🚑️
fix: Critical hotfix - 🎨
style: Code structure/format - 🔥
fix: Remove code/files - 📦️
chore: Dependencies - 🌱
chore: Seed files - 🧑💻
chore: Developer experience - 🏷️
feat: Types - 💬
feat: Text/literals - 🌐
feat: i18n/l10n - 💡
feat: Business logic - 📱
feat: Responsive design - 🚸
feat: UX improvements - ♿️
feat: Accessibility - 🗃️
db: Database changes - 🚩
feat: Feature flags - ⚰️
refactor: Remove dead code - 🦺
feat: Validation
Commit Strategy
Single Commit (Default)
git add .
git commit -m "✨ feat: implement user auth"
Multiple Commits (Complex Changes)
# Stage and commit separately
git add src/auth.py
git commit -m "✨ feat: add authentication module"
git add tests/test_auth.py
git commit -m "✅ test: add auth unit tests"
git add docs/auth.md
git commit -m "📝 docs: document auth API"
# Push all commits
git push
Pre-Commit Hooks
Your project uses pre-commit with:
- Ruff: Linting with auto-fix + formatting
- Standard hooks: Trailing whitespace, AST check, YAML/JSON/TOML validation
- Security: Private key detection
- Quality: Debug statement detection, merge conflict check
Important: Pre-commit hooks will auto-fix issues and may modify your files. The commit process will:
- Run pre-commit hooks
- If hooks modify files, automatically re-stage them
- Complete the commit with all fixes applied
Command Options
--no-verify: Skip pre-commit checks (emergency use only)--amend: Amend previous commit--pr-s: Create PR tostagingbranch (feature → staging)--pr-d: Create PR todevelopbranch (staging → develop)--pr-m: Create PR tomainbranch (develop → main)--pr: Legacy flag for other repositories (creates PR todevelop)- NOT ALLOWED in unify_2_1_dm_synapse_env_d10 - must use
-s,-d, or-m
- NOT ALLOWED in unify_2_1_dm_synapse_env_d10 - must use
- Default: Run all pre-commit hooks and create new commit
- Automatic Work Item Comments: When using any PR flag, work items linked to the PR will automatically receive comments with commit details (no footer attribution)
Azure DevOps Integration Features
Pull Request Workflow (PR Flags)
When using PR flags, the command will:
- Commit changes locally
- Push to remote branch
- Validate repository and branch configuration:
- THIS repo (unify_2_1_dm_synapse_env_d10): Requires explicit flag (
--pr-s,--pr-d, or--pr-m)--pr-s: Current feature branch →staging--pr-d: Must be onstagingbranch →develop--pr-m: Must be ondevelopbranch →main--pralone: ERROR - must specify target
- OTHER repos:
--prcreates PR todevelop(all other flags ignored)
- THIS repo (unify_2_1_dm_synapse_env_d10): Requires explicit flag (
- Use
mcp__ado__repo_create_pull_requestto create PR with:- Title: Extracted from commit message
- Description: Full commit details with summary and test plan
- Source Branch: Current branch
- Target Branch: Determined by flag and repository
- Work Items: Auto-linked from commit message (e.g., "fixes #12345")
Viewing Commit History
You can view commit history using:
mcp__ado__repo_search_commits- Search commits by branch, author, date range- Traditional
git log- For local history
Branch Management
mcp__ado__repo_list_branches_by_repo- View all Azure DevOps branchesgit branch- View local branches
Branch Validation Rules (unify_2_1_dm_synapse_env_d10)
Before creating a PR, the command validates:
--pr-s (Feature → Staging)
- ✅ ALLOWED: Any
feature/*branch - ❌ BLOCKED:
staging,develop,mainbranches - Target:
staging
--pr-d (Staging → Develop)
- ✅ ALLOWED: Only
stagingbranch - ❌ BLOCKED: All other branches (including
feature/*) - Target:
develop
--pr-m (Develop → Main)
- ✅ ALLOWED: Only
developbranch - ❌ BLOCKED: All other branches (including
staging,feature/*) - Target:
main
--pr (Legacy - NOT ALLOWED)
- ❌ BLOCKED: All branches in unify_2_1_dm_synapse_env_d10
- 💡 Error Message: "Must use --pr-s, --pr-d, or --pr-m for this repository"
- ✅ ALLOWED: All other repositories (targets
develop)
Best Practices
- Let pre-commit work - Don't use
--no-verifyunless absolutely necessary - Atomic commits - One logical change per commit
- Descriptive messages - Emoji + type + clear description
- Review before commit - Always check
git diff - Clean history - Split complex changes into multiple commits
- Trust the hooks - They maintain code quality automatically
- Use correct PR flag -
--pr-sfor features,--pr-dfor staging promotion,--pr-mfor production - Link work items - Reference Azure DevOps work items in commit messages (e.g., "#43815") to enable automatic PR linking
- Validate branch - Ensure you're on the correct branch before using
--pr-dor--pr-m - Work item linking - Work items linked to PRs will automatically receive comments with commit details
- Keep stakeholders informed - Use PR flags to ensure work items are automatically updated with progress
Example Workflows
Simple Commit
/commit "fix: resolve enum import error"
Commit with Work Item
/commit "feat: add enum imports for Synapse environment"
Commit and Create PR (Feature to Staging)
/commit --pr-s "feat: refactor commit command with ADO MCP integration"
This will:
- Create commit locally
- Push to current branch
- Create PR:
feature/xyz → staging - Link work items automatically if mentioned in commit message
Promote Staging to Develop
# First checkout staging branch
git checkout staging
git pull origin staging
# Then commit and create PR
/commit --pr-d "release: promote staging changes to develop"
This will:
- Create commit on
stagingbranch - Push to
staging - Create PR:
staging → develop
Promote Develop to Main (Production)
# First checkout develop branch
git checkout develop
git pull origin develop
# Then commit and create PR
/commit --pr-m "release: promote develop to production"
This will:
- Create commit on
developbranch - Push to
develop - Create PR:
develop → main
Error: Using --pr without suffix
/commit --pr "feat: some feature"
Result: ERROR - unify_2_1_dm_synapse_env_d10 requires explicit PR target (--pr-s, --pr-d, or --pr-m)
Feature PR with Automatic Work Item Comments
# On feature/xyz branch
/commit --pr-s "feat(user-auth): implement OAuth2 authentication #12345"
This will:
- Create commit on feature branch
- Push to feature branch
- Create PR:
feature/xyz → staging - Link work item #12345 to the PR
- Automatically add comment to work item #12345 with:
- PR title and number
- Commit message and SHA
- File changes summary
- Link to PR in Azure DevOps
- Link to commit in Azure DevOps
- (No footer attribution text)
Staging to Develop PR with Multiple Work Items
# On staging branch
/commit --pr-d "release: promote staging to develop - fixes #12345, #67890"
This will:
- Create commit on
stagingbranch - Push to
staging - Create PR:
staging → develop - Link work items #12345 and #67890 to the PR
- Automatically add comments to both work items with PR and commit details (without footer attribution)
Note: Work items are automatically detected from commit message and linked to PR. Comments are added automatically to all linked work items without any footer text.