📚
Aditya Kumar
  • About me
    • Resume
  • Automating Amazon EBS
  • ECS Bluegreen with Lambda SWAP
  • First drive of AWS Chatbot
  • Talking COVID-19 with Amazon Lex
  • Managed Jupyter on AWS SageMaker
  • Extending GitOps to reliability-as-code with GitHub and StackPulse
  • HashiCorp Packer for Machine Images
  • Deleted My Web App and App Service Plan, Whats Next ?
  • Using Terraform for zero downtime updates of an Auto Scaling group in AWS
  • Automating Instagram Posts with AI: A Step-by-Step Guide
  • Merge Commit Message Validator for Pull Requests
  • Automating Jenkins Data Backup with rsync and Slack Notifications
  • Creating a One-Time Setup for Kubernetes Cluster with Worker Nodes Using HAProxy
Powered by GitBook
On this page
  • Features
  • Files Overview
  • Installation and Setup
  • Usage
  • Example Scenarios
  • Contribution Guidelines

Was this helpful?

Merge Commit Message Validator for Pull Requests

PreviousAutomating Instagram Posts with AI: A Step-by-Step GuideNextAutomating Jenkins Data Backup with rsync and Slack Notifications

Last updated 6 months ago

Was this helpful?

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:

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

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

    forge deploy
    forge install
  4. 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, 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.

Git Repo

https://github.com/ttn-aditya/merge-commit-regex-checker-bitbucket-cloud
Diskit,Nubra Valley,Ladakh