Skip to content

Instantly share code, notes, and snippets.

@ryuheechul
Last active September 16, 2022 16:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryuheechul/4a7f9cc76fec34dd6b63de85a022f991 to your computer and use it in GitHub Desktop.
Save ryuheechul/4a7f9cc76fec34dd6b63de85a022f991 to your computer and use it in GitHub Desktop.
a helper to bootstrap stand-ups messages quickly by fetching data from Jira and render for editing and pasting
# vim: set ft=zsh:
## You are suppose to source this file from your shell - tested on zsh and might work with bash as well
# like `source [this_file]`
# You can turn this into scripts if that's more of your taste
## binary dependancies
# - https://github.com/stedolan/jq # json processor
# - https://github.com/charmbracelet/glow # markdown render on cli
# - https://github.com/httpie/httpie # A command line HTTP client whose goal is to make CLI human-friendly
# - https://gitlab.com/saalen/ansifilter # ANSI sequence filter - like [ansi2txt](https://github.com/kilobyte/colorized-logs)
# - https://github.com/antonmedv/fx # (optional) json viewer (for debuging)
# - https://github.com/ankitpokhrel/jira-cli # (optional) jira cli
## export these either here or prior to source this file
## also hard code values if the construction logic doesn't work for you
# I'm just following the same naiming here from the jira cli above
export JIRA_API_TOKEN=gEtYouRaPItoKen
# other names here is just arbitrary choice of mine
export MY_JIRA_USER_NAME='your.username'
export MY_JIRA_ORG_NAME='your_org'
export MY_JIRA_EMAIL="${MY_JIRA_USER_NAME}@${MY_JIRA_ORG_NAME}.com"
export MY_JIRA_HOST="https://${MY_JIRA_ORG_NAME}.atlassian.net"
# the jql here works for me and you might want to change that for your liking
# also this only works after you go through `jira init`, but this is optional anyway
alias myjira="jira issue list -q='assignee = ${MY_JIRA_USER_NAME} AND status != done AND status != backlog AND type != epic' --order-by=updated"
# a url that would be used by a command like `curl` or `http(ie)` based on jql above and it is easily extractable from `jira` CLI following https://github.com/ankitpokhrel/jira-cli/issues/228#issuecomment-1098281201
jira_request_url="${MY_JIRA_HOST}"'/rest/api/3/search?jql=assignee+%3D+'"${MY_JIRA_USER_NAME}"'+AND+status+%21%3D+done+AND+status+%21%3D+backlog+AND+type+%21%3D+epic+ORDER+BY+updated+DESC&maxResults=100'
# helpful for debuging
debug-json-result-of-my-jira() {
http get \
"${jira_request_url}" \
--auth="${MY_JIRA_EMAIL}:${JIRA_API_TOKEN}" | jq '.issues[0]' | fx
}
# restructure to have a compact format
json-summary-of-my-jira() {
# extract key informations only
jq_code='[.issues[] | {key: .key, type: .fields.issuetype.name, summary: .fields.summary, status: .fields.status.name, updated: .fields.updated }]'
http get "${jira_request_url}" \
--auth="${MY_JIRA_EMAIL}:${JIRA_API_TOKEN}" | jq "${jq_code}"
}
# using the json result from above to edit
write-standup-from-jira() {
# create a temp file
tmp_file="$(mktemp --suffix='.md')"
# change format here
jq_code='.[] | "- \(.key): \(.summary) [\(.status)] - \(.updated)"'
# print in markdown format and save to the temp file
json-summary-of-my-jira | jq -r "${jq_code}" > "${tmp_file}"
# open editor to edit - in case it's (neo)vim, edit and save and quit to go to the next step
${EDITOR} "${tmp_file}"
# search the glow binary that is not alias (this might not be necessary for you but to me it is)
glow_cmd="$(which glow | grep -v alias | head | tr -d '\n')"
# this will render markdown format to be more pastable format (to slack, for example) it also copies to clipboard as well as printing to stdout
${glow_cmd:-glow} -w 500 -s dark "${tmp_file}" \
| ansifilter | sed 's/[ \t]*$//' | sed '/^$/d' | cut -c 3- \
| tee /dev/tty | pbcopy
}
# if you have all the dependencies and run `write-standup-from-jira` on the terminal, you will see what I mean
@ryuheechul
Copy link
Author

sed '/^$/d' - delete empty line - https://www.cyberciti.biz/faq/using-sed-to-delete-empty-lines/
sed 's/[ \t]*$//' - remove trailing white space - https://stackoverflow.com/a/4438318/1570165

@ryuheechul
Copy link
Author

cat ~/.config/.jira/.config.yml to check which board and project is being used

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