kota's memex

View your current work

gh pr status

Checkout pull request

gh pr checkout 12
gh pr checkout branch-name
gh pr checkout josegpt:go

Create issues and pull requests

gh pr create
gh issue create
gh pr create --web

For current repo

gh repo fork

Listing issues and pull requests

gh pr list
gh issue list
gh pr list --state closed --assignee user

List all changed files in each open pull request

Often times it's nice to see if another open PR edits the same file you're planning on changing. The gh tool exposes github's api directly and handles all the pesky authentication shit for you.

#!/bin/sh
# usage: pr-files portainer/portainer-ee
# or to look at PRs against a specific branch:
# usage: pr-files portainer/portainer-ee release/2.14

if [ -z "$1" ]
then
      echo "error: please provide a repo to search!"
	  exit 1
fi


if [ -z "$2" ]
then
	prs=$(gh search prs -L 100 --repo="$1" --state=open --json number \
		| jq '.[] | .number')
else
	prs=$(gh search prs -L 100 --repo="$1" -B="$2" --state=open --json number \
		| jq '.[] | .number')
fi


for pr in $prs; do
	files=$(gh api \
	  -H "Accept: application/vnd.github+json" \
	  /repos/portainer/portainer-ee/pulls/"$pr"/files | jq -r '.[] | .filename')

	for file in $files; do
		echo "$pr" "$file"
	done
done

Get a diff for every open PR on a repo

On a very similar note, sometimes I want to search through all "changes" being made in every open PR. This script downloads a diff of every open PR and stores it in /tmp/pr-diffs/username/repo which I can then search with rg or whatever:

#!/bin/sh
# usage: pr-diffs portainer/portainer-ee
# or to look at PRs against a specific branch:
# usage: pr-files portainer/portainer-ee release/2.14
#
# Diffs will be stored in /tmp/pr-diffs/portainer/portainer-ee/
# You can search this new directory with ripgrep or whatever now!

if [ -z "$1" ]
then
      echo "error: please provide a repo to search!"
	  exit 1
fi

if [ -z "$2" ]
then
	prs=$(gh search prs -L 100 --repo="$1" --state=open --json number \
		| jq '.[] | .number')
else
	prs=$(gh search prs -L 100 --repo="$1" -B="$2" --state=open --json number \
		| jq '.[] | .number')
fi

dir=/tmp/pr-diffs/"$1"
rm -rf "$dir"
mkdir -p "$dir"

for pr in $prs; do
	gh pr diff -R "$1" "$pr" > "$dir"/"$pr".diff
done