-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds simplified generator for pre-commit configs
- Loading branch information
Showing
5 changed files
with
63 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ pre-commit, stagesStr }: | ||
{ | ||
shellHookExtra = '' | ||
# Uninstall all existing hooks | ||
hooks="pre-commit pre-merge-commit pre-push prepare-commit-msg commit-msg post-checkout post-commit" | ||
for hook in $hooks; do | ||
${pre-commit}/bin/pre-commit uninstall -t $hook | ||
done | ||
# Install configured hooks | ||
for stage in ${stagesStr}; do | ||
if [[ "$stage" == "manual" ]]; then | ||
continue | ||
fi | ||
${pre-commit}/bin/pre-commit install -t "$stage" | ||
done | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ pkgs, lib }: | ||
{ | ||
mkConfig = import ./make.nix { inherit pkgs lib; }; | ||
mkLocalConfig = import ./make_local.nix { inherit pkgs lib; }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ pkgs, lib }: | ||
{ config, pre-commit ? pkgs.pre-commit, jq ? pkgs.jq, yq ? pkgs.yq-go }: | ||
with pkgs.lib; | ||
let | ||
# Find all stages that require installation | ||
stages = unique (flatten (builtins.map (hook: optionals (hook ? stages) hook.stages) (attrValues config))); | ||
stagesStr = builtins.concatStringsSep " " stages; | ||
|
||
# Add an extra hook for reinstalling required stages whenever the file changes | ||
shellHookExtra = (import ./common.nix { inherit pre-commit stagesStr; }).shellHookExtra; | ||
|
||
# Add structure to config | ||
hooks = attrValues (pkgs.lib.mapAttrs | ||
(id: hook: ( | ||
{ inherit id; name = if (hook ? name) then hook.name else id; } // hook | ||
)) | ||
config); | ||
data = { | ||
repos = [ | ||
{ | ||
inherit hooks; | ||
repo = "local"; | ||
} | ||
]; | ||
}; | ||
|
||
# Generate the module | ||
result = lib.common.mkTemplate { | ||
inherit data shellHookExtra; | ||
files = [ ./template.cue ]; | ||
output = ".pre-commit-config.yaml"; | ||
}; | ||
in | ||
{ | ||
inherit (result) configFile shellHook; | ||
} |