Skip to content

Commit

Permalink
Handle multiple pull requests with same revision
Browse files Browse the repository at this point in the history
Due to rebasing the same revision that triggered the pipeline for one
pull request can occur in other pull requests. With this not only the
first result from `gh search prs` is used, changes from all of them are
considered.

This means that some Tasks that might not need to run are still ran,
this should be acceptable given it guarantees that all Tasks that need
to run have ran.
  • Loading branch information
zregvart committed Dec 20, 2024
1 parent cab9bea commit 27d1120
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions .tekton/tasks/task-switchboard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ spec:
ec opa check --v1-compatible "${rules}"
pr_number="$(gh search prs --repo konflux-ci/build-definitions "$(params.revision)" --json number --jq '.[].number')"
rev="$(params.revision)"
changed_files=()
for pr_number in $(gh search prs --repo konflux-ci/build-definitions "${rev}" --json number --jq '.[].number'); do
echo "Found revision ${rev} in pull request number ${pr_number}"
echo "Determined pull request number ${pr_number}"
changed="$(gh pr view "https://github.com/konflux-ci/build-definitions/pull/${pr_number}" --json files --jq '[.files.[].path'])"
echo Changed files:
echo "${changed}" | jq -r '.[]'
changed="$(gh pr view "https://github.com/konflux-ci/build-definitions/pull/${pr_number}" --json files --jq '[.files.[].path'])"
echo Changed files:
echo "${changed}" | jq -r '.[]'
changed_files+=("${changed}")
done
echo "${changed}" | ec opa eval --v1-compatible --data "${rules}" --stdin-input \
echo "${changed_files[@]}" | jq -s 'add | unique' | ec opa eval --v1-compatible --data "${rules}" --stdin-input \
'data[_]' \
| jq '[.result.[].expressions.[].value | to_entries | .[] | select(.value == true) | .key]' \
| tee "$(results.bindings.path)"

0 comments on commit 27d1120

Please sign in to comment.