Skip to content

Instantly share code, notes, and snippets.

@PatOConnor43
Created May 11, 2022 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PatOConnor43/196e87f3ada7a35ac6b580907a8c5600 to your computer and use it in GitHub Desktop.
Save PatOConnor43/196e87f3ada7a35ac6b580907a8c5600 to your computer and use it in GitHub Desktop.
A script to open PRs with fzf
### filename: fuzzy-github-prs.sh
### description: A script to open PRs with fzf
# Get the time in seconds 10 days ago
since=$(date -Iseconds -d '10 days ago')
export GH_TOKEN='<YOUR TOKEN WITH NOTIFICATION AND REPO ACCESS>'
export GH_USER='<YOUR USERNAME>'
# Get 10 "notifications" since 10 days ago in json
json=$(curl --silent -u "${GH_USER}":"${GH_TOKEN}" "https://api.github.com/notifications?per_page=10&since=${since}")
# Create tuples from the json using jq to filter for "review_requested". The
# output will look like a list of json objects with title and url.
pairs=$(echo ${json} | jq '.[] | select(.reason == "review_requested") | [{title: .subject.title, url: .subject.url}]')
# Pass the titles into fzf and wait for a selection
selected=$(echo "${pairs}" | jq '.[].title' | fzf-tmux -h 20)
[[ "$selected" = "" ]] && exit
# Re-parse the json and look for the url that matches the title that was
# selected.
selected_url=$(echo ${json} | jq '.[] | select(.subject.title == '"$selected"') | .subject.url' | sed 's/"//g')
# We need to use curl again to get the html url. Then we just use xdg-open (or
# open on Mac) to open the url in our browser. EASY.
curl --silent -u "${GH_USER}":"${GH_TOKEN}" "${selected_url}" | jq '.html_url' | xargs -i{} nohup xdg-open {} > /dev/null 2>&1 &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment