Skip to content

Commit 6575e4d

Browse files
chmouelzakisk
authored andcommitted
fix: Improve Tekton gitlint step to list all failing commits
* Updated the Gitlint invocation method within the Tekton pipeline script. * Changed the commit linting check to collect all non-compliant commit hashes. * Modified the step to output a list of every commit that failed the linting check before exiting. * Provided clearer feedback to developers by identifying all commits needing correction. Signed-off-by: Chmouel Boudjnah <[email protected]>
1 parent 8dbb5f5 commit 6575e4d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

.tekton/linter.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,29 @@ spec:
7575
fi
7676
7777
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]"
7880
git log -1 --format=format:%s |grep -E -q '^Merge branch' && exit 0
7981
pip3 install gitlint
8082
8183
# Check all commits between base_sha and HEAD
8284
base_sha="{{ body.pull_request.base.sha }}"
83-
failed=0
85+
failed=()
8486
while read -r commit_hash; do
8587
echo "Checking commit: $commit_hash"
86-
if ! gitlint --commit "$commit_hash" --ignore "Merge branch"; then
87-
failed=1
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")
8891
fi
8992
done < <(git log "${base_sha}..HEAD" --format=format:%H --no-merges)
9093
91-
exit $failed
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
100+
fi
92101
93102
- name: check-generated-schemas
94103
displayName: "Check generated OpenAPI schemas"

0 commit comments

Comments
 (0)