-
Notifications
You must be signed in to change notification settings - Fork 0
/
try
executable file
·115 lines (104 loc) · 2.67 KB
/
try
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#! /bin/bash
set -euo pipefail
IFS=$'\n\t'
CANONICAL="http://n2t.net/ark:/99152/p0d.json"
DATASET_URL=${DATASET:-"$CANONICAL"}
usage () {
echo "Usage: $0 {new|without-patch|with-patch|accept} <proposed change>"
echo
echo "<proposed change> should be one of:"
ls -1 changes/proposed
echo
exit 1
}
new () {
mkdir -p "changes/proposed/$1"
local add="changes/proposed/$1/constraints-added.ttl"
local rem="changes/proposed/$1/constraints-removed.ttl"
touch "$add"
touch "$rem"
if [ ! -f "fix/$1.js" ]; then
(cat <<EOF
// Object => Promise { Array<Operation> }
module.exports = async function createPatch(o) {
throw 'implement me'
}
EOF
) > "fix/$1.js"
fi
printf "Put new SHACL constraints in:\\n %s\\n\\n" "$add"
printf "Put SHACL constraints to be removed in:\\n %s\\n\\n" "$rem"
printf "Implement your fix in:\\n %s\\n" "fix/$1.js"
}
validate_with_change () {
local results
results=$(
./validate - \
--shapes shapes \
--remove "changes/proposed/$1/constraints-removed.ttl" \
--shapes "changes/proposed/$1/constraints-added.ttl" \
--json
)
local problems
problems=$(echo "$results" | jq -f report.jq)
if [ "$problems" == "[]" ]
then
echo "No problems found."
else
echo "$results" | jq -f report.jq -C | less -R
fi
}
without_patch () {
curl -s -L "${DATASET_URL}?inline-context" | validate_with_change "$1"
}
with_patch () {
node fix "$1" -d "$DATASET_URL" -a | validate_with_change "$1"
}
accept () {
local dir
if [ "$DATASET_URL" == "$CANONICAL" ]
then
dir="changes/accepted/$(date +%Y-%m-%d)-$1"
else
domain=$(echo "$DATASET_URL" | awk -F/ '{print $3}')
dir="changes/accepted/$domain/$(date +%Y-%m-%d)-$1"
fi
mkdir -p "$dir"
echo -n "Writing patch to $dir... "
node fix "$1" -d "$DATASET_URL" > "$dir/patch.json"
node fix "$1" -d "$DATASET_URL" -a > "$dir/data-after.json"
curl -s -L "${DATASET_URL}?inline-context" > "$dir/data-before.json"
echo "OK"
}
if [ "${1:-}" == "" ]; then
usage
fi
if [ "${2:-}" == "" ]; then
usage
fi
if [ "$1" != "new" ] && [ ! -d "changes/proposed/$2" ]; then
usage
fi
if [ ! -L shapes ] || [ ! -e shapes ]
then
echo "Create a symlink 'shapes' pointing to the shapes directory, e.g.:"
echo "ln -s ../periodo-server/shapes"
exit 1
fi
case "$1" in
new)
new "$2"
;;
without-patch)
without_patch "$2"
;;
with-patch)
with_patch "$2"
;;
accept)
accept "$2"
;;
*)
usage
;;
esac