Browse code
(init)
Ed Langley authored on 20/04/2019 03:30:17
Showing 2 changed files
Showing 2 changed files
0 | 2 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,172 @@ |
1 |
+#!/usr/bin/env zsh |
|
2 |
+autoload -U colors |
|
3 |
+colors |
|
4 |
+ |
|
5 |
+set -eu -o pipefail |
|
6 |
+ |
|
7 |
+function define() { |
|
8 |
+ IFS='\n' read -r -d '' ${1} || true; |
|
9 |
+} |
|
10 |
+ |
|
11 |
+local commit_template_fn="$(mktemp)" |
|
12 |
+TRAPEXIT() { |
|
13 |
+ rm "$commit_template_fn" |
|
14 |
+} |
|
15 |
+ |
|
16 |
+function git-issue-start() { |
|
17 |
+ >"$commit_template_fn" <<"EOF" |
|
18 |
+issue: |
|
19 |
+ |
|
20 |
+# issue body |
|
21 |
+EOF |
|
22 |
+ |
|
23 |
+ git stash |
|
24 |
+ TRAPEXIT() { |
|
25 |
+ git stash pop |
|
26 |
+ } |
|
27 |
+ git commit --allow-empty -t "$commit_template_fn" |
|
28 |
+} |
|
29 |
+ |
|
30 |
+git-issue-sum() { |
|
31 |
+ git log --format=format:"%h: %s" --grep issue: |
|
32 |
+} |
|
33 |
+alias git-issue-list=git-issue-sum |
|
34 |
+alias git-issue-summary=git-issue-sum |
|
35 |
+ |
|
36 |
+ |
|
37 |
+function git-issue-summarize() { |
|
38 |
+ git show -s --format=format:"%h: %s" "${1?need a ref}" -- |
|
39 |
+ echo |
|
40 |
+} |
|
41 |
+ |
|
42 |
+git-issue-normalize-ref () { |
|
43 |
+ git show -s --format=format:"%h" ${1?need a ref} -- |
|
44 |
+} |
|
45 |
+ |
|
46 |
+git-issue-closed-commits() { |
|
47 |
+ git log --format=format:"%h:%s" --grep close | sed -E 's/^.*:close\(([^)]+)\):.*$/\1/' | sort |
|
48 |
+} |
|
49 |
+git-issue-aborted-commits() { |
|
50 |
+ git log --format=format:"%h:%s" --grep abort | sed -E 's/^.*:abort\(([^)]+)\):.*$/\1/' | sort |
|
51 |
+} |
|
52 |
+git-issue-issue-commits() { |
|
53 |
+ git log --format=format:"%h" --grep issue: | sort |
|
54 |
+} |
|
55 |
+ |
|
56 |
+git-issue-open() { |
|
57 |
+ comm -23 <( ( git-issue-issue-commits ) ) <( ( git-issue-closed-commits ) ) | { |
|
58 |
+ while read -r; do |
|
59 |
+ git-issue-summarize "$REPLY" |
|
60 |
+ done |
|
61 |
+ } |
|
62 |
+} |
|
63 |
+ |
|
64 |
+git-issue-closed() { |
|
65 |
+ git-issue-closed-commits | { |
|
66 |
+ while read -r; do |
|
67 |
+ git-issue-summarize "$REPLY" |
|
68 |
+ done |
|
69 |
+ } |
|
70 |
+} |
|
71 |
+ |
|
72 |
+git-issue-aborted() { |
|
73 |
+ git-issue-aborted-commits | { |
|
74 |
+ while read -r; do |
|
75 |
+ git-issue-summarize "$REPLY" |
|
76 |
+ done |
|
77 |
+ } |
|
78 |
+} |
|
79 |
+ |
|
80 |
+git-issue-progress() { |
|
81 |
+ : ${1?need a ref} |
|
82 |
+ issue="$(git-issue-normalize-ref "$1")" |
|
83 |
+ |
|
84 |
+ git-issue-show "$issue" |
|
85 |
+ echo |
|
86 |
+ |
|
87 |
+ git log \ |
|
88 |
+ --format=format:$'%h: %s\n' \ |
|
89 |
+ --grep "$(git-issue-normalize-ref "${issue}")" | |
|
90 |
+ gtac |
|
91 |
+} |
|
92 |
+ |
|
93 |
+in-progress() { |
|
94 |
+ : ${1?need a ref} |
|
95 |
+ issue="$(git-issue-normalize-ref "$1")" |
|
96 |
+ |
|
97 |
+ git log \ |
|
98 |
+ --format=format:$'%h: %s\n' \ |
|
99 |
+ --grep "$(git-issue-normalize-ref "${issue}")" | |
|
100 |
+ grep -v "close($issue)" |
|
101 |
+} |
|
102 |
+ |
|
103 |
+git-issue-ip() { |
|
104 |
+ in-progress "$@" |
|
105 |
+} |
|
106 |
+ |
|
107 |
+function git-issue-all() { |
|
108 |
+ { |
|
109 |
+ git-issue-open | { |
|
110 |
+ while read -r; do |
|
111 |
+ if in-progress "${REPLY%%:*}" >/dev/null; then |
|
112 |
+ printf "${fg[yellow]}PROGRESS${reset_color}\t$REPLY\n"; |
|
113 |
+ else |
|
114 |
+ printf "${fg[green]}OPEN${reset_color}\t$REPLY\n"; |
|
115 |
+ fi |
|
116 |
+ done |
|
117 |
+ } | sort -r |
|
118 |
+ git-issue-closed | { |
|
119 |
+ while read -r; do |
|
120 |
+ printf "${fg[red]}CLOSED${reset_color}\t$REPLY\n"; |
|
121 |
+ done |
|
122 |
+ } |
|
123 |
+ git-issue-aborted | { |
|
124 |
+ while read -r; do |
|
125 |
+ printf "${fg[red]}ABORTED${reset_color}\t$REPLY\n"; |
|
126 |
+ done |
|
127 |
+ } |
|
128 |
+ } | column -t -s $'\t' |
|
129 |
+} |
|
130 |
+ |
|
131 |
+git-issue-show() { |
|
132 |
+ git show --format=full "$1" -- |
|
133 |
+} |
|
134 |
+ |
|
135 |
+git-issue-show-brief() { |
|
136 |
+ git show --format=format:"%h: %s" "$1" -- |
|
137 |
+} |
|
138 |
+ |
|
139 |
+git-issue-close() { |
|
140 |
+ issue="$(git-issue-normalize-ref "${1?must provide an issue hash to close}")" |
|
141 |
+ |
|
142 |
+ if ! git-issue-show "$issue" &>/dev/null; then |
|
143 |
+ echo "invalid issue '$issue' provided" >&2 |
|
144 |
+ return |
|
145 |
+ fi |
|
146 |
+ |
|
147 |
+ >"$commit_template_fn" <<EOF |
|
148 |
+abort($issue): |
|
149 |
+EOF |
|
150 |
+ |
|
151 |
+ git commit --allow-empty -t "$commit_template_fn" |
|
152 |
+} |
|
153 |
+ |
|
154 |
+git-issue-abort() { |
|
155 |
+ issue="$(git-issue-normalize-ref "${1?must provide an issue hash to close}")" |
|
156 |
+ |
|
157 |
+ if ! git-issue-show "$issue" &>/dev/null; then |
|
158 |
+ echo "invalid issue '$issue' provided" >&2 |
|
159 |
+ return |
|
160 |
+ fi |
|
161 |
+ |
|
162 |
+ >"$commit_template_fn" <<EOF |
|
163 |
+abort($issue): |
|
164 |
+EOF |
|
165 |
+ |
|
166 |
+ git commit --allow-empty -t "$commit_template_fn" |
|
167 |
+} |
|
168 |
+ |
|
169 |
+local subcmd=$1 |
|
170 |
+shift |
|
171 |
+ |
|
172 |
+"git-issue-$subcmd" "$@" |