Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .config/gitlint/rules/on-behalf-of-marker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from gitlint.rules import LineRule, RuleViolation, CommitMessageTitle, CommitRule

class BodyContainsOnBehalfOfSAPMarker(CommitRule):
"""Enforce that each commit coming from an SAP contractor contains an
"On-behalf-of SAP user@sap.com" marker.
"""

# A rule MUST have a human friendly name
name = "body-requires-on-behalf-of-sap"

# A rule MUST have a *unique* id
# We recommend starting with UC (for User-defined Commit-rule).
id = "UC-sap"

# Lower-case list of contractors
contractors = [
"@cyberus-technology.de"
]

# Marker followed by " name.surname@sap.com"
marker = "On-behalf-of: SAP"

def validate(self, commit):
if "@sap.com" in commit.author_email.lower():
return

# Allow third-party open-source contributions
if not any(contractor in commit.author_email.lower() for contractor in self.contractors):
return

for line in commit.message.body:
if line.startswith(self.marker) and "@sap.com" in line.lower():
return

msg = f"Body does not contain a '{self.marker} user@sap.com' line"
return [RuleViolation(self.id, msg, line_nr=1)]
23 changes: 23 additions & 0 deletions .github/workflows/commit-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Commit Lint
on: [ pull_request ]
jobs:
gitlint:
name: Check commit messages
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Set up Python 3.10
uses: actions/setup-python@v3
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade gitlint
- name: Lint git commit messages
run: |
gitlint --commits origin/$GITHUB_BASE_REF..
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
result*
/.pre-commit-config.yaml
/.nixos-test-history

# Produced by gitlint
__pycache__
20 changes: 20 additions & 0 deletions .gitlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[general]
extra-path=.config/gitlint/rules
regex-style-search=true
ignore=body-is-missing

[ignore-by-author-name]
regex=dependabot
ignore=all

# default 72
[title-max-length]
line-length=72

# default 80
[body-max-line-length]
line-length=72

# Empty bodies are fine
[body-min-length]
min-length=0
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
devShells.default = pkgs.mkShellNoCC {
inherit (self.checks.${system}.pre-commit-check) shellHook;
buildInputs = self.checks.${system}.pre-commit-check.enabledPackages;
packages = with pkgs; [ gitlint ];
};

lib = {
Expand Down