diff --git a/.github/config/gitlint/gitlint.cfg b/.github/config/gitlint/gitlint.cfg new file mode 100644 index 0000000..5628f44 --- /dev/null +++ b/.github/config/gitlint/gitlint.cfg @@ -0,0 +1,9 @@ +# Config for linting git commit messages +[general] +extra-path=.github/config/gitlint/rules + +[title-match-regex] +regex=^(feat|fix|docs|style|refactor|perf|test|chore)(\(.*\))?: .* + +[author-valid-email] +regex=[^@ ]+@[^@ ]+\.[^@ ]+ diff --git a/.github/config/gitlint/rules/github.py b/.github/config/gitlint/rules/github.py new file mode 100644 index 0000000..b97487a --- /dev/null +++ b/.github/config/gitlint/rules/github.py @@ -0,0 +1,34 @@ +from gitlint.rules import CommitRule, RuleViolation +from gitlint.options import IntOption +import re + +class SignedOffBy(CommitRule): + """ This rule will enforce that each commit contains a "Signed-off-by" line with a name and email address. + """ + id = "SIGNOFF" + name = "body-requires-signed-off-by" + + signOffRegex = re.compile('^(DCO 1.1 )?Signed-off-by: .* <[^@ ]+@[^@ ]+\.[^@ ]+>') + + def validate(self, commit): + for line in commit.message.body: + if self.signOffRegex.match(line): + return + + return [RuleViolation(self.id, "Body does not contain a valid 'Signed-off-by' line", line_nr=1)] + + +class GithubIssue(CommitRule): + """ This rule will enforce that each commit is associated with a Github issue that explains what the commit is for. + """ + id = "COMMIT" + name = "commit-require-github-issue" + + githubIssueRegex = re.compile('(Resolves|Closes|Contributes to|Reverts):? [a-z\-/]*#[0-9]+') + + def validate(self, commit): + for line in commit.message.body: + if self.githubIssueRegex.match(line): + return + + return [RuleViolation(self.id, "Body does not contain a github issue reference", line_nr=1)] diff --git a/.github/workflows/gitlint.yml b/.github/workflows/gitlint.yml new file mode 100644 index 0000000..6a3ee3e --- /dev/null +++ b/.github/workflows/gitlint.yml @@ -0,0 +1,20 @@ +name: Gitlint + +on: + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + name: Gitlint + + steps: + - uses: actions/checkout@v2 + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: '3.9' + - name: Install gitlint + run: pip install gitlint + - name: Execute gitlint + run: gitlint --config=.github/config/gitlint/gitlint.cfg --debug