-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathgraph.sh
More file actions
executable file
·33 lines (31 loc) · 820 Bytes
/
graph.sh
File metadata and controls
executable file
·33 lines (31 loc) · 820 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
32
33
#!/bin/sh
#
# Usage:
#
# cat cincinnati.json | graph.sh >graph.dot
#
# For example:
#
# curl -sH 'Accept:application/json' 'https://api.openshift.com/api/upgrades_info/graph?channel=prerelease-4.1' | graph.sh | dot -Tsvg >graph.svg
set -e
JQ_SCRIPT='"digraph Upgrades {\n labelloc=t;\n rankdir=BT;" as $header |
(
[
.nodes |
to_entries[] |
" " + (.key | tostring) +
" [ label=\"" + .value.version + "\"" + (
if .value.metadata.url then " href=\"" + .value.metadata.url + "\"" else "" end
) +
" ];"
] | join("\n")
) as $nodes |
(
[
.edges[] |
" " + (.[0] | tostring) + "->" + (.[1] | tostring) + ";"
] | join("\n")
) as $edges |
[$header, $nodes, $edges, "}"] | join("\n")
'
exec jq -r "${JQ_SCRIPT}"