mattduck / gh2md

Export Github repository issues, pull requests and comments to markdown.
MIT License
254 stars 45 forks source link

with --multiple-files, generate readme.md index file #33

Open milahu opened 2 years ago

milahu commented 2 years ago

for better navigation

navigating an anonymous file list like

2020-09-22.1.issue.closed.md
2020-09-22.2.issue.closed.md
2020-11-04.3.issue.closed.md
2021-07-31.4.issue.open.md
2022-05-31.7.issue.open.md
2022-06-01.8.issue.open.md
2022-06-05.9.issue.open.md

is not user friendly

milahu commented 1 year ago

workaround in bash: archive-github-issues.sh

archive-github-issues.sh ```sh #! /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 "

$section

" echo '
' echo "$section" echo '' 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 '^#### \[.*?\]\(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 '' if false; then # column: icon if [[ "$type" == "issue" ]]; then if [[ "$status" == "open" ]]; then echo '' else echo '' fi else echo '' fi else # column: type #echo "" # column: status #echo "" # column: status + type #echo "" : fi # column: title, number, date, author #echo "" comments_str=$(if ((num_comments > 0)); then echo " 💬 $num_comments"; else echo ""; fi) echo "" # column: number of replies # https://www.fileformat.info/info/unicode/char/1f4ac/index.htm if false; then if ((num_comments > 0)); then echo "" else echo "" fi fi #echo '' done echo '
TODO iconTODO icon$type$status$status $type$title
#$number opened on $datetime by $author
$title
#$number opened on $datetime by $author$comments_str
💬 $num_comments
' echo '
' done ) >github-issues/readme.md git -C github-issues add . git -C github-issues commit -m "update github issues" ```

example result: github-issues