Skip to content

Commit ae3e21e

Browse files
committed
git subrepo pull (merge) ingest/vendored
subrepo: subdir: "ingest/vendored" merged: "744de92" upstream: origin: "https://github.com/nextstrain/ingest" branch: "main" commit: "744de92" git-subrepo: version: "0.4.6" origin: "https://github.com/ingydotnet/git-subrepo" commit: "110b9eb"
1 parent 45a96a0 commit ae3e21e

File tree

2 files changed

+61
-26
lines changed

2 files changed

+61
-26
lines changed

ingest/vendored/.gitrepo

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[subrepo]
77
remote = https://github.com/nextstrain/ingest
88
branch = main
9-
commit = 258ab8ce898a88089bc88caee336f8d683a0e79a
10-
parent = a1dd6dedc766e0ca82c893d1c6bd1118dec89889
9+
commit = 744de922333f9dbf947ae901409d3ce8701073d1
10+
parent = 45a96a043c864f303888bd6704f99d3d6cdbaca3
1111
method = merge
1212
cmdver = 0.4.6

ingest/vendored/notify-slack

+59-24
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ upload=0
88
output=/dev/null
99
thread_ts=""
1010
broadcast=0
11+
fail_on_error=0
1112
args=()
1213

1314
for arg; do
@@ -20,6 +21,8 @@ for arg; do
2021
thread_ts="${arg#*=}";;
2122
--broadcast)
2223
broadcast=1;;
24+
--fail-on-error)
25+
fail_on_error=1;;
2326
*)
2427
args+=("$arg");;
2528
esac
@@ -29,28 +32,60 @@ set -- "${args[@]}"
2932

3033
text="${1:?Some message text is required.}"
3134

32-
if [[ "$upload" == 1 ]]; then
33-
echo "Uploading data to Slack with the message: $text"
34-
curl https://slack.com/api/files.upload \
35-
--header "Authorization: Bearer $SLACK_TOKEN" \
36-
--form-string channels="$SLACK_CHANNELS" \
37-
--form-string title="$text" \
38-
--form-string filename="$text" \
39-
--form-string thread_ts="$thread_ts" \
40-
--form file=@/dev/stdin \
41-
--form filetype=text \
42-
--fail --silent --show-error \
43-
--http1.1 \
44-
--output "$output"
45-
else
46-
echo "Posting Slack message: $text"
47-
curl https://slack.com/api/chat.postMessage \
48-
--header "Authorization: Bearer $SLACK_TOKEN" \
49-
--form-string channel="$SLACK_CHANNELS" \
50-
--form-string text="$text" \
51-
--form-string thread_ts="$thread_ts" \
52-
--form-string reply_broadcast="$broadcast" \
53-
--fail --silent --show-error \
54-
--http1.1 \
55-
--output "$output"
35+
send_slack_message() {
36+
if [[ "$upload" == 1 ]]; then
37+
echo "Uploading data to Slack with the message: $text"
38+
39+
upload_file="$(mktemp -t upload-file-XXXXXX)"
40+
trap "rm -f '$upload_file'" EXIT
41+
42+
cat /dev/stdin > "$upload_file"
43+
length=$(printf '%d' "$(<"$upload_file" wc -c)")
44+
45+
upload_info=$(curl https://slack.com/api/files.getUploadURLExternal \
46+
--header "Authorization: Bearer $SLACK_TOKEN" \
47+
--form-string filename="$text" \
48+
--form-string length="$length" \
49+
--fail --silent --show-error \
50+
--http1.1 )
51+
52+
upload_url="$(jq -r .upload_url <<< "$upload_info")"
53+
curl "$upload_url" \
54+
--form-string filename="$text" \
55+
--form file="@$upload_file" \
56+
--fail --silent --show-error \
57+
--http1.1 > /dev/null
58+
59+
files_uploaded="$(jq -r "[{id: .file_id}]" <<< "$upload_info")"
60+
curl -X POST https://slack.com/api/files.completeUploadExternal \
61+
--header "Authorization: Bearer $SLACK_TOKEN" \
62+
--form-string channel_id="$SLACK_CHANNELS" \
63+
--form-string thread_ts="$thread_ts" \
64+
--form-string files="$files_uploaded" \
65+
--fail --silent --show-error \
66+
--http1.1 \
67+
--output "$output"
68+
69+
else
70+
echo "Posting Slack message: $text"
71+
curl https://slack.com/api/chat.postMessage \
72+
--header "Authorization: Bearer $SLACK_TOKEN" \
73+
--form-string channel="$SLACK_CHANNELS" \
74+
--form-string text="$text" \
75+
--form-string thread_ts="$thread_ts" \
76+
--form-string reply_broadcast="$broadcast" \
77+
--fail --silent --show-error \
78+
--http1.1 \
79+
--output "$output"
80+
fi
81+
}
82+
83+
if ! send_slack_message; then
84+
if [[ "$fail_on_error" == 1 ]]; then
85+
echo "Sending Slack message failed"
86+
exit 1
87+
else
88+
echo "Sending Slack message failed, but exiting with success anyway."
89+
exit 0
90+
fi
5691
fi

0 commit comments

Comments
 (0)