Skip to content

Commit fe32890

Browse files
chmouelpipelines-as-code[bot]
authored andcommitted
chore: Improve commit and pull request title validation
* Consolidated Gitlint and conventional commit checks into a single task. * Added a new validation step for pull request titles to ensure they followed conventional commit format. * Enhanced the commit validation script with improved error handling and explicit pip package installation. * Updated markdownlint configuration to align with new rule names. * Corrected minor formatting inconsistencies across several markdown documentation files. Signed-off-by: Chmouel Boudjnah <[email protected]>
1 parent ce23998 commit fe32890

File tree

6 files changed

+108
-67
lines changed

6 files changed

+108
-67
lines changed

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Fixes #
2626
- [ ] Integration tests
2727
- [ ] End-to-end tests
2828
- [ ] Manual testing
29-
- [ ] Note Applicable
29+
- [ ] Not Applicable
3030

3131
## ✅ Submitter Checklist
3232

.markdownlint.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"line-length": false,
33
"first-header-h1": false,
4-
"first-line-h1": false,
4+
"first-header-heading": false,
55
"no-inline-html": false,
66
"MD013": false,
77
"MD025": false,
8+
"MD041": false,
89
"descriptive-link-text": false
910
}

.tekton/linter.yaml

Lines changed: 99 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -58,47 +58,124 @@ spec:
5858
workingDir: $(workspaces.source.path)
5959
script: |
6060
shellcheck $(find hack/ -type f -regex ".*sh" -print)
61-
- name: gitlint
62-
displayName: "Git commit linter"
61+
- name: commit-validation
62+
displayName: "Git commit validation (gitlint + conventional commits)"
6363
image: registry.access.redhat.com/ubi9/python-312
6464
workingDir: $(workspaces.source.path)
6565
script: |
6666
set -euxo pipefail
67+
68+
# Configure git
69+
git config --global user.name "Pipelines as Code"
70+
git config --global user.email "[email protected]"
71+
git config --global --add safe.directory $(workspaces.source.path)
72+
73+
# Check if this is a GitHub event
6774
if [[ "{{ headers['X-Github-Event'] }}" == "" ]]; then
68-
echo "Not a GitHub event, skipping gitlint"
75+
echo "Not a GitHub event, skipping commit validation"
6976
exit 0
7077
fi
7178
79+
# Only run on pull requests
7280
if [[ "{{ headers['X-Github-Event'] }}" != "pull_request" ]]; then
73-
echo "Not a pull request, skipping gitlint"
81+
echo "Not a pull request, skipping commit validation"
7482
exit 0
7583
fi
7684
77-
git config --global --add safe.directory $(workspaces.source.path)
78-
git config --global user.name "Pipelines as Code"
79-
git config --global user.email "[email protected]"
80-
git log -1 --format=format:%s |grep -E -q '^Merge branch' && exit 0
81-
pip3 install gitlint
82-
83-
# Check all commits between base_sha and HEAD
85+
# Get base SHA and validate
8486
base_sha="{{ body.pull_request.base.sha }}"
85-
failed=()
87+
if [[ -z "$base_sha" ]]; then
88+
echo "Base SHA is empty, cannot determine commit range"
89+
exit 1
90+
fi
91+
92+
echo "Validating commits between $base_sha and HEAD"
93+
94+
# Install gitlint
95+
echo "Installing gitlint..."
96+
if ! pip3 install gitlint; then
97+
echo "Failed to install gitlint"
98+
exit 1
99+
fi
100+
101+
# Define conventional commit regex
102+
conv_regexp='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9-]+\))?: .+'
103+
104+
# Validate commits
105+
gitlint_failed=()
106+
conventional_failed=()
107+
86108
while read -r commit_hash; do
87-
echo "Checking commit: $commit_hash"
88-
if ! git log -1 --pretty=format:%B "$commit_hash" | gitlint --staged; then
89-
echo "Gitlint failed for commit: $commit_hash"
90-
failed+=("$commit_hash")
109+
if [[ -n "$commit_hash" ]]; then
110+
echo "Validating commit: $commit_hash"
111+
112+
# Get commit message
113+
commit_msg=$(git log -1 --pretty=format:%s "$commit_hash")
114+
commit_body=$(git log -1 --pretty=format:%B "$commit_hash")
115+
116+
# Skip merge commits
117+
if echo "$commit_msg" | grep -E -q '^Merge branch'; then
118+
echo " Skipping merge commit: $commit_hash"
119+
continue
120+
fi
121+
122+
# Run gitlint check
123+
if ! echo "$commit_body" | gitlint --staged; then
124+
echo " Gitlint failed for commit: $commit_hash"
125+
gitlint_failed+=("$commit_hash")
126+
fi
127+
128+
# Run conventional commit check
129+
if ! echo "$commit_msg" | grep -E -q "${conv_regexp}"; then
130+
echo " Conventional commit check failed for: $commit_hash"
131+
echo " Message: $commit_msg"
132+
conventional_failed+=("$commit_hash")
133+
fi
91134
fi
92135
done < <(git log "${base_sha}..HEAD" --format=format:%H --no-merges)
93136
94-
if [ "${#failed[@]}" -ne 0 ]; then
95-
echo "Failed commits: ${failed[@]}"
96-
exit 1
97-
else
98-
echo "Gitlint completed. All commits passed."
99-
exit 0
137+
# Check pull request title for conventional commit format
138+
pull_request_title="{{ body.pull_request.title }}"
139+
pr_title_failed=false
140+
if [[ -n "$pull_request_title" ]] && ! echo "$pull_request_title" | grep -E -q "${conv_regexp}"; then
141+
echo "ERROR: Pull request title does not follow conventional commit format:"
142+
echo " Title: $pull_request_title"
143+
pr_title_failed=true
144+
fi
145+
146+
# Report results
147+
exit_code=0
148+
149+
if [ "${#gitlint_failed[@]}" -ne 0 ]; then
150+
echo ""
151+
echo "ERROR: Gitlint failed for commits: ${gitlint_failed[*]}"
152+
exit_code=1
153+
fi
154+
155+
if [ "${#conventional_failed[@]}" -ne 0 ]; then
156+
echo ""
157+
echo "ERROR: Conventional commit format failed for commits: ${conventional_failed[*]}"
158+
echo "Expected format: type(scope): description"
159+
echo "Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
160+
echo "See: https://www.conventionalcommits.org/en/v1.0.0/#summary"
161+
exit_code=1
162+
fi
163+
164+
if [ "$pr_title_failed" = true ]; then
165+
echo ""
166+
echo "ERROR: Pull request title validation failed"
167+
echo "Expected format: type(scope): description"
168+
echo "Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
169+
exit_code=1
170+
fi
171+
172+
if [ $exit_code -eq 0 ]; then
173+
echo ""
174+
echo "All commit validations passed successfully!"
100175
fi
101176
177+
exit $exit_code
178+
102179
- name: check-generated-schemas
103180
displayName: "Check generated OpenAPI schemas"
104181
image: golang:1.23
@@ -131,43 +208,6 @@ spec:
131208
# check now that there are no changes in config with git
132209
git diff --exit-code config/ || { echo "Error: you need to run 'make update-schemas' and commit it."; exit 1; }
133210
134-
- name: conventional-commits
135-
displayName: "conventional commit check"
136-
image: registry.access.redhat.com/ubi9/python-312
137-
workingDir: $(workspaces.source.path)
138-
script: |
139-
set -euxo pipefail
140-
git config --global --add safe.directory /workspace/source
141-
142-
if [[ "{{ headers['X-Github-Event'] }}" == "" ]]; then
143-
echo "Not a GitHub event, skipping gitlint"
144-
exit 0
145-
fi
146-
147-
if [[ "{{ headers['X-Github-Event'] }}" != "pull_request" ]]; then
148-
echo "Not a pull request, skipping gitlint"
149-
exit 0
150-
fi
151-
base_sha="{{ body.pull_request.base.sha }}"
152-
153-
# make sure we have a conventional commit
154-
invalid_commits=0
155-
while read -r commit_msg; do
156-
if ! echo "$commit_msg" | grep -E -q '^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9-]+\))?:'; then
157-
echo "ERROR: Found commit message that does not follow conventional commit format:"
158-
echo "$commit_msg"
159-
invalid_commits=$((invalid_commits + 1))
160-
fi
161-
done < <(git log "${base_sha}..HEAD" --format=format:%s --no-merges)
162-
163-
if [ $invalid_commits -gt 0 ]; then
164-
echo "ERROR: $invalid_commits commit(s) do not follow conventional commit format."
165-
echo "Expected format: type(scope): description"
166-
echo "Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
167-
echo "See: https://www.conventionalcommits.org/en/v1.0.0/#summary"
168-
exit 1
169-
fi
170-
171211
- name: yamllint
172212
displayName: "YAML Linter"
173213
image: cytopia/yamllint

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Pipelines-as-Code is an opinionated CI/CD solution built on OpenShift Pipelines
99
and Tekton. It enables you to define, manage, and execute pipelines directly
1010
from your source code repository.
1111

12-
📖 **Full documentation:** [pipelinesascode.com](https://pipelinesascode.com)
12+
📖 **Full documentation:** [pipelinesascode.com](https://pipelinesascode.com)
1313
🛠️ **Development branch docs:** [here](https://nightly.pipelines-as-code.pages.dev/)
1414

1515
---
@@ -69,7 +69,7 @@ If you'd like to help improve Pipelines-as-Code, check out our contribution guid
6969

7070
## 🎥 Videos & Blogs
7171

72-
- 📺 [OpenShift Developer Experience: Pipelines-as-Code](https://www.youtube.com/watch?v=PhqzGsJnFEI)
72+
- 📺 [OpenShift Developer Experience: Pipelines-as-Code](https://www.youtube.com/watch?v=PhqzGsJnFEI)
7373
- 📘 [How to make a release pipeline with Pipelines-as-Code](https://blog.chmouel.com/2021/07/01/how-to-make-a-release-pipeline-with-pipelines-as-code)
7474

7575
- 📝 **Latest Developer Documentation:** [Main branch docs](https://main.pipelines-as-code.pages.dev/)

docs/content/docs/guide/resolver.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The resolver will skip resolving if it sees these type of tasks:
3737

3838
* a reference to a [`ClusterTask`](https://github.com/tektoncd/pipeline/blob/main/docs/tasks.md#task-vs-clustertask)
3939
* a `Task` or `Pipeline` [`Bundle`](https://github.com/tektoncd/pipeline/blob/main/docs/pipelines.md#tekton-bundles)
40-
* a reference to a Tekton [`Resolver`](https://github.com/tektoncd/pipeline/blob/main/docs/pipelines.md#specifying-remote-tasks)
40+
* a reference to a Tekton [`Resolver`](https://github.com/tektoncd/pipeline/blob/main/docs/pipelines.md#specifying-remote-tasks)
4141
* a [Custom Task](https://github.com/tektoncd/pipeline/blob/main/docs/pipelines.md#using-custom-tasks) with an apiVersion that doesn't have a `tekton.dev/` prefix.
4242

4343
It just uses them "as is" and will not try to do anything with it.

docs/content/docs/install/settings.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,12 @@ There is a few things you can configure through the config map
145145
both a push event and a pull request. If a push event comes from a commit that is
146146
part of an open pull request, the push event will be skipped as it would create
147147
a duplicate pipeline run.
148-
148+
149149
This feature works by checking if a pushed commit SHA exists in any open pull request,
150150
and if so, skipping the push event processing.
151-
151+
152152
Default: `true`
153-
153+
154154
{{< support_matrix github_app="true" github_webhook="true" gitea="false" gitlab="false" bitbucket_cloud="false" bitbucket_datacenter="false" >}}
155155

156156
### Global Cancel In Progress Settings

0 commit comments

Comments
 (0)