Skip to content

Instantly share code, notes, and snippets.

@ntindle
Created July 22, 2023 20:40
Show Gist options
  • Save ntindle/0e23168494b04659296a900111bc8409 to your computer and use it in GitHub Desktop.
Save ntindle/0e23168494b04659296a900111bc8409 to your computer and use it in GitHub Desktop.
Gets a random issue from a GitHub repo
#!/bin/bash
# Parse command line arguments
for i in "$@"
do
case $i in
--repo=*)
REPO="${i#*=}"
shift
;;
*)
# unknown option
;;
esac
done
# Check if repo was provided
if [ -z "$REPO" ]
then
echo "Error: No repository provided. Use --repo=\"https://github.com/user/repo\""
exit 1
fi
# Extract user and repo from URL
USER_REPO=$(echo $REPO | awk -F'https://github.com/' '{print $2}')
# Fetch issues from repository
ISSUES=$(gh issue list -R $USER_REPO)
# Check if there are any issues
if [ -z "$ISSUES" ]
then
echo "No issues found in repository $REPO"
exit 1
fi
# Select random issue
RANDOM_ISSUE=$(echo "$ISSUES" | shuf -n 1)
# Extract issue number
ISSUE_NUMBER=$(echo $RANDOM_ISSUE | awk '{print $1}')
# Output URL of random issue
echo "https://github.com/$USER_REPO/issues/$ISSUE_NUMBER"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment