From 07a96b883a380a3ad8b4fb76b87ff69174ff1416 Mon Sep 17 00:00:00 2001 From: Jon Date: Tue, 8 Mar 2022 01:14:30 +0000 Subject: [PATCH] hotpocket.sh: change applyTopicsToTags merging algorithm --- hotpocket.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/hotpocket.sh b/hotpocket.sh index c4ebd34..15aa0c7 100755 --- a/hotpocket.sh +++ b/hotpocket.sh @@ -232,7 +232,17 @@ oneOfTagsAsArray () { applyTopicsToTags () { # applyTopicsToTags: - jq --argjson aliases "$TOPICS" '[foreach ($aliases | to_entries[]) as $alias (.; if any($alias.value[] == .) then . + [$alias.key] else . end)] | last' --< /dev/stdin + # TODO: While this uses action's tags to match against instead of the rules, it doesn't report the + # alias which is resulting in the match. Needs more looking into + # jq --argjson aliases "$TOPICS" '[foreach ($aliases | to_entries[]) as $alias (.; if any($alias.value[] == .) then . + [$alias.key] else . end)] | last' --< /dev/stdin + jq --argjson topics "$TOPICS" \ +'[foreach ($topics | to_entries | reverse[]) as $topic (.; + if index($topic.key) then + . + $topic.value + else + . + end +)] | last' < /dev/stdin return $? } @@ -356,8 +366,7 @@ ingestRule () { local match local code - # TODO - rule_tags="$(oneOfTagsAsArray <<< "$1" | applyTopicsToTags)" || return 1 + rule_tags="$(oneOfTagsAsArray <<< "$1")" || return 1 for actions_index in $(arrayIndexList "$ACTIONS"); do action="$(jq ".[$((actions_index-1))]" -rc <<< "$ACTIONS")" || return 2