A tool for checking whether commit messages in Azure DevOps (TFS) Pull Requests comply with standards, especially suitable for PRs using squash commit method.
- Connect to Azure DevOps (TFS) services
- Retrieve detailed information about specific PRs
- Check if PR titles conform to commit message standards
- Support custom commit message validation with regex patterns
- Automatically detect the PR of the current branch without manual PR ID specification
- .NET 8.0
- Azure DevOps API
- System.CommandLine (command-line parsing)
Clone the repository
Build the project
cd Azure-Commitlog-Check dotnet build
Run the check (two options):
a. With auto-detection (recommended):
dotnet run -- --url "https://dev.azure.com/yourorganization" --token "your-pat-token" --project "your-project" --auto-detect
b. With manual PR ID:
dotnet run -- --url "https://dev.azure.com/yourorganization" --token "your-pat-token" --project "your-project" --pr-id 12345
Parameter | Description | Required |
---|---|---|
--url | Azure DevOps server URL | Yes |
--token | Personal Access Token (PAT) | Yes |
--project | Azure DevOps project name | Yes |
--pr-id | Pull Request ID (optional if --auto-detect used) | No |
--repository | Repository name (for auto-detection) | No |
--auto-detect | Auto-detect PR of current branch | No |
--pattern | Regex pattern for validation | No |
--quiet | Only output final result | No |
The tool uses the following regex pattern by default:
^(feat|fix|docs|style|refactor|perf|test|chore)(\(.+\))?: .{1,50}
This pattern requires commit messages to follow this format:
- Must start with a type: feat, fix, docs, style, refactor, perf, test, chore
- Optional scope in parentheses, like feat(login)
- Colon and space followed by 1-50 characters description
You can customize the regex pattern using the --pattern
parameter:
dotnet run -- --url "https://dev.azure.com/yourorganization" --token "your-pat-token" --project "your-project" --pr-id 12345 --pattern "^(feat|fix|custom)(\(.+\))?: .+"
If server auto-generated merge messages (like "Merged PR 123: Title content") don't comply with your commit standards, you can use a more permissive regex pattern:
# Allow standard format or auto-merge PR format
dotnet run -- --auto-detect --pattern "^(feat|fix|docs|style|refactor|perf|test|chore)(\(.+\))?: .+|^Merged\s+PR\s+\d+:.*"
Or exclude specific PR checks (use only in special cases):
# Skip check if PR title matches auto-merge format
if ($prTitle -match "^Merged\s+PR\s+\d+:") { exit 0 } else { azcommitcheck --auto-detect }
Code | Meaning | Typical Scenario |
---|---|---|
0 | Success | All commits meet standards |
1 | Invalid Commit Message | Commit message format is incorrect |
2 | PR Not Found | Specified PR ID doesn't exist |
3 | No Commits | PR has no commit records |
4 | API Error | Network issues/token expired |
5 | Git Not Found | Missing Git environment variables |
6 | No PR For Branch | Branch not associated with any PR |
This tool can also be used as an Azure DevOps Pipeline extension, allowing you to automatically check commit messages in your CI/CD workflows.
Install the "Azure Commitlog Check" extension from the Azure DevOps Marketplace
- Search for "Azure Commitlog Check"
- Click the "Install" button to add the extension to your organization
Grant the necessary permissions for your pipelines
- Make sure to enable the "Allow scripts to access OAuth token" option in your pipeline settings
If you want to modify or customize this extension, follow these steps:
Build the project and copy the executable to the extension task folder
# Build the project dotnet publish -c Debug -r win-x64 --self-contained false # Copy the executable to the extension task folder copy Azure-Commitlog-Check\bin\Debug\net8.0\win-x64\Azure-Commitlog-Check.exe Azure-Commitlog-Check\extension\task\
Ensure there's an extension icon in the images directory
# Create images directory if it doesn't exist mkdir -p Azure-Commitlog-Check\extension\images # Add an extension icon # Example: copy your-icon.png Azure-Commitlog-Check\extension\images\extension-icon.png
Package the extension
# Install the TFS Cross Platform Command Line Interface if you don't have it npm install -g tfx-cli # Package the extension cd Azure-Commitlog-Check\extension tfx extension create --manifest-globs vss-extension.json
Upload the generated .vsix file to the Azure DevOps Marketplace
# Example azure-pipelines.yml
trigger:
- main
- feature/*
pool:
vmImage: 'windows-latest'
steps:
- checkout: self
fetchDepth: 0 # Required for PR auto-detection to work correctly
# Make sure to enable OAuth token access for this task
- task: AzureCommitlogCheck@1
inputs:
autoDetect: true # Auto-detect PR from current branch
# repository: 'MyRepository' # Optional: specify if auto-detection has issues
pattern: '^(feat|fix|docs|style|refactor|perf|test|chore)(\(.+\))?: .{1,50}' # Optional: customize pattern
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken) # Required for API access
Input Parameter | Description | Default |
---|---|---|
autoDetect | Auto-detect PR of current branch | true |
pullRequestId | Manual PR ID (ignored if autoDetect=true) | |
repository | Repository name for auto-detection | Auto-detected from env |
pattern | Regex pattern for validation | Standard pattern |
For the task to work correctly, you need to:
- Enable "Allow scripts to access the OAuth token" in the pipeline settings
- Grant sufficient permissions to the build service account to access Pull Request information
This task is ideal for use in build validation policies. To set up:
- Go to your repository settings
- Navigate to Policies > Branch Policies
- Add a build validation policy and select your pipeline
- Configure the policy to run on PR creation/updates
This project uses Flow and automated releases through Actions:
- Continuous Integration: Automatically runs build and tests when Pull Requests are submitted to the master branch
- Automated Release: When version tags (e.g., v1.0.0) are pushed, Actions will automatically:
- Build the project
- Create release packages for Windows, Linux, and macOS
- Publish a new Release with the packaged files
This project is licensed under the MIT License