From 61fb59581cd4c5d548077612721f7ee1b7527049 Mon Sep 17 00:00:00 2001 From: David Leong <116610336+leongdl@users.noreply.github.com> Date: Wed, 23 Oct 2024 16:21:06 -0700 Subject: [PATCH] docs: Add documentation and for default git hook containing DCO and conventional commits. Add a new quality target to run both fmt and lint (#482) Signed-off-by: David Leong <116610336+leongdl@users.noreply.github.com> --- CONTRIBUTING.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ hatch.toml | 5 +++++ 2 files changed, 59 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3fa3c4fc..9a5df4b7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,6 +14,8 @@ Table of contents: * [Talk with us first](#talk-with-us-first) * [Contributing via Pull Requests](#contributing-via-pull-requests) * [Conventional Commits](#conventional-commits) + * [Digital Certificate of Origin](#digital-certificate-of-origin) + * [Conventional Commit & DCO Automation](#automating-conventional-commits-and-dco) * [Licensing](#licensing) ## Reporting Bugs/Feature Requests @@ -107,6 +109,58 @@ If you need change a commit message, then please see the [GitHub documentation on the topic](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/changing-a-commit-message) to guide you. +### Digital Certificate of Origin. + +This repository enforces the Developer Certificate of Origin (DCO) on Pull Requests. It requires all commit messages to contain the `Signed-off-by` line with an email address that matches the commit author. + +To generate the `Signed-off-by` line, make sure `git commit` is passed with the `-s` flag. + +### Automating Conventional Commits and DCO. + +To simplify Conventional Commit and DCO, it is recommended to setup a Git hook for the repository. Add the following as a git hook: + +- Edit `{repository}/.git/hooks/commit-msg` +- `chmod +x {repository}/.git/hooks/commit-msg` +- Paste in the following shell script, customize as necessary. +``` +#!/bin/sh +SIGNATURE="Signed-off-by: `git config --global --get user.name` <`git config --global --get user.email`>" +grep -qs "^${SIGNATURE}" "$1" || echo "\n${SIGNATURE}" >> "$1" + +commitTitle="$(cat $1 | head -n1)" + +# ignore merge requests +if echo "$commitTitle" | grep -qE "Merge branch"; then + echo "Commit hook: ignoring branch merge" + exit 0 +fi + +# check semantic versioning scheme +if ! echo "$commitTitle" | grep -qE '^(feat|fix|docs|style|refactor|perf|test|chore|build|ci|revert)(\([a-z0-9\s\-\_\,]+\))?!?:\s\w'; then + echo "Your commit message did not follow semantic versioning: $commitTitle" + echo "" + echo "Format: (): " + echo "Example: feat(api): add endpoint" + echo "" + echo "Valid types: build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test" + echo "" + echo "Please see" + echo "- https://www.conventionalcommits.org/en/v1.0.0/#summary" + exit 1 +fi +``` + +If you want to create this hook automatically on every new git repository you will create from now on (using git init, git clone...) you can use git-templates; to do so, just save the script described above into (duplicate files): + +``` +~/.git-templates/hooks/commit-msg +``` + +Configure the Git default as follows: +``` +git config --global init.templatedir ~/.git-templates +``` + ## Licensing See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. diff --git a/hatch.toml b/hatch.toml index 6aedc893..5651bc1f 100644 --- a/hatch.toml +++ b/hatch.toml @@ -20,6 +20,11 @@ lint = [ "style", "typing", ] +quality = [ + "black {args:.}", + "typing", + "style", +] [[envs.all.matrix]] python = ["3.8", "3.9", "3.10", "3.11"]