Skip to content

Commit cd5772e

Browse files
authored
docs: add ci setup for gitlab pull request title validation (#70)
1 parent e35e02b commit cd5772e

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
2+
# Merge Request Title Validation CI/CD Setup on GitLab
3+
4+
## Table of Contents
5+
6+
- [1. Introduction](#1-introduction)
7+
- [2. Getting Started](#2-getting-started)
8+
- [3. Workflow Configuration](#3-workflow-configuration)
9+
- [3.1 Stages](#31-stages)
10+
- [3.2 Tags](#32-tags)
11+
- [3.3 Script](#33-script)
12+
- [4. Example YAML Configuration](#4-example-yaml-configuration)
13+
- [5. Validation Checks](#5-validation-checks)
14+
- [6. Troubleshooting](#6-troubleshooting)
15+
- [7. Sample Repository](#7-sample-repository)
16+
- [8. Conclusion](#8-conclusion)
17+
- [Benefits of CI Setup](#benefits-of-ci-setup)
18+
- [Future Enhancements](#future-enhancements)
19+
20+
## 1. Introduction
21+
22+
This document provides guidelines for setting up Continuous Integration and Continuous Deployment (CI/CD) to validate MR Title for projects on GitLab. It aims to ensure consistent merge request titles across all projects.
23+
24+
[Back to top](#table-of-contents)
25+
26+
## 2. Getting Started
27+
28+
Before you begin, ensure you have a Gitlab account, and a basic understanding of Gitlab workflows.
29+
30+
[Back to top](#table-of-contents)
31+
32+
## 3. Workflow Configuration
33+
34+
Create a `.gitlab-ci.yml` file in your project to define your workflow.
35+
36+
### 3.1 Stages
37+
38+
Specify in which stage your workflow should run. Stage used is `validate`.
39+
40+
### 3.2 Tags
41+
42+
Define the gitlab runner tag in which your workflow will run. For example - `python-3.11.9`.
43+
44+
### 3.3 Script
45+
46+
Specify the logic of the checks which needs to be checked for merge request validation.
47+
48+
[Back to top](#table-of-contents)
49+
50+
## 4. Example YAML Configuration
51+
52+
Here is an example of a basic Gitlab Actions workflow file for MR Title Validation:
53+
54+
```yaml
55+
stages:
56+
- validate
57+
58+
validate_merge_request_title:
59+
stage: validate
60+
tags:
61+
- python-3.11.9
62+
script:
63+
- 'echo "Validating merge request title: $CI_MERGE_REQUEST_TITLE"'
64+
- |
65+
if echo "$CI_MERGE_REQUEST_TITLE" | grep -Eq "^(build|chore|ci|docs|feat|fix|perf|refactor|style|test|sample): [a-z0-9 ]{0,50}$"; then
66+
echo "PR title is as per standards"
67+
else
68+
echo "PR title is not as per standards. PR title must start with one of the following prefixes: build, chore, ci, docs, feat, fix, perf, refactor, style, test, sample. PR title content must not exceed 50 characters and shouldn't have any upper case letter character."
69+
exit 1
70+
fi
71+
only:
72+
- merge_requests
73+
- triggers
74+
```
75+
76+
[Back to top](#table-of-contents)
77+
78+
## 5. Validation Checks
79+
80+
1. MR title must start with the following prefixes: build, chore, ci, docs, feat, fix, perf, refactor, style, test, sample.
81+
2. MR title content must not exceed 50 characters.
82+
3. MR title shouldn't have any upper case letter character.
83+
84+
[Back to top](#table-of-contents)
85+
86+
## 6. Troubleshooting
87+
88+
If your CI build fails, check the logs in Gitlab Actions. Ensure your MR Title follows the above checks to pass the validation.
89+
90+
[Back to top](#table-of-contents)
91+
92+
## 7. Sample Repository
93+
94+
[Repository Link](https://gitlab.osmosys.co/osmosys-research-and-development/mr-lint-app/-/tree/main)
95+
96+
Explore this for practical demonstration of MR Title Validation CI setups.
97+
98+
[Back to top](#table-of-contents)
99+
100+
## 8. Conclusion
101+
102+
### Benefits of CI Setup
103+
104+
Setting up a CI pipeline for MR Title Validation provides several benefits:
105+
106+
- Consistency: Ensures uniform pull request titles for easier understanding and management.
107+
- Communication: Enhances clarity and collaboration among team members.
108+
- Efficiency: Streamlines the review process by providing immediate context to reviewers.
109+
- Compliance: Automatically enforces naming conventions and standards, reducing manual checks.
110+
111+
### Future Enhancements
112+
113+
Additional checks for MR title validation can be incorporated as per project requirements.
114+
115+
[Back to top](#table-of-contents)

0 commit comments

Comments
 (0)