Merge Commit Message Validator for Pull Requests

This repository provides a Forge app for validating merge commit messages in Bitbucket pull requests. It ensures that pull requests targeting specific branches meet configurable standards for commit message patterns and merge strategies.
Features
Pull Request Validation:
Validates pull requests targeting specific branches (
main
,master
,boost_1.80.0
).Ensures the merge strategy is set to
squash
.Checks the merge commit message against a configurable regex pattern.
Configurable Regex:
Admins can update the regex pattern used for validating merge commit messages via a user-friendly UI.
Files Overview
src/merge-checks/index.ts
src/merge-checks/index.ts
This file contains the backend logic for validating pull requests. Key functionalities include:
Fetching Pull Request Details:
Retrieves the destination branch and checks if it's one of the allowed branches (
main
,master
,boost_1.80.0
).
Validation Logic:
Ensures the merge strategy is set to
squash
.Validates the merge commit message against a regex pattern retrieved from Forge storage.
Dynamic Configuration:
The regex pattern for commit messages is fetched from Forge storage, allowing it to be updated without code changes.
Error and Success Handling:
Logs and returns appropriate responses based on validation results.
frontend/TitleSubstringForm.tsx
frontend/TitleSubstringForm.tsx
This file provides the frontend interface for configuring the regex pattern. It is built using Atlassian's UI Kit 2.
Key Features:
A form to set the merge commit message regex pattern.
Validates user input to ensure the field is not empty.
Displays success messages when changes are applied.
Automatically saves the regex pattern to Forge storage via an
invoke
resolver.
Installation and Setup
Clone the repository:
git clone <repository-url> cd <repository-name>
Install Dependencies: Make sure you have the Forge CLI installed. Then install dependencies:
npm install
Deploy the Forge App: Deploy the app to your Atlassian account.
forge deploy forge install
Run the App: To test the app locally, use:
forge tunnel
Usage
1. Setting Up Commit Message Regex
Navigate to the app's configuration UI to set a custom regex for validating merge commit messages. For example:
Regex:
^JIRA-\d+: .*
Ensures commit messages start with a JIRA ticket ID.
2. Merge Request Validation
When a pull request is created or updated, the app validates:
The destination branch (must be
main
,master
, orboost_1.80.0
).The merge strategy (must be
squash
).The commit message (must match the configured regex).
Example Scenarios
Successful Validation:
A pull request targets
main
.The merge strategy is
squash
.The commit message matches the regex.
Failure Cases:
The destination branch is not allowed.
The merge strategy is not
squash
.The commit message does not match the regex.
Contribution Guidelines
Fork the repository.
Make your changes in a new branch.
Submit a pull request with a detailed description.
Last updated
Was this helpful?