-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch.sh
executable file
·48 lines (36 loc) · 1.53 KB
/
fetch.sh
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
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
main_dir="$(dirname "$(realpath "$0")")"
echo "Adding key"
export KEY_FILE="$main_dir/.private"
echo "$PRIVATE_KEY" > $KEY_FILE
export GIT_SSH_COMMAND="ssh -o IdentitiesOnly=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $KEY_FILE"
ls -la $KEY_FILE
echo "Cleaning workspace"
[[ -d mendeley-api-changes/ ]] && rm -rf mendeley-api-changes/
git clone git@github.com:tori3852/mendeley-api-changes.git
[[ -d mendeley-api-changes/apis/ ]] && rm -rf mendeley-api-changes/apis/
mkdir mendeley-api-changes/apis/
echo "Fetching API"
endpoints=$(curl --retry 5 -vs "https://api.mendeley.com/apidocs/apis" | $main_dir/bin/jq -rS '.apis[].path')
for endpoint in $endpoints;
do
echo "Endpoint: $endpoint"
endpoint="$(echo $endpoint | sed 's|^/||')"
file="$(echo $endpoint | sed 's|/|_|g').json"
# Sort by: '.apis[].path' + '.apis[].operations.nickname'
curl -retry 5 -vs "https://api.mendeley.com/apidocs/apis/$endpoint" \
| $main_dir/bin/jq -S '.apis |= sort_by(.path) | .apis[].operations |= sort_by(.nickname)' \
> "mendeley-api-changes/apis/$file"
done
echo "Recording changes"
changes="$(git -C mendeley-api-changes/apis status -s | tr "\n" " ")"
echo "Changes: $changes"
git -C mendeley-api-changes/ add apis/
echo "Changes added to git"
git -C mendeley-api-changes/ -c user.name=heroku -c user.email=heroku commit -m "API changes for $(date '+%F %H:%M:%S'): $changes"
echo "Changes commited to git"
echo "Pushing changes"
git -C mendeley-api-changes/ push
echo "Done."