#!/bin/bash JIRA_URL="https://joinhonor.atlassian.net" # Check if input string is provided if [ $# -eq 0 ]; then echo "Usage: $0 [--url]" exit 1 fi INPUT_STRING="" SHOW_URL=false # Parse arguments for arg in "$@"; do if [ "$arg" == "--url" ]; then SHOW_URL=true else INPUT_STRING="$arg" fi done # Extract ticket ID using regex (assuming ticket ID format is ABC-123) if [[ $INPUT_STRING =~ ([A-Za-z]+-[0-9]+) ]]; then TICKET_ID=${BASH_REMATCH[1]} else # No valid ticket ID found in input string. exit 2 fi if [ "$SHOW_URL" == true ]; then echo "$JIRA_URL/browse/$TICKET_ID" else JIRA_EMAIL="nagee.elghassein@joinhonor.com" JIRA_API_TOKEN=$(op item get "jira API token" --fields label=password) RESPONSE=$(http --auth "$JIRA_EMAIL:$JIRA_API_TOKEN" GET "$JIRA_URL/rest/api/2/issue/$TICKET_ID") TITLE=$(echo $RESPONSE | jq -r '.fields.summary') # Check if the title was extracted successfully if [ -z "$TITLE" ]; then # Failed to retrieve the ticket title. Please check the ticket ID and API token. exit 3 fi echo $TITLE fi