Skip to content

Instantly share code, notes, and snippets.

@Antoniozinchenko
Last active October 8, 2024 13:22
Show Gist options
  • Save Antoniozinchenko/300587670a18002e891672fbea032c43 to your computer and use it in GitHub Desktop.
Save Antoniozinchenko/300587670a18002e891672fbea032c43 to your computer and use it in GitHub Desktop.
# generate jira api token with your account here https://id.atlassian.com/manage-profile/security/api-tokens
export JIRA_API_TOKEN=<YOUR_API_TOKEN_HERE>
# get current jira issue title
jira_title()
{
BRANCH=$(git branch --show-current)
jira issue view "$BRANCH" --plain | sed -n '1p' | awk '{print $2}'
ISSUE_TITLE=$(jira issue view "$BRANCH" --plain | grep '#' | sed -n '1 p' | sed 's/#//' | awk '$1=$1')
echo "[$BRANCH] $ISSUE_TITLE"
}
# do git checkout to current active jira issue
jirastart()
{
BRANCH=$(jira issue list -s "In Progress" -a$(jira me) --plain --columns key | sed -n '2 p')
git co $BRANCH || git co -b $BRANCH
}
jiracommit()
{
git add .
MESSAGE=$(jira_title)
git commit -m "$MESSAGE"
}
# find ticket by branch name and move to "In Review" status
jirareview()
{
jira issue move $(git branch --show-current) "<YOUR_JIRA_STATUS_HERE>"
}
# do commit and create pull request with current jira issue
jirapush()
{
jiracommit
git push -u origin $(git branch --show-current)
gh pr create --title "$(git log -1 --pretty=%B)" --body "https://<YOUR_JIRA_DOMAIN>.atlassian.net/browse/$(git branch --show-current)"
if [[ $1 == "--review" ]]; then
jirareview
fi
}
@Antoniozinchenko
Copy link
Author

Antoniozinchenko commented Sep 20, 2024

CLI shortcuts for working with your jira


install jira-cli and qithub cli (gh) before you start


just use jirastart for finding first your jira issue which has status 'In Progress' and do git checkout with correct branch name

$ jirastart

when you finish with code edit just run jirapush for making commit and create pull request with issue title

$ jirapush

if your want also to move ticket in jira board, just add --review flag

$ jirapush --review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment