Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enforce conventional commit format using convco #1573

Merged
merged 1 commit into from
Feb 4, 2023
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
19 changes: 18 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
crane.url = "github:ipetkov/crane?rev=98894bb39b03bfb379c5e10523cd61160e1ac782"; # https://github.com/ipetkov/crane/releases/tag/v0.11.0
crane.inputs.nixpkgs.follows = "nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
Expand All @@ -18,12 +19,17 @@
};
};

outputs = { self, nixpkgs, flake-utils, flake-compat, fenix, crane, advisory-db }:
outputs = { self, nixpkgs, nixpkgs-unstable, flake-utils, flake-compat, fenix, crane, advisory-db }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};

pkgs-unstable = import nixpkgs-unstable {
inherit system;
};

lib = pkgs.lib;
stdenv = pkgs.stdenv;

Expand Down Expand Up @@ -885,6 +891,7 @@
pkgs.nixpkgs-fmt
pkgs.shellcheck
pkgs.rnix-lsp
pkgs-unstable.convco
pkgs.nodePackages.bash-language-server
] ++ cliTestsDeps;
RUST_SRC_PATH = "${fenixChannel.rust-src}/lib/rustlib/src/rust/library";
Expand Down Expand Up @@ -950,6 +957,7 @@
pkgs.nixpkgs-fmt
pkgs.shellcheck
pkgs.git
pkgs-unstable.convco
];
};

Expand Down
53 changes: 53 additions & 0 deletions misc/git-hooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

set -eu

export tmp_file="$1.tmp"

function rm_tmp_file {
rm -f "$tmp_file"
}

trap rm_tmp_file EXIT

while : ; do
# Sanitize file first, by removing leading lines that are empty or start with a hash,
# as `convco` currently does not do it automatically (but git will)
echo -n "" > "$tmp_file"
body_detected=""
while read -r line ; do
# skip any initial comments (possibly from previous run)
if [ -z "${body_detected:-}" ] && { [[ "$line" =~ ^#.*$ ]] || [ "$line" == "" ]; }; then
continue
fi
body_detected="true"

echo "$line" >> "$tmp_file"
done < "$1"

# We have a sanitized version in "$tmp_file" now, move it the original
cp "$tmp_file" "$1"


# Run convco, start preparing a buffer we will display to the user,
# if lint fails.
echo -n "# " > "$tmp_file"
if convco check < "$1" 2>> "$tmp_file" ; then
break
fi

# lint failed, prepare the content to show
{
echo "# Refer to https://www.conventionalcommits.org/en/v1.0.0/#summary"
echo "# Quit without changes to abort"
cat "$1"
} >> "$tmp_file"

# "$tmp_file" has a commit message prefixed with comments explaining what's wrong.
cp "$tmp_file" "$1"
"${VISUAL:-${EDITOR:-vi}}" "$1"
if cmp -s "$tmp_file" "$1"; then
>&2 echo "Not changes. Exiting..."
exit 1
fi
done