Created
July 22, 2023 20:40
-
-
Save ntindle/0e23168494b04659296a900111bc8409 to your computer and use it in GitHub Desktop.
Gets a random issue from a GitHub repo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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