Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue Key Normalization #43

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/commands/notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ parameters:
description: Override the default project key regexp if your project keys follow a different format. Your key must be in the [1] capture group.
default: ([A-Z]{2,30}-[0-9]+)
type: string
issue_normalize:
description: Normalize the issue regexp to match the default expected value of 'issue_regexp' -- Set slug to uppercase and replace space and underscore with dash.
type: boolean
default: false
pipeline_id:
description: Pass in the pipeline id via CircleCI pipeline parameters. This must be specified manually. Refer to usage example.
type: string
Expand Down Expand Up @@ -67,6 +71,7 @@ steps:
JIRA_VAL_ENVIRONMENT_TYPE: <<parameters.environment_type>>
JIRA_VAL_SERVICE_ID: <<parameters.service_id>>
JIRA_VAL_ISSUE_REGEXP: <<parameters.issue_regexp>>
JIRA_VAL_ISSUE_NORMALIZE: <<parameters.issue_normalize>>
JIRA_VAL_PIPELINE_ID: <<parameters.pipeline_id>>
JIRA_VAL_PIPELINE_NUMBER: <<parameters.pipeline_number>>
JIRA_VAL_JIRA_WEBHOOK_URL: <<parameters.webhook_url>>
Expand Down
13 changes: 10 additions & 3 deletions src/scripts/notify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,15 @@ getSlug() {
# Accepts a string and returns an array of keys
parseKeys() {
local KEY_ARRAY=()
local MATCH
while [[ "$1" =~ $JIRA_VAL_ISSUE_REGEXP ]]; do
KEY_ARRAY+=("${BASH_REMATCH[1]}")
MATCH="${BASH_REMATCH[1]}"
# Check if this match should be normalized
if [[ "$JIRA_VAL_ISSUE_NORMALIZE" -eq 1 ]]; then
# Make uppercase and replace underscore and space with dash
MATCH=$(echo "${MATCH^^}" | tr '_ ' '-')
fi
KEY_ARRAY+=("${MATCH}")
# Remove the matched part from the string so we can continue matching the rest
local rest="${1#*"${BASH_REMATCH[0]}"}"
set -- "$rest"
Expand All @@ -65,7 +72,7 @@ remove_duplicates() {
declare -A seen
# Declare UNIQUE_KEYS as a global variable
UNIQUE_KEYS=()

for value in "$@"; do
# Splitting value into array by space, considering space-separated keys in a single string
for single_value in $value; do
Expand Down Expand Up @@ -121,7 +128,7 @@ getIssueKeys() {
JIRA_ISSUE_KEYS=$(printf '%s\n' "${KEY_ARRAY[@]}" | jq -R . | jq -s .)
echo "Issue keys found:"
echo "$JIRA_ISSUE_KEYS" | jq -r '.[]'

# Export JIRA_ISSUE_KEYS for use in other scripts or sessions
export JIRA_ISSUE_KEYS
}
Expand Down