Skip to content

Commit

Permalink
Allow fallback notification address for unknown issues
Browse files Browse the repository at this point in the history
  • Loading branch information
perlpunk committed May 10, 2022
1 parent c67315b commit 9da76cd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion _common
Expand Up @@ -95,7 +95,7 @@ label_on_issue() {
}

handle_unknown() {
local testurl=$1 out=$2 reason=$3 group_id=$4 email_unreviewed=$5 from_email=$6
local testurl=$1 out=$2 reason=$3 group_id=$4 email_unreviewed=$5 from_email=$6 notification_address=${7:-}
local group_data group_description group_mailto header
to_review+=("$testurl ${reason:0:50}")
header="$testurl : Unknown issue, to be reviewed -> $testurl/file/autoinst-log.txt"
Expand All @@ -109,6 +109,7 @@ handle_unknown() {
group_data=$(openqa-cli "${client_args[@]}" "job_groups/$group_id")
group_description=$(echo "$group_data" | runjq -r '.[0].description' ) || true
group_mailto=$(echo "$group_description" | perl -n -wE'm/.*MAILTO: (\S+).*/ and say $1' | head -1)
group_mailto=${group_mailto:-$notification_address}
if [[ -n "$group_mailto" ]]; then
echo "$header"$'\n'"Reason: $reason" | mailx -s "Unknown issue to be reviewed (Group $group_id)" -r "openqa-label-known-issues <$from_email>" "$group_mailto"
fi
Expand Down
3 changes: 2 additions & 1 deletion openqa-label-known-issues
Expand Up @@ -18,6 +18,7 @@ issue_query="${issue_query:-"https://progress.opensuse.org/projects/openqav3/iss
reason_min_length="${reason_min_length:-"8"}"
grep_timeout="${grep_timeout:-5}"
email_unreviewed=${email_unreviewed:-true}
notification_address=${notification_address:-}
from_email=${from_email:-openqa-label-known-issues@open.qa}
to_review=()
curl_args=(--user-agent "openqa-label-known-issues")
Expand Down Expand Up @@ -129,7 +130,7 @@ investigate_issue() {
# subject line
elif label_on_issues_without_tickets "$id"; then return
else
handle_unknown "$testurl" "$out" "$reason" "$group_id" "$email_unreviewed" "$from_email"
handle_unknown "$testurl" "$out" "$reason" "$group_id" "$email_unreviewed" "$from_email" "$notification_address"
fi
}

Expand Down
14 changes: 12 additions & 2 deletions test/01-label-known-issues.t
Expand Up @@ -13,7 +13,7 @@ PATH=$BASHLIB$PATH

source bash+ :std
use Test::More
plan tests 16
plan tests 18

source _common

Expand Down Expand Up @@ -86,13 +86,23 @@ mailx() {
echo "$subject,$header,$recv" >&2
}
openqa-cli() {
cat "$dir/data/group24.json"
local id=$(basename "$4")
cat "$dir/data/group$id.json"
}
from_email=foo@bar
client_args=(api --host http://localhost)
testurl=https://openqa.opensuse.org/api/v1/jobs/2291399
group_id=24
out=$(handle_unknown "$testurl" "$logfile1" "no reason" "$group_id" true "$from_email" 2>&1 >/dev/null) || true
is "$out" 'Unknown issue to be reviewed (Group 24),openqa-label-known-issues <foo@bar>,dummy@example.com.dummy' "mailx called like expected"

out=$(handle_unknown "$testurl" "$logfile1" "no reason" "null" true "$from_email" 2>&1 >/dev/null) || true
is "$out" '' "mailx not called for group_id null"

group_id=25
out=$(handle_unknown "$testurl" "$logfile1" "no reason" "$group_id" true "$from_email" 2>&1 >/dev/null) || true
is "$out" '' "mailx not called for no email address and no fallback address"

notification_address=fallback@example.com
out=$(handle_unknown "$testurl" "$logfile1" "no reason" "$group_id" true "$from_email" "$notification_address" 2>&1 >/dev/null) || true
is "$out" 'Unknown issue to be reviewed (Group 25),openqa-label-known-issues <foo@bar>,fallback@example.com' "mailx called like expected with fallback address"
8 changes: 8 additions & 0 deletions test/data/group25.json
@@ -0,0 +1,8 @@
[
{
"default_priority": 50,
"description": "Just a description without a MAILTO address to notify",
"id": 25,
"name": "Lala"
}
]

0 comments on commit 9da76cd

Please sign in to comment.