hotpocket.sh: change applyTopicsToTags merging algorithm

This commit is contained in:
Jon 2022-03-08 01:14:30 +00:00
parent 0e4e9504a1
commit 07a96b883a

View File

@ -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