Created
May 11, 2022 00:31
-
-
Save PatOConnor43/196e87f3ada7a35ac6b580907a8c5600 to your computer and use it in GitHub Desktop.
A script to open PRs with fzf
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
### 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