Skip to content

Commit

Permalink
[ISV-5448] FBC Catalog changes include Operators in the PR Title. (#752)
Browse files Browse the repository at this point in the history
  • Loading branch information
BorekZnovustvoritel authored Dec 5, 2024
1 parent 95cb624 commit 3b4e511
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ spec:
value: "$(tasks.detect-changes.results.added_bundle)"
- name: affected_catalogs
value: "$(tasks.detect-changes.results.affected_catalogs)"
- name: affected_catalog_operators
value: "$(tasks.detect-changes.results.affected_catalog_operators)"
- name: github_token_secret_name
value: "$(params.github_token_secret_name)"
- name: github_token_secret_key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ spec:
- name: affected_catalogs
description: Comma separated list of updated catalogs

- name: affected_catalog_operators
description: Comma separated list of operators inside all catalogs

- name: github_token_secret_name
description: The name of the Kubernetes Secret that contains the GitHub token.
default: github
Expand Down Expand Up @@ -52,8 +55,45 @@ spec:
TITLE="operator $(params.operator_name) ($(params.bundle_version))"
elif [[ "$(params.affected_catalogs)" != "" ]]; then
# Update of catalogs only
TITLE="Catalog update [$(params.affected_catalogs)]"
# Update of catalogs only, can get quite long
# Limit that is shown by GH API
MAX_TITLE_LEN=256
TITLE_BEGINNING="Catalog update ["
TITLE_ENDING="] [$(params.affected_catalogs)]"
# Catalog Operators are in the following format:
# catalogVersion1/operator1,catalogVersion2/operator1,...
# We need to trim Catalog version from all operators in 5 steps:
# Step 1: split operators
IFS=',' read -ra RAW_OPERATOR_ARR <<< "$(params.affected_catalog_operators)"
unset IFS
OPERATOR_ARR=()
# Step 2: Remove everything before the first '/' in each operator
for OPERATOR in "${RAW_OPERATOR_ARR[@]}"; do
OPERATOR_ARR+=("${OPERATOR#*/}")
done
# Step 3: dedup the array
IFS=' ' read -ra OPERATOR_ARR <<< "$(echo "${OPERATOR_ARR[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')"
unset IFS
# Step 4: Join operator names back
TITLE_MIDDLE=$(printf ",%s" "${OPERATOR_ARR[@]}")
# Step 5: Remove the heading ','
TITLE_MIDDLE="${TITLE_MIDDLE:1}"
FREE_CAPACITY=$(( "${MAX_TITLE_LEN}" - $(echo "${TITLE_BEGINNING}" | wc -m) - $( echo "${TITLE_ENDING}" | wc -m) ))
# Shorten the middle part if it is too long
if [[ $(echo "${TITLE_MIDDLE}" | wc -m) -gt "${FREE_CAPACITY}" ]]; then
CUT_TO_LENGTH=$(( "${FREE_CAPACITY}" - 3 ))
TITLE_MIDDLE="${TITLE_MIDDLE::${CUT_TO_LENGTH}}..."
fi
TITLE="${TITLE_BEGINNING}${TITLE_MIDDLE}${TITLE_ENDING}"
else
echo "No bundles nor catalogs have been added/updated"
Expand Down

0 comments on commit 3b4e511

Please sign in to comment.