forked from btdig/dhtcrawler2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchive-github-issues.sh
executable file
·119 lines (111 loc) · 4.5 KB
/
archive-github-issues.sh
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
#! /usr/bin/env bash
set -e
set -u
set -x
# check dependencies
git --version
gh2md --version
pandoc --version
if ! (git branch --format="%(refname)" | grep -q -x "refs/heads/github-issues"); then
echo creating orphan branch github-issues
git branch --copy master master-temp-copy
git worktree add github-issues master-temp-copy
git -C github-issues switch --orphan github-issues
git branch --delete master-temp-copy
else
echo mounting branch github-issues
git worktree add github-issues github-issues || true
fi
# run gh2md
git -C github-issues rm -rf ghmd || true
rm -rf github-issues/ghmd || true
gh2md --multiple-files --file-extension .ghmd --idempotent btdig/dhtcrawler2 github-issues/ghmd
# convert ghmd to md files
git -C github-issues rm -rf md || true
rm -rf github-issues/md || true
mkdir github-issues/md || true
find github-issues/ghmd -type f -name "*.ghmd" | while read ghmd_path; do
md_path=${ghmd_path%.*}.md
md_path=github-issues/md/${md_path#*/*/}
pandoc -f gfm -t commonmark "$ghmd_path" -o "$md_path" --wrap=none
done
# remove ghmd files to save space
git -C github-issues rm -rf ghmd || true
rm -rf github-issues/ghmd || true
# generate index file
# workaround for https://github.com/mattduck/gh2md/issues/33
(
#echo "# github issues"
#echo
# loop sections
# TODO add more sections
# TODO? generate multiple index files, one file per section
# FIXME skip empty sections
for selector in "open issue" "closed issue" "merged pr"; do
section="${selector}s"
selected_status=${selector% *}
selected_type=${selector#* }
echo "<h2>$section</h2>"
echo '<details>'
echo "<summary>$section</summary>"
echo '<table>'
find github-issues/md -type f -name "*.$selected_type.$selected_status.md" | sort -n --reverse | while read md_path; do
# 2021-06-16.1.pr.merged.md 2023-08-07.2.issue.open.md 2023-08-07.3.issue.open.md 2023-08-08.4.issue.open.md
md_name=$(basename "$md_path")
md_url="md/$md_name"
number=$(echo "$md_name" | cut -d. -f 2)
type=$(echo "$md_name" | cut -d. -f 3) # "pr" or "issue"
status=$(echo "$md_name" | cut -d. -f 4) # pr: merged/?/?, issue: open/?
num_comments=$(cat "$md_path" | grep -E '^#### <img src="https://avatars\.githubusercontent\.com/u/[0-9]+\?v=[0-9]+" width="50">\[.*?\]\(https://github.com/.*?\) commented at \[.*\):$' | wc -l)
text=$(pandoc -f commonmark -t plain --wrap=none "$md_path")
title=$(echo "$text" | head -n1 | cut -d' ' -f4-)
author=$(echo "$text" | head -n3 | tail -n1 | cut -d' ' -f1)
datetime=$(echo "$text" | head -n3 | tail -n1 | cut -d' ' -f5-6 | sed 's/:$//')
# FIXME: use only the first comment
start=$(echo "$text" | tail -n +5 | head -c 200)
start_escaped=$(echo "$start" | sed 's/"/\"/g' | perl -0777 -pe 's/\n/ /g')
# debug
echo "start: $start" >&2
echo "start_escaped: $start_escaped" >&2
#echo '<tr>'
if false; then
# column: icon
if [[ "$type" == "issue" ]]; then
if [[ "$status" == "open" ]]; then
echo '<td><svg class="octicon octicon-issue-opened open" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="M8 9.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z"></path><path d="M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM1.5 8a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0Z"></path></svg></td>'
else
echo '<td>TODO icon</td>'
fi
else
echo '<td>TODO icon</td>'
fi
else
# column: type
#echo "<td>$type</td>"
# column: status
#echo "<td>$status</td>"
# column: status + type
#echo "<td>$status $type</td>"
:
fi
# column: title, number, date, author
#echo "<td><b><a href=\"$md_url\">$title</a></b><br>#$number opened on $datetime by $author</td>"
comments_str=$(if ((num_comments > 0)); then echo " 💬 $num_comments"; else echo ""; fi)
echo "<tr><td><b><a href=\"$md_url\" title=\"$start_escaped\">$title</a></b><br>#$number opened on $datetime by $author$comments_str</td></tr>"
# column: number of replies
# https://www.fileformat.info/info/unicode/char/1f4ac/index.htm
if false; then
if ((num_comments > 0)); then
echo "<td>💬 $num_comments</td>"
else
echo "<td></td>"
fi
fi
#echo '</tr>'
done
echo '</table>'
echo '</details>'
done
) >github-issues/readme.md
git -C github-issues add .
git -C github-issues commit -m "update github issues"