From 669e0a6eee57201f5b06cc2eb25eb36ba141d8e7 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 23 Jul 2026 11:50:34 +0200 Subject: [PATCH] feat: add reusable issue submitter detector --- .github/scripts/find_addon_submitter.sh | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/scripts/find_addon_submitter.sh diff --git a/.github/scripts/find_addon_submitter.sh b/.github/scripts/find_addon_submitter.sh new file mode 100644 index 0000000000..93d0cd7cbb --- /dev/null +++ b/.github/scripts/find_addon_submitter.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +set -euo pipefail + +mapping_file="${1:-.github/addon_submitters.json}" +output_file="${GITHUB_OUTPUT:-/dev/stdout}" + +if [[ ! -f "$mapping_file" ]]; then + echo "Mapping file not found: $mapping_file" >&2 + exit 1 +fi + +normalize() { + tr '[:upper:]' '[:lower:]' | + sed -E 's/[^a-z0-9]+/ /g; s/^ +//; s/ +$//; s/ +/ /g' +} + +text="$(printf '%s %s' "${ISSUE_TITLE:-}" "${ISSUE_BODY:-}" | normalize)" +text=" $text " +matches='[]' + +while IFS= read -r addon; do + [[ -z "$addon" ]] && continue + + submitter="$(jq -r --arg addon "$addon" '.[$addon] // empty' "$mapping_file")" + [[ -z "$submitter" ]] && continue + + normalized_addon="$(printf '%s' "$addon" | normalize)" + [[ -z "$normalized_addon" ]] && continue + + if [[ "$text" == *" $normalized_addon "* ]]; then + matches="$( + jq -c \ + --arg addon "$addon" \ + --arg submitter "$submitter" \ + '. + [{addon: $addon, submitter: $submitter}]' <<< "$matches" + )" + fi +done < <(jq -r 'keys[]' "$mapping_file") + +matched=false +addon='' +submitter='' + +if [[ "$(jq 'length' <<< "$matches")" -gt 0 ]]; then + matched=true + addon="$(jq -r '.[0].addon' <<< "$matches")" + submitter="$(jq -r '.[0].submitter' <<< "$matches")" +fi + +{ + echo "matched=$matched" + echo "addon=$addon" + echo "submitter=$submitter" + echo "matches_json=$matches" +} >> "$output_file"