-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.sh
More file actions
executable file
·64 lines (54 loc) · 1.57 KB
/
script.sh
File metadata and controls
executable file
·64 lines (54 loc) · 1.57 KB
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
#!/usr/bin/env bash
set -euo pipefail
if [ -z "${GL_USERNAME}" ]; then
echo "GL_USERNAME is not set"
exit 1
fi
if [ -z "${GH_REPOSITORY}" ]; then
echo "GH_REPOSITORY is not set"
exit 1
fi
if [ -z "${GH_USERNAME}" ]; then
echo "GH_USERNAME is not set"
exit 1
fi
if [ -z "${GH_EMAIL}" ]; then
echo "GH_EMAIL is not set"
exit 1
fi
if [ -z "${GH_SSH_KEY}" ]; then
echo "GH_SSH_KEY is not set"
exit 1
fi
cd "$(mktemp -d)"
dir_path="$(pwd)"
trap "rm -rf ${dir_path}" EXIT
echo "${GH_SSH_KEY}" > ssh_key
chmod 600 ssh_key
GIT_SSH_COMMAND="ssh -i ${dir_path}/ssh_key" git clone "${GH_REPOSITORY}" "repo"
cd "repo"
git config user.name "${GH_USERNAME}"
git config user.email "${GH_EMAIL}"
PRE_COMMIT_MSG='auto: '
function modif(){
cat changes | grep -q "true" && echo "false" > changes || echo "true" > changes
}
todo="$(curl -s "https://gitlab.com/users/${GL_USERNAME}/calendar.json" | jq -rc '. | to_entries | .[] | "\(.key)-\(range(.value)+1)"')"
already_done="$(git log --pretty='format:%s' | grep -E "^${PRE_COMMIT_MSG}" | sed "s/^${PRE_COMMIT_MSG}//")"
export IFS=$'\n'
commits=0
for x in $todo;
do
echo "Processing ${x}"
if [[ ! $already_done =~ $x ]]; then
modif
git add changes
commit_date="$(date -d "$(echo "${x}" | cut -d- -f-3)" '+%Y-%m-%d %H:%M:%S')"
GIT_COMMITTER_DATE="${commit_date}" git commit -s -m "${PRE_COMMIT_MSG}${x}" --date "${commit_date}"
commits=$((commits + 1))
fi
done
GIT_SSH_COMMAND="ssh -i ${dir_path}/ssh_key" git push origin HEAD
echo
echo "Done ! Added ${commits} commits"
echo