Last active
October 16, 2025 22:10
-
-
Save chr0n1x/a61fc150d352d097169c5e68b3155947 to your computer and use it in GitHub Desktop.
jira-cli wrappers specifically for tracking time spent on issues
This file contains hidden or 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
| # REQUIREMENTS: https://github.com/ankitpokhrel/jira-cli | |
| # also somewhere in your shell env: | |
| # | |
| # export JIRA_API_TOKEN="REPLACEME" | |
| # export JIRA_AUTH_TYPE="bearer" # this goes with the API token above | |
| # export JIRA_SITE="https://jira.private.vpn.corp.com/" | |
| # export JIRA_EDITOR=nvim | |
| # export JIRA_ME_NAME="full name here" # useful for jira-cli commands that accept --no-input | |
| # export JIRA_DEFAULT_ISSUE_TYPE=Story | |
| # export JIRA_DEFAULT_COMPONENT="thingy" | |
| ## INFORMATIONAL FXS | |
| function jira-check-cw-or-err { | |
| if [ -z "$JIRA_CW_ISSUE" ]; then | |
| echo "No JIRA_CW_ISSUE set; try running jira-cw-issue first" | |
| return 1 | |
| fi | |
| } | |
| function jira-check-timer-started-or-err { | |
| if [ -z "$JIRA_WORKING_START_TIME" ]; then | |
| echo "No JIRA_WORKING_START_TIME set; try running jira-timer-start first" | |
| return 1 | |
| fi | |
| } | |
| function jira-cw { | |
| jira-check-cw-or-err || return 1 | |
| jira issue view $JIRA_CW_ISSUE | |
| } | |
| function jira-seconds-working { | |
| jira-check-timer-started-or-err || return 1 | |
| JIRA_WORKING_END_TIME=$(date +%s) | |
| echo $(($JIRA_WORKING_END_TIME - $JIRA_WORKING_START_TIME)) | |
| } | |
| function jira-cws { | |
| jira-check-cw-or-err || return 1 | |
| jira-check-timer-started-or-err || return 1 | |
| JIRA_WORKING_END_TIME=$(date +%s) | |
| echo "Seconds working on $JIRA_CW_ISSUE: $(jira-seconds-working)" | |
| } | |
| ## TIMER / WORKLOG FXS | |
| # set the current-working ("cw") issue ID | |
| # if you were already working on an issue in this same shell with a timer | |
| # going, you have to STOP that timer and log your work first, before changing | |
| # issues | |
| function jira-set-cw { | |
| if [ ! -z "$JIRA_CW_ISSUE" ]; then | |
| if [ "$JIRA_CW_ISSUE" = "$@" ]; then | |
| echo "Already working on $JIRA_CW_ISSUE in this shell" | |
| return 0 | |
| fi | |
| if [ ! -z "$JIRA_WORKING_START_TIME" ]; then | |
| echo "You are currently working on $JIRA_CW_ISSUE; finish up work by running jira-stop, log your time, then run this again to start work on a different ticket." | |
| return 1 | |
| fi | |
| unset JIRA_CW_ISSUE | |
| fi | |
| export JIRA_CW_ISSUE=$@ | |
| } | |
| function jira-timer-start { | |
| jira-check-cw-or-err || return 1 | |
| if [ ! -z "$JIRA_WORKING_START_TIME" ]; then | |
| echo "Timer already started! $(jira-seconds-working) ago!" | |
| return 1 | |
| fi | |
| printf "Working on $JIRA_CW_ISSUE; starting timer @ " | |
| date | |
| export JIRA_WORKING_START_TIME=$(date +%s) | |
| } | |
| function jira-log-work { | |
| COMMENT="$@" | |
| if [ -z "$COMMENT" ]; then | |
| echo "Must provide a comment on what you did!" | |
| return 1 | |
| fi | |
| jira-check-timer-started-or-err || return 1 | |
| secondsSpent=$(jira-seconds-working) | |
| minutesSpent=$(($secondsSpent / 60)) | |
| if [ "$minutesSpent" = "0" ]; then | |
| echo "Can only log work that's > 1 minute" | |
| return 1 | |
| fi | |
| jira issue worklog add \ | |
| $JIRA_CW_ISSUE "${minutesSpent}m" \ | |
| --comment "$COMMENT" --no-input || return 1 | |
| unset JIRA_WORKING_START_TIME | |
| jira-timer-start | |
| } | |
| function jira-stop { | |
| jira-log-work "$@" > /dev/null | |
| unset JIRA_WORKING_START_TIME | |
| } | |
| ## OTHER MISC | |
| function jira-quick-create { | |
| jira issue create \ | |
| --type "$JIRA_DEFAULT_ISSUE_TYPE" \ | |
| --component "$JIRA_DEFAULT_COMPONENT" \ | |
| --assignee "$JIRA_ME_NAME" \ | |
| --summary "$@" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment