-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
global: add gitlint for commit message checks
* closes cernanalysispreservation#2033 Signed-off-by: Ilias Koutsakis <[email protected]>
- Loading branch information
Showing
7 changed files
with
186 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
--- | ||
name: Commit Check | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
CommitCheckJob: | ||
name: Commit Check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
# fetch-depth is needed to get the full list of commits | ||
# necessary for commit msg linting when a PR has 2 commits or more | ||
# to avoid getting ALL the commits, we get current commits + origin | ||
fetch-depth: ${{ github.event.pull_request.commits }} + 1 | ||
ref: ${{ github.event.pull_request.head.sha }} | ||
- name: Setup python 3.6 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.6.9 | ||
- name: Checking commit quality (messages, signatures, etc) | ||
env: | ||
GIT_LAST: ${{ github.event.after }} | ||
GIT_ORIGIN: ${{ github.event.pull_request.base.sha }} | ||
run: | | ||
sh ./scripts/ci/prebuild.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[general] | ||
ignore=body-is-missing | ||
extra-path=gitlint_rules/ | ||
debug=true | ||
verbosity=3 | ||
|
||
[title-max-length] | ||
line-length=50 | ||
|
||
[body-max-line-length] | ||
line-length=72 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from gitlint.rules import CommitRule, RuleViolation | ||
|
||
COMMIT_SUBJECTS = [ | ||
"alice", | ||
"atlas", | ||
"cms", | ||
"lhcb", | ||
"ui", | ||
"access", | ||
"deposits", | ||
"auth", | ||
"devops", | ||
"docker", | ||
"docs", | ||
"files", | ||
"fixtures", | ||
"global", | ||
"mail", | ||
"records", | ||
"repos", | ||
"schemas", | ||
"scripts", | ||
"search", | ||
"services", | ||
"tests", | ||
"workflows" | ||
] | ||
|
||
|
||
class SignedOffBy(CommitRule): | ||
""" | ||
This rule will enforce that each commit contains a "Signed-off-by" line. | ||
""" | ||
name = "body-requires-signed-off-by" | ||
id = "CAP1" | ||
|
||
def validate(self, commit): | ||
for line in commit.message.body: | ||
if line.startswith("Signed-off-by"): | ||
return | ||
|
||
msg = "Body does not contain a 'Signed-Off-By' line" | ||
return [RuleViolation(self.id, msg, line_nr=1)] | ||
|
||
|
||
class ApprovedSubject(CommitRule): | ||
""" | ||
This rule will enforce that each commit starts with one of the approved | ||
subjects, as presented in the list above. | ||
""" | ||
name = "approved-subject-in-title" | ||
id = "CAP2" | ||
|
||
def validate(self, commit): | ||
for subject in COMMIT_SUBJECTS: | ||
if commit.message.title.startswith(f'{subject}: '): | ||
return | ||
|
||
msg = f"Subject not approved, please start with one of: " \ | ||
f"{COMMIT_SUBJECTS}" | ||
return [RuleViolation(self.id, msg, line_nr=1)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
# | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of CERN Analysis Preservation Framework. | ||
# Copyright (C) 2021 CERN. | ||
# | ||
# CERN Analysis Preservation Framework is free software; you can redistribute | ||
# it and/or modify it under the terms of the GNU General Public License as | ||
# published by the Free Software Foundation; either version 2 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# CERN Analysis Preservation Framework is distributed in the hope that it will | ||
# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with CERN Analysis Preservation Framework; if not, write to the | ||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
# MA 02111-1307, USA. | ||
# | ||
# In applying this license, CERN does not | ||
# waive the privileges and immunities granted to it by virtue of its status | ||
# as an Intergovernmental Organization or submit itself to any jurisdiction. | ||
|
||
handle_test_result(){ | ||
EXIT_CODE=$1 | ||
RESULT="$2" | ||
if [ $EXIT_CODE -eq 0 ]; then | ||
echo "Commit check was succesfull." | ||
else | ||
echo "Errors in commit message." | ||
fi | ||
|
||
# Print RESULT if not empty | ||
if [ -n "$RESULT" ] ; then | ||
echo "$RESULT" | ||
fi | ||
} | ||
|
||
run_git_check(){ | ||
RESULT=$(gitlint --commits $GIT_ORIGIN..$GIT_LAST 2>&1) | ||
local exit_code=$? | ||
handle_test_result $exit_code "$RESULT" | ||
return $exit_code | ||
} | ||
|
||
pip install gitlint | ||
run_git_check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,30 @@ | ||
#!/bin/bash | ||
# | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of CERN Analysis Preservation Framework. | ||
# Copyright (C) 2021 CERN. | ||
# | ||
# CERN Analysis Preservation Framework is free software; you can redistribute | ||
# it and/or modify it under the terms of the GNU General Public License as | ||
# published by the Free Software Foundation; either version 2 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# CERN Analysis Preservation Framework is distributed in the hope that it will | ||
# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with CERN Analysis Preservation Framework; if not, write to the | ||
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
# MA 02111-1307, USA. | ||
# | ||
# In applying this license, CERN does not | ||
# waive the privileges and immunities granted to it by virtue of its status | ||
# as an Intergovernmental Organization or submit itself to any jurisdiction. | ||
|
||
echo "RUNNING PREBUILD SCRIPTS" | ||
# if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then | ||
# ./scripts/helpers/check_commit_subject.sh -r $TRAVIS_COMMIT_RANGE | ||
# fi | ||
# 1st step: commit message | ||
|
||
echo "RUNNING COMMIT MESSAGE CHECKS" | ||
sh ./scripts/ci/commit-msg-check.sh |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters