-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdefault.nix
124 lines (108 loc) · 2.73 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
{nixpkgs ? import <nixpkgs> {}}:
with nixpkgs; let
dependencies = [
coreutils
gnugrep
git
];
wrapper = writeShellScriptBin "mailmap-linter" ''
set -o errexit
set -o nounset
set -o pipefail
export PATH="${lib.makeBinPath dependencies}"
mailmap_exclude=()
echo '[INFO] Veryfing if .mailmap exists'
test -e .mailmap \
|| {
echo ' [ERROR] Please add a .mailmap file in the root of the repo'
exit 1
}
echo '[INFO] Computing contributors'
mapfile -t 'authors' < \
<((
git -P log --format='%aN <%aE>' \
&& git -P log --format='%cN <%cE>'
) | LC_ALL=C sort \
| uniq)
echo '[INFO] Reading current .mailmap'
mapfile -t 'mailmap' < \
.mailmap
test -e .mailmap-exclude \
&& echo '[INFO] Found .mailmap-exclude file' \
&& echo ' [INFO] Reading current .mailmap-exclude' \
&& mapfile -t 'mailmap_exclude' < .mailmap-exclude
while (( "$#" )); do
case "$1" in
-e|--exclude)
mailmap_exclude+=("$2")
shift 2
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
echo '[INFO] Veryfing .mailmap format'
line_number=0
format='^[A-Z][[:alpha:]]+ [A-Z][[:alpha:]]+ <.*> (.*?) <.*?>$'
for mapping in "''${mailmap[@]}"
do
line_number=$((line_number + 1))
if ! echo "$mapping" | grep -qP "$format"
then
echo " [ERROR] Expected: $format"
echo " Line $line_number: $mapping"
exit 1
fi
done
echo '[INFO] Veryfing that every author is in the .mailmap'
success=true
for author in "''${authors[@]}"
do
echo " [INFO] Veryfing: $author"
found=false
for exclude in "''${mailmap_exclude[@]}"
do
if [[ $author =~ $exclude ]]
then
echo " [INFO] Excluded: $author"
continue 2
fi
done
for mapping in "''${mailmap[@]}"
do
if [[ $mapping == *"$author"* ]]
then
found=true
break
fi
done
if test "$found" != "true"
then
echo " [ERROR] Please add a .mailmap entry for: $author"
success=false
fi
done
if test "$success" != 'true'
then
exit 1
fi
echo '[INFO] Veryfing that .mailmap is sorted'
if LC_ALL=C sort --check=silent .mailmap
then
echo ' [INFO] OK'
else
echo ' [ERROR] Please sort the .mailmap with: $ LC_ALL=C sort .mailmap'
exit 1
fi
'';
in
stdenv.mkDerivation {
name = "mailmap-linter";
installPhase = ''
mkdir -p $out/bin
install ${wrapper}/bin/* $out/bin
'';
src = ./.;
}