Shell Script to Open GitHub Issues Updated in the Last n Hours in Browser

Tadashi Shigeoka ·  Sat, October 21, 2023

I’ll introduce a shell script that opens GitHub issues updated in the last n hours in a browser.

GitHub

Background: Creating Daily Reports with GitHub Issues

Since I started creating daily reports with GitHub issues, I needed a way to batch open and read issues updated within the last day.

Sample Shell Script to Batch Open GitHub Issues Updated After 22:00 the Previous Day

Environment

  • macOS 13.5.2
  • zsh 5.9 (x86_64-apple-darwin22.0)
## Please change the values of the following variables as appropriate before execution
# Get issues updated after 22:00 the previous day
previous_date=$(date -v-1d "+%Y-%m-%dT22:00:00+09:00")
# Repository name to fetch
gh_repo_name="codenote-net/sandbox"

gh_updated_date="$previous_date"

# Save the output of `gh issue list` to a variable
issue_list=$(gh issue list --repo "$gh_repo_name" --search "updated:>$gh_updated_date" --state all --limit 1000)

base_url="https://github.com/$gh_repo_name/issues/"

# Extract the first number, combine URLs, and open in browser
echo "$issue_list" | awk '{print $1}' | while read -r issue_num; do
    open "${base_url}${issue_num}"
    sleep 1
done

That’s all from the Gemba, where I created a shell script to batch open GitHub issues updated in the last n hours in a browser.