Last active
January 14, 2022 15:54
-
-
Save airburst/5ed30ae4c495cbfd686b197a3d128cde to your computer and use it in GitHub Desktop.
Simple CLI to create Jira issue stub
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
#!/bin/bash | |
################################################################## | |
# Step 1: Sign in to Jira and create an API token at this link: | |
# https://id.atlassian.com/manage-profile/security/api-tokens | |
# | |
# Step 2: Create a file named ~/.jiraconfig and add the following: | |
# JIRA_USER={fname.lname@simplybusiness.co.uk} | |
# JIRA_API_TOKEN={your-api-token} | |
# JIRA_PROJECT_KEY={jira-project-key} e.g. FETT | |
# | |
# Step 3: Copy this script to e.g. ~/bin/story | |
# chmod +x ~/bin/story | |
# optionally add an alias in .zshrc or .bashrc or add ~/bin to PATH | |
# | |
# Usage: story "Summary text" ["Longer description text"] | |
################################################################## | |
# Set config file path | |
CONFIG_FILE=~/.jiraconfig | |
BASE_URL=https://simplybusiness.atlassian.net/rest/api/2 | |
if test -f "$CONFIG_FILE"; then | |
# Get ids from config file | |
source $CONFIG_FILE | |
# Check that we have at least one argument for summary | |
if [ $# -eq 0 ]; then | |
echo "No summary provided" | |
echo "Required pattern is: story \"Summary\" [\"Description\"]" | |
exit 1 | |
fi | |
# Template payload to create story | |
template='{ | |
"fields": { | |
"project": { "key": "%s" }, | |
"summary": "%s", | |
"description": "%s", | |
"issuetype": { "name": "Story" } | |
} | |
}' | |
json_data=$(printf "$template" "$JIRA_PROJECT_KEY" "$1" "$2") | |
curl -s -X POST \ | |
-u $JIRA_USER:$JIRA_API_TOKEN \ | |
-H "Content-Type:application/json" \ | |
--data "$json_data" \ | |
$BASE_URL/issue/ | |
else | |
echo "JIRA config file $CONFIG_FILE does not exist" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment