Closed zmoog closed 5 months ago
Before dealing with the GitHub API, let's see if we can make it with the GitHub CLI.
The GitHub API docs are really good. Here's the docs for the comments endpoint:
https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#list-issue-comments
It has an example for cURL, JavaScript, and our beloved friend CLI. Here's the CLI one:
# GitHub CLI api
# https://cli.github.com/manual/gh_api
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/OWNER/REPO/issues/ISSUE_NUMBER/comments
I asked GitHub Copilot to generate a little script for me, and in a couple of iterations I got
# Parse script arguments to get the issue number
while getopts ":i:" opt; do
case $opt in
i)
issue_number=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# Check if the issue number is provided
if [ -z "$issue_number" ]; then
echo "Issue number is required (for example, ./dump.sh -i 80)"
exit 1
fi
repo="zmoog/public-notes"
owner="zmoog"
# issue_number="80"
#
# https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#get-an-issue
#
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/$repo/issues/$issue_number | jq -r '.body' > $issue_number.md
#
# https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#list-issue-comments
#
# GitHub CLI api
# https://cli.github.com/manual/gh_api
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
repos/$repo/issues/$issue_number/comments | jq -r '.[].body' >> $issue_number.md
Here's the output for this very issue:
# ./dump.sh -i 82
# cat 82.md | pbcopy
I need to turn the issue threads in this repo into asciidoc documents.
Let's figure out how to:
1. dump an issue thread as .md file
2. convert the .md file to a asciidoc file
I expect to make changes to the asciidoc file, but I want to have a good starting point.
Before dealing with the GitHub API, let's see if we can make it with the GitHub CLI.
The GitHub API docs are really good. Here's the docs for the comments endpoint:
https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#list-issue-comments
It has an example for cURL, JavaScript, and our beloved friend CLI. Here's the CLI one:
```
# GitHub CLI api
# https://cli.github.com/manual/gh_api
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/OWNER/REPO/issues/ISSUE_NUMBER/comments
```
I asked GitHub Copilot to generate a little script for me, and in a couple of iterations I got
```bash
# Parse script arguments to get the issue number
while getopts ":i:" opt; do
case $opt in
i)
issue_number=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# Check if the issue number is provided
if [ -z "$issue_number" ]; then
echo "Issue number is required (for example, ./dump.sh -i 80)"
exit 1
fi
repo="zmoog/public-notes"
owner="zmoog"
# issue_number="80"
#
# https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#get-an-issue
#
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/$repo/issues/$issue_number | jq -r '.body' > $issue_number.md
#
# https://docs.github.com/en/rest/issues/comments?apiVersion=2022-11-28#list-issue-comments
#
# GitHub CLI api
# https://cli.github.com/manual/gh_api
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
repos/$repo/issues/$issue_number/comments | jq -r '.[].body' >> $issue_number.md
```
Not bad.
Now it's time to see how can I turn this into an ASCIIDOC document.
Let's try the goto tool for this kind of tasks, pandoc.
I added one more line at the end of the bash script:
# Convert markdown to asciidoc
pandoc $issue_number.md -o $issue_number.adoc
And the result is pretty good as a first draft to finalize the document!
I need to turn the issue threads in this repo into asciidoc documents.
Let's figure out how to:
I expect to make changes to the asciidoc file, but I want to have a good starting point.