#!/bin/bash # Copyright (C) 2026 Red Hat, Inc. # Written by: # Andrew John Hughes # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # Retrieve the status of a build's progress through gating RHEL_VER=${1} NVR=${2} if test "${RHEL_VER}" = ""; then echo "No RHEL version specified."; echo "${0} "; exit 1; fi if test "${NVR}" = ""; then echo "No NVR specified."; echo "${0} "; exit 2; fi CURL=$(command -v curl) JSON_TOOL=$(command -v jq) JSON_FILE=$(mktemp --tmpdir query.XXXXXX.json) JSON_OUT=$(mktemp --tmpdir out.XXXXXX.json) URL="https://greenwave.engineering.redhat.com/api/v1.0/decision" if test "${CURL}" = ""; then echo "curl not found"; exit 3; fi if test "${JSON_TOOL}" = ""; then echo "jq not found"; exit 4; fi { echo "{"; printf "\t\"decision_context\":\"osci_compose_gate\",\n"; printf "\t\"product_version\":\"rhel-%d\",\n" "${RHEL_VER}"; printf "\t\"subject_type\":\"koji_build\",\n"; printf "\t\"subject_identifier\":\"%s\",\n" "${NVR}"; printf "\t\"verbose\":false\n"; echo "}"; } > "${JSON_FILE}" echo "Sending the following JSON..."; cat "${JSON_FILE}" CMD=("${CURL}" --silent --show-error -X POST) JSON_COMMAND="--json"; # Check --json is available ${CURL} ${JSON_COMMAND} 2> /dev/null if [ $? -eq 2 ] ; then echo "--json unsupported; falling back on --data-ascii"; CMD=("${CMD[@]}" --header Content-Type:application/json --data-ascii); else CMD=("${CMD[@]}" "${JSON_COMMAND}"); fi CMD=("${CMD[@]}" "@${JSON_FILE}" "${URL}") echo "${CMD[@]}" if command "${CMD[@]}" > "${JSON_OUT}" ; then "${JSON_TOOL}" < "${JSON_OUT}" else echo "Failed to obtain JSON"; exit 5; fi # Local Variables: # compile-command: "shellcheck query_build_gating.sh" # fill-column: 80 # indent-tabs-mode: nil # sh-basic-offset: 4 # End: