Skip to content

Commit e2d3ff3

Browse files
committed
refactor(RELEASE-2475): convert close-advisory-issues to python
This commit replaces the inline task script for the close-advisory-issues managed task with a standalone python script contained in the utils image. The tekton unit tests are updated accordingly. We only keep one happy path test as the other scenarios are covered by pytest in the utils repo. Assisted-By: Cursor Signed-off-by: Johnny Bieren <jbieren@redhat.com>
1 parent 8556582 commit e2d3ff3

10 files changed

Lines changed: 36 additions & 807 deletions

tasks/managed/close-advisory-issues/close-advisory-issues.yaml

Lines changed: 11 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ spec:
121121
- name: sourceDataArtifact
122122
value: $(params.sourceDataArtifact)
123123
- name: close-issues
124-
image: quay.io/konflux-ci/release-service-utils@sha256:5546fa78d3c88d7b6a2e8cff8902f7757f00541d0bbaf113b9f293133894afa3
124+
image: quay.io/jbieren/release-service-utils:closeissues_2
125125
computeResources:
126126
limits:
127127
memory: 32Mi
@@ -131,86 +131,16 @@ spec:
131131
volumeMounts:
132132
- name: access-token-secret-vol
133133
mountPath: "/etc/secrets"
134-
script: |
135-
#!/usr/bin/env bash
136-
# We do not set -x here because it would leak the ACCESS_TOKEN
137-
set -eu
138-
139-
ACCESS_TOKEN="$(cat /etc/secrets/token)"
140-
EMAIL="$(cat /etc/secrets/email)"
141-
142-
ISSUE_TRACKERS='{
143-
"Jira": {
144-
"api": "rest/api/2/issue",
145-
"servers": [
146-
"issues.redhat.com",
147-
"jira.atlassian.com",
148-
"redhat.atlassian.net"
149-
]
150-
},
151-
"bugzilla": {
152-
"api": "rest/bug",
153-
"servers": [
154-
"bugzilla.redhat.com"
155-
]
156-
}
157-
}'
158-
159-
DATA_FILE="$(params.dataDir)/$(params.dataPath)"
160-
if [ ! -f "${DATA_FILE}" ] ; then
161-
echo "No data JSON was provided."
162-
exit 1
163-
fi
164-
165-
NUM_ISSUES=$(jq -cr '.releaseNotes.issues.fixed | length' "${DATA_FILE}")
166-
for ((i = 0; i < NUM_ISSUES; i++)); do
167-
issue=$(jq -c --argjson i "$i" '.releaseNotes.issues.fixed[$i]' "${DATA_FILE}")
168-
server=$(jq -r '.source' <<< "$issue")
169-
if [ "$server" = "issues.redhat.com" ] ; then
170-
server=redhat.atlassian.net
171-
fi
172-
if [ "$server" != "redhat.atlassian.net" ] ; then
173-
echo "This task currently only supports closing issues on issues.redhat.com"
174-
echo "and redhat.atlassian.net. Skipping issue $issue as it is on $server"
175-
continue
176-
fi
177-
178-
CURL_ARGS=(-u "${EMAIL}:${ACCESS_TOKEN}")
179-
180-
API=$(jq -r '.[] | select(.servers[] | contains("'"$server"'")) | .api' <<< "$ISSUE_TRACKERS")
181-
API_URL="https://${server}/${API}/$(jq -r '.id' <<< "$issue")"
182-
183-
if [ "$(curl-with-retry "${CURL_ARGS[@]}" "${API_URL}" | jq -r '.fields.status.name')" == "Closed" ] ; then
184-
echo "Issue $issue is already in Closed state. Skipping it."
185-
continue
186-
fi
187-
188-
echo "Closing issue $issue"
189-
CLOSE_COMMENT="Fixed in Konflux Advisory $(params.advisoryUrl)"
190-
CLOSING_RC=0
191-
# Get the Closed transition id. This varies per Jira project
192-
if ! CLOSED_ID="$(curl-with-retry "${CURL_ARGS[@]}" "${API_URL}/transitions" \
193-
| jq -er '.transitions[] | select(.name=="Closed") | .id')"; then
194-
echo "Warning: failed to fetch the closed state id for issue $issue. We most likely do not have" \
195-
"permission to close it. Will try to add a comment instead."
196-
CLOSING_RC=1
197-
# Close the issue
198-
elif ! curl-with-retry "${CURL_ARGS[@]}" -XPOST --data \
199-
'{"transition":{"id":"'"$CLOSED_ID"'"},"update":{"comment":[{"add":{"body":"'"$CLOSE_COMMENT"'"}}]}}' \
200-
-H "Content-Type: application/json" "${API_URL}/transitions"; then
201-
echo "Warning: failed to close issue $issue. Will try to add a comment instead."
202-
CLOSING_RC=1
203-
fi
204-
205-
if [ "$CLOSING_RC" -ne 0 ] ; then
206-
# Try to add the comment even if closing failed
207-
if ! curl-with-retry "${CURL_ARGS[@]}" -XPOST --data \
208-
'{"body":"'"$CLOSE_COMMENT"'"}' \
209-
-H "Content-Type: application/json" "${API_URL}/comment"; then
210-
echo "Warning: failed to add comment to issue $issue."
211-
fi
212-
fi
213-
done
134+
env:
135+
- name: PARAM_DATA_DIR
136+
value: $(params.dataDir)
137+
- name: PARAM_DATA_PATH
138+
value: $(params.dataPath)
139+
- name: PARAM_ADVISORY_URL
140+
value: $(params.advisoryUrl)
141+
- name: JIRA_SECRET_PATH
142+
value: /etc/secrets
143+
command: ["/home/scripts/python/tasks/managed/close_advisory_issues.py"]
214144
- name: create-trusted-artifact
215145
computeResources:
216146
limits:

tasks/managed/close-advisory-issues/tests/mocks.sh

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
# Declarative mocks for Tekton tests of this task (Python entrypoint). Rendered
3+
# by .github/scripts/render_python_task_mocks_from_yaml.py when
4+
# test_tekton_tasks.sh runs.
5+
version: 1
6+
services:
7+
- type: http_json
8+
port: 8080
9+
bind: 127.0.0.1
10+
mock_server_for_env_var: JIRA_API_BASE_URL
11+
mock_server_api_path: ""
12+
routes:
13+
- path_contains: /issue/ISSUE-123/transitions
14+
method: POST
15+
body: '{}'
16+
- path_contains: /issue/ISSUE-123/transitions
17+
method: GET
18+
body: '{"transitions":[{"id":"91","name":"Closed","description":""},{"id":"11","name":"New"}]}'
19+
- path_contains: /issue/ISSUE-123
20+
method: GET
21+
body: '{"fields":{"status":{"name":"Open"}}}'
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
#!/usr/bin/env bash
22

3-
# Add mocks to the beginning of task step script
4-
TASK_PATH="$1"
5-
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
6-
yq -i '.spec.steps[1].script = load_str("'$SCRIPT_DIR'/mocks.sh") + .spec.steps[1].script' "$TASK_PATH"
7-
83
# Create a dummy access token secret (and delete it first if it exists)
94
kubectl delete secret konflux-advisory-jira-secret --ignore-not-found
105
kubectl create secret generic konflux-advisory-jira-secret --from-literal=token=abcdefg --from-literal=email=team@domain.com

tasks/managed/close-advisory-issues/tests/test-close-advisory-issues-cannot-close-issue.yaml

Lines changed: 0 additions & 110 deletions
This file was deleted.

tasks/managed/close-advisory-issues/tests/test-close-advisory-issues-cannot-get-transitions.yaml

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)