-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathdemo.sh
More file actions
executable file
·31 lines (28 loc) · 832 Bytes
/
Copy pathdemo.sh
File metadata and controls
executable file
·31 lines (28 loc) · 832 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env bash
# Hackathon demo: POST a sample failing CI log to the local webhook.
# Usage: ./demo.sh [webhook_url]
# PIPELINEMEDIC_URL=http://127.0.0.1:8000 ./demo.sh
set -euo pipefail
URL="${1:-${PIPELINEMEDIC_URL:-http://127.0.0.1:8000}/webhook}"
exec python3 - "$URL" <<'PY'
import json, sys, urllib.request
url = sys.argv[1]
body = json.dumps(
{
"repository": "demo/hackathon",
"log": "ModuleNotFoundError: No module named 'requests'",
}
).encode("utf-8")
req = urllib.request.Request(
url,
data=body,
headers={"Content-Type": "application/json"},
method="POST",
)
with urllib.request.urlopen(req, timeout=30) as resp:
raw = resp.read().decode("utf-8", errors="replace")
try:
print(json.dumps(json.loads(raw), indent=2))
except json.JSONDecodeError:
print(raw)
PY