-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoeditor-purge-projects.sh
56 lines (36 loc) · 1.16 KB
/
poeditor-purge-projects.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
49
50
51
52
53
54
55
56
#!/bin/bash
# EXPORTS ENV FROM .ENV FILE
if [ -f ".env" ]; then
set -a
source ".env"
set +a
fi
# CHECKS IF POEDITOR_TOKEN IS SET
if [ -z "$POEDITOR_TOKEN" ]; then
echo "POEDITOR_TOKEN is not set"
exit 1
fi
# RETRIEVES PROJECTS LIST
# CACHES IT TO .projects.log.json
[ -f ".projects.log.json" ] || curl --verbose --silent -X POST "https://api.poeditor.com/v2/projects/list" -d api_token="$POEDITOR_TOKEN" -o .projects.log.json
# CHECKS IF JQ IS INSTALLED
if ! [ -x "$(command -v jq)" ]; then
echo "jq is not installed"
exit 1
fi
# JQ WRAPPER TO DECODE BASE64
_jq() {
echo ${i} | base64 --decode | jq -r ${1}
}
# FOREACH RESULT PROJECTS ID CURLS POEDITOR API TO DELETE IT
jq -r '.result.projects[] | @base64' .projects.log.json | while read i; do
project_id=$(_jq '.id')
if [ -z "$project_id" ]; then
echo "error reading project_id"
exit 1
fi
result=$(curl --silent -sw '%{http_code}' -X POST "https://api.poeditor.com/v2/projects/delete" -d api_token="$POEDITOR_TOKEN" -d id="$project_id")
echo "PROJECT $project_id DELETE responded with $result"
done
# DELETES .projects.log.json
rm .projects.log.json