Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
export GITHUB_REPO="user/repo"
export GITHUB_USERNAME=$(cat ~/.githubrc 2> /dev/null | grep user.login | cut -d ":" -f2 | xargs)
export GITHUB_PASSWORD=$(cat ~/.githubrc 2> /dev/null | grep user.password | cut -d ":" -f2 | xargs)
if [ -z "$GITHUB_USERNAME" ]
then
read -p "Type your Github username: " GITHUB_USERNAME
echo "user.login: $GITHUB_USERNAME" >> ~/.githubrc
fi
if [ -z "$GITHUB_PASSWORD" ]
then
read -p "Type your Github password (won't be shown): " -s GITHUB_PASSWORD
echo "user.password: $GITHUB_PASSWORD" >> ~/.githubrc
fi
read -p "Type the issue id: " ISSUE_ID
git checkout master
git pull origin master
git checkout -b issue-$ISSUE_ID
export LABEL="Stage: In progress"
response=$(curl -u "$GITHUB_USERNAME:$GITHUB_PASSWORD" -sL "https://api.github.com/repos/$GITHUB_REPO/issues/$ISSUE_ID/labels" -X "POST" -d "[\"$LABEL\"]")
if [[ "$response" == *"errors"* ]]; then
echo "Error adding label"
else
echo "Label $LABEL added"
fi
response=$(curl -u "$GITHUB_USERNAME:$GITHUB_PASSWORD" -sL "https://api.github.com/repos/$GITHUB_REPO/issues/$ISSUE_ID/assignees" -X "POST" -d "{\"assignees\": [\"$GITHUB_USERNAME\"]}")
if [[ "$response" == *"errors"* ]]; then
echo "Error adding label"
else
echo "$GITHUB_USERNAME assigned to issue"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment