Skip to content

Commit 3b4e511

Browse files
[ISV-5448] FBC Catalog changes include Operators in the PR Title. (#752)
1 parent 95cb624 commit 3b4e511

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

ansible/roles/operator-pipeline/templates/openshift/pipelines/operator-hosted-pipeline.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,8 @@ spec:
385385
value: "$(tasks.detect-changes.results.added_bundle)"
386386
- name: affected_catalogs
387387
value: "$(tasks.detect-changes.results.affected_catalogs)"
388+
- name: affected_catalog_operators
389+
value: "$(tasks.detect-changes.results.affected_catalog_operators)"
388390
- name: github_token_secret_name
389391
value: "$(params.github_token_secret_name)"
390392
- name: github_token_secret_key

ansible/roles/operator-pipeline/templates/openshift/tasks/set-github-pr-title.yaml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ spec:
2020
- name: affected_catalogs
2121
description: Comma separated list of updated catalogs
2222

23+
- name: affected_catalog_operators
24+
description: Comma separated list of operators inside all catalogs
25+
2326
- name: github_token_secret_name
2427
description: The name of the Kubernetes Secret that contains the GitHub token.
2528
default: github
@@ -52,8 +55,45 @@ spec:
5255
TITLE="operator $(params.operator_name) ($(params.bundle_version))"
5356
5457
elif [[ "$(params.affected_catalogs)" != "" ]]; then
55-
# Update of catalogs only
56-
TITLE="Catalog update [$(params.affected_catalogs)]"
58+
# Update of catalogs only, can get quite long
59+
60+
# Limit that is shown by GH API
61+
MAX_TITLE_LEN=256
62+
63+
TITLE_BEGINNING="Catalog update ["
64+
TITLE_ENDING="] [$(params.affected_catalogs)]"
65+
66+
# Catalog Operators are in the following format:
67+
# catalogVersion1/operator1,catalogVersion2/operator1,...
68+
# We need to trim Catalog version from all operators in 5 steps:
69+
# Step 1: split operators
70+
IFS=',' read -ra RAW_OPERATOR_ARR <<< "$(params.affected_catalog_operators)"
71+
unset IFS
72+
OPERATOR_ARR=()
73+
74+
# Step 2: Remove everything before the first '/' in each operator
75+
for OPERATOR in "${RAW_OPERATOR_ARR[@]}"; do
76+
OPERATOR_ARR+=("${OPERATOR#*/}")
77+
done
78+
79+
# Step 3: dedup the array
80+
IFS=' ' read -ra OPERATOR_ARR <<< "$(echo "${OPERATOR_ARR[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')"
81+
unset IFS
82+
83+
# Step 4: Join operator names back
84+
TITLE_MIDDLE=$(printf ",%s" "${OPERATOR_ARR[@]}")
85+
86+
# Step 5: Remove the heading ','
87+
TITLE_MIDDLE="${TITLE_MIDDLE:1}"
88+
89+
FREE_CAPACITY=$(( "${MAX_TITLE_LEN}" - $(echo "${TITLE_BEGINNING}" | wc -m) - $( echo "${TITLE_ENDING}" | wc -m) ))
90+
91+
# Shorten the middle part if it is too long
92+
if [[ $(echo "${TITLE_MIDDLE}" | wc -m) -gt "${FREE_CAPACITY}" ]]; then
93+
CUT_TO_LENGTH=$(( "${FREE_CAPACITY}" - 3 ))
94+
TITLE_MIDDLE="${TITLE_MIDDLE::${CUT_TO_LENGTH}}..."
95+
fi
96+
TITLE="${TITLE_BEGINNING}${TITLE_MIDDLE}${TITLE_ENDING}"
5797
5898
else
5999
echo "No bundles nor catalogs have been added/updated"

0 commit comments

Comments
 (0)