Skip to content

Instantly share code, notes, and snippets.

@lukeledet
Created March 15, 2018 21:46
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 lukeledet/83276df47ce8973d18d24bd5960f3d69 to your computer and use it in GitHub Desktop.
Save lukeledet/83276df47ce8973d18d24bd5960f3d69 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Assign and request a review from someone for a pull request
# Requires GITHUB_OAUTH_TOKEN environment variable
pr_url=""
pr_url_pattern="https://github.com/(.+)/(.+)/pull/(.+)"
while read url
do
pr_url=$url
done < /dev/stdin
if [[ $pr_url =~ $pr_url_pattern ]]
then
curl -d "{\"assignees\": [\"$1\"]}" -H "Authorization: token $GITHUB_OAUTH_TOKEN" https://api.github.com/repos/${BASH_REMATCH[1]}/${BASH_REMATCH[2]}/issues/${BASH_REMATCH[3]}/assignees > /dev/null 2>&1
curl -d "{\"reviewers\": [\"$1\"]}" -H "Authorization: token $GITHUB_OAUTH_TOKEN" https://api.github.com/repos/${BASH_REMATCH[1]}/${BASH_REMATCH[2]}/pulls/${BASH_REMATCH[3]}/requested_reviewers > /dev/null 2>&1
else
echo "Invalid pull request URL"
fi
echo $pr_url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment