> For the complete documentation index, see [llms.txt](https://ak2019cs.gitbook.io/aditya-kumar/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ak2019cs.gitbook.io/aditya-kumar/merge-commit-message-validator-for-pull-requests.md).

# Merge Commit Message Validator for Pull Requests

<figure><img src="/files/HFtA3z4xRkXjsMMCykqQ" alt=""><figcaption><p>Diskit,Nubra Valley,Ladakh</p></figcaption></figure>

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`**

This file contains the backend logic for validating pull requests. Key functionalities include:

1. **Fetching Pull Request Details**:
   * Retrieves the destination branch and checks if it's one of the allowed branches (`main`, `master`, `boost_1.80.0`).
2. **Validation Logic**:
   * Ensures the merge strategy is set to `squash`.
   * Validates the merge commit message against a regex pattern retrieved from Forge storage.
3. **Dynamic Configuration**:
   * The regex pattern for commit messages is fetched from Forge storage, allowing it to be updated without code changes.
4. **Error and Success Handling**:
   * Logs and returns appropriate responses based on validation results.

#### **`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

1. **Clone the repository**:

   ```bash
   git clone <repository-url>
   cd <repository-name>
   ```
2. **Install Dependencies**: Make sure you have the Forge CLI installed. Then install dependencies:

   ```bash
   npm install
   ```
3. **Deploy the Forge App**: Deploy the app to your Atlassian account.

   ```bash
   forge deploy
   forge install
   ```
4. **Run the App**: To test the app locally, use:

   ```bash
   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`, or `boost_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

1. Fork the repository.
2. Make your changes in a new branch.
3. Submit a pull request with a detailed description.
4. Git Repo <https://github.com/ttn-aditya/merge-commit-regex-checker-bitbucket-cloud>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ak2019cs.gitbook.io/aditya-kumar/merge-commit-message-validator-for-pull-requests.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
