Last active
July 24, 2024 14:18
-
-
Save glenrobertson/66f478483e1f971f43f62414f222c4b6 to your computer and use it in GitHub Desktop.
Create git branch for JIRA issue and mark in progress
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
export JIRA_USERNAME="JIRA_EMAIL"; | |
export JIRA_API_KEY="API_KEY"; # Get key at https://id.atlassian.com/manage-profile/security | |
export JIRA_DOMAIN="example.atlassian.net" | |
export JIRA_PROJECT="PROJECT" | |
function j() { | |
git add .; | |
git stash; | |
local ticket_id="$JIRA_PROJECT-$1" | |
if ! git checkout -b $ticket_id 2>/dev/null; then | |
echo "branch $ticket_id exists. checking out"; | |
git checkout "$ticket_id"; | |
else | |
echo "branch $ticket_id does not exist. creating" | |
# Find transition ID for in progress at: | |
# https://$JIRA_DOMAIN/rest/api/2/issue/$TICKET_ID/transitions | |
local transition_id="21" # This may vary in your JIRA instance | |
echo "marking JIRA $ticket_id in progress" | |
curl -s -w "%{http_code}" \ | |
-u "${JIRA_USERNAME}:${JIRA_API_KEY}" \ | |
-X POST \ | |
-H "Content-Type: application/json" \ | |
-d "{\"transition\": {\"id\": \"${transition_id}\"}}" \ | |
"https://${JIRA_DOMAIN}/rest/api/2/issue/${ticket_id}/transitions" | |
fi; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment