Skip to content

Commit

Permalink
Merge pull request #4 from mloberg/feature/latest-updated-first
Browse files Browse the repository at this point in the history
feat: show last updated PRs first
  • Loading branch information
mloberg authored Feb 5, 2024
2 parents afb7863 + f8a9ebb commit 7ee9d57
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions gh-prs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ Usage: gh prs
Display an interactive list of open PRs. The selected PR is checked out.
Options:
--list|-l Prints a non-interactive list of open PRs
--help Show this message
--list|-l Prints a non-interactive list of open PRs
--reverse|-r Show oldest PRs first
--help Show this message
Dependencies: fzf
EOF
}

list_prs() {
direction="DESC"
[ "$1" == "1" ] && direction="ASC"

# shellcheck disable=SC2016
gh api graphql --cache=5m -F owner='{owner}' -F repo='{repo}' -f query='
query ($owner: String!, $repo: String!) {
gh api graphql --cache=5m -F owner='{owner}' -F repo='{repo}' -F direction="$direction" -f query='
query ($owner: String!, $repo: String!, $direction: OrderDirection!) {
repository(owner: $owner, name: $repo) {
pullRequests(first: 100, states: [OPEN]) {
pullRequests(first: 100, states: [OPEN], orderBy: { field: UPDATED_AT, direction: $direction }) {
nodes {
number
title
Expand Down Expand Up @@ -53,6 +57,9 @@ while test $# != 0; do
--static|--list|-l)
static=1
;;
--reverse|-r)
reverse=1
;;
*)
help >&2
exit 1
Expand All @@ -62,7 +69,7 @@ while test $# != 0; do
done

if [ -n "$static" ]; then
list_prs
list_prs "$reverse"
exit
fi

Expand All @@ -72,6 +79,6 @@ if ! type -p fzf >/dev/null; then
exit 1
fi

selected=$(fzf --ansi <<<"$(list_prs)")
selected=$(fzf --ansi <<<"$(list_prs "$reverse")")
[ -n "$selected" ] || exit 1
gh pr checkout "${selected%% *}"

0 comments on commit 7ee9d57

Please sign in to comment.