-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
148 lines (137 loc) Β· 5.36 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
{
inputs,
flake-parts-lib,
...
}: {
imports = [
inputs.flake-parts.flakeModules.flakeModules
];
flake.flakeModules.integrations = {
options.perSystem = flake-parts-lib.mkPerSystemOption ({
lib,
pkgs,
config,
...
}: let
inherit (lib) types mkOption mkIf mkEnableOption;
inherit (import ../utils.nix {inherit lib;}) mkIntegration;
cfg = config.snow-blower.integrations.git-cliff;
in {
options.snow-blower.integrations.git-cliff = mkIntegration {
name = "Git-Cliff";
package = pkgs.git-cliff;
settings = {
file-name = mkOption {
type = types.str;
description = lib.mdDoc "The name of the file to output the chaneglog to.";
default = "CHANGELOG.md";
};
config-file = mkOption {
type = types.str;
description = ''
The git-cliff config to use.
See https://git-cliff.org/docs/configuration/
'';
default = ''
[changelog]
header = """
# Changelog\n
All notable changes to this project will be documented in this file.\n
"""
body = """
{% if version %}\
## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
{% else %}\
## [unreleased]
{% endif %}\
{% for group, commits in commits | group_by(attribute="group") %}
### {{ group | striptags | trim | upper_first }}
{% for commit in commits %}
- {% if commit.scope %}*({{ commit.scope }})* {% endif %}\
{% if commit.breaking %}[**breaking**] {% endif %}\
{{ commit.message | upper_first }}\
{% endfor %}
{% endfor %}\n
"""
# template for the changelog footer
footer = """
<!-- generated by git-cliff -->
"""
# remove the leading and trailing s
trim = true
[git]
conventional_commits = true
filter_unconventional = true
split_commits = false
commit_parsers = [
{ message = "^feat", group = "<!-- 0 -->π Features" },
{ message = "^fix", group = "<!-- 1 -->π Bug Fixes" },
{ message = "^doc", group = "<!-- 3 -->π Documentation" },
{ message = "^perf", group = "<!-- 4 -->β‘ Performance" },
{ message = "^refactor", group = "<!-- 2 -->π Refactor" },
{ message = "^style", group = "<!-- 5 -->π¨ Styling" },
{ message = "^test", group = "<!-- 6 -->π§ͺ Testing" },
{ message = "^chore\\(release\\): prepare for", skip = true },
{ message = "^chore\\(deps.*\\)", skip = true },
{ message = "^chore\\(pr\\)", skip = true },
{ message = "^chore\\(pull\\)", skip = true },
{ message = "^chore|^ci", group = "<!-- 7 -->βοΈ Miscellaneous Tasks" },
{ body = ".*security", group = "<!-- 8 -->π‘οΈ Security" },
{ message = "^revert", group = "<!-- 9 -->βοΈ Revert" },
]
protect_breaking_commits = false
filter_commits = false
topo_order = false
sort_commits = "oldest"
'';
};
integrations = {
github.enable = mkEnableOption "Enable the GitHub integration. See https://git-cliff.org/docs/integration/github";
};
};
};
config.snow-blower = mkIf cfg.enable {
packages = [
cfg.package
];
just.recipes.git-cliff = {
enable = lib.mkDefault true;
justfile = let
fileName = cfg.settings.file-name;
git-cliff-config = pkgs.writeTextFile {
name = "cliff.toml";
text = cfg.settings.config-file;
};
git-cliff-entry = pkgs.writeShellScriptBin "git-cliff" ''
${lib.optionalString cfg.settings.integrations.github.enable ''
# Get the remote URL
REMOTE_URL=$(git config --get remote.origin.url)
# Extract the owner and repo name from the URL
if [[ $REMOTE_URL =~ ^https://github.com/(.*)/(.*)\.git$ ]]; then
OWNER=''${BASH_REMATCH[1]}
REPO=''${BASH_REMATCH[2]}
elif [[ $REMOTE_URL =~ ^[email protected]:(.*)/(.*)\.git$ ]]; then
OWNER=''${BASH_REMATCH[1]}
REPO=''${BASH_REMATCH[2]}
else
echo "Unsupported remote URL format: $REMOTE_URL"
exit 1
fi
# Combine owner and repo name
GITHUB_REPO="$OWNER/$REPO"
''}
${lib.getExe' cfg.package "git-cliff"} \
--output ${fileName} \
--config ${git-cliff-config.outPath}
'';
in
lib.mkDefault ''
# Generate ${fileName} using recent commits
changelog:
${git-cliff-entry}/bin/git-cliff
'';
};
};
});
};
}