Skip to content

Commit

Permalink
workflows: Added commit message formating
Browse files Browse the repository at this point in the history
Signed-off-by: Lorenzo Vagliano
  • Loading branch information
Lorenzovagliano committed Oct 23, 2024
1 parent 1dd37aa commit 484a161
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 3 deletions.
1 change: 0 additions & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ jobs:

- name: Run pre-commit
uses: pre-commit/[email protected]

3 changes: 1 addition & 2 deletions .github/workflows/pull-request-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Pull request main
on:
pull_request_target:
branches: [main]
paths-ignore: [ "docs/**" ]
paths-ignore: ["docs/**"]

jobs:
test:
Expand All @@ -17,4 +17,3 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha }}
secrets: inherit

11 changes: 11 additions & 0 deletions .gitlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[general]
ignore=body-is-missing
extra-path=./scripts/gitlint_rules/
debug=true
verbosity=3

[title-max-length]
line-length=50

[body-max-line-length]
line-length=72
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ repos:
rev: "v2.7.1"
hooks:
- id: prettier
stages: [commit]
- repo: https://github.com/pycqa/isort
rev: "5.12.0"
hooks:
Expand All @@ -22,3 +23,11 @@ repos:
- id: check-merge-conflict
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/jorisroovers/gitlint
rev: "v0.17.0"
hooks:
- id: gitlint
language: python
entry: gitlint
stages: [commit-msg]
args: [--msg-filename]
39 changes: 39 additions & 0 deletions scripts/gitlint_rules/rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import re

from gitlint.rules import CommitRule, RuleViolation

class SignedOffBy(CommitRule):
"""This rule will enforce that each commit contains a "Signed-off-by" line."""

name = "body-requires-signed-off-by"
id = "Workflows1"

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):
"""Validate subject of each commit.
This rule will enforce that each commit starts with a "module: text" format.
The 'module' can be any alphanumeric word, and the message must start with a colon followed by a space.
"""

name = "approved-subject-in-title"
id = "Workflows2"

MODULE_PATTERN = re.compile(r"^[a-zA-Z0-9_-]+: .+")

def validate(self, commit):
title = commit.message.title

if not self.MODULE_PATTERN.match(title):
msg = "Subject does not follow 'module: text' format"
return [RuleViolation(self.id, msg, line_nr=1)]

return

0 comments on commit 484a161

Please sign in to comment.