Skip to content

Commit a414bf7

Browse files
committed
feat: update script for auto run
Signed-off-by: QuentinN42 <quentin@lieumont.fr>
1 parent 283d93e commit a414bf7

1 file changed

Lines changed: 30 additions & 9 deletions

File tree

script.sh

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,38 @@
1-
#!/bin/sh
2-
# Create a git repo on github
3-
# Put this script inside
4-
# Update USERNAME
5-
# Run this script
6-
# Push
1+
#!/usr/bin/env bash
2+
3+
if [ -z "${GITLAB_USERNAME}" ]; then
4+
echo "USERNAME is not set"
5+
exit 1
6+
fi
7+
if [ -z "${REPOSITORY}" ]; then
8+
echo "REPOSITORY is not set"
9+
exit 1
10+
fi
11+
if [ -z "${GITHUB_USERNAME}" ]; then
12+
echo "GITHUB_USERNAME is not set"
13+
exit 1
14+
fi
15+
if [ -z "${GITHUB_EMAIL}" ]; then
16+
echo "GITHUB_EMAIL is not set"
17+
exit 1
18+
fi
19+
20+
cd "$(mktemp -d)"
21+
dir_path="$(pwd)"
22+
trap "rm -rf ${dir_path}" EXIT
23+
git clone "${REPOSITORY}" "repo"
24+
cd "repo"
25+
26+
git config user.name "${GITHUB_USERNAME}"
27+
git config user.email "${GITHUB_EMAIL}"
728

829
PRE_COMMIT_MSG='auto: '
9-
USERNAME='QuentinN42'
1030

1131
function modif(){
1232
cat changes | grep -q "true" && echo "false" > changes || echo "true" > changes
1333
}
1434

15-
todo="$(curl -s "https://gitlab.com/users/${USERNAME}/calendar.json" | jq -rc '. | to_entries | .[] | "\(.key)-\(range(.value)+1)"')"
35+
todo="$(curl -s "https://gitlab.com/users/${GITLAB_USERNAME}/calendar.json" | jq -rc '. | to_entries | .[] | "\(.key)-\(range(.value)+1)"')"
1636
already_done="$(git log --pretty='format:%s' | grep -E "^${PRE_COMMIT_MSG}" | sed "s/^${PRE_COMMIT_MSG}//")"
1737

1838
export IFS=$'\n'
@@ -22,6 +42,7 @@ do
2242
if [[ ! $already_done =~ $x ]]; then
2343
modif
2444
git add changes
25-
git commit -s -m "${PRE_COMMIT_MSG}${x}" --date="$(date -d "$(echo "${x}" | cut -d- -f-3)")"
45+
commit_date="$(date -d "$(echo "${x}" | cut -d- -f-3)" '+%Y-%m-%d %H:%M:%S')"
46+
GIT_COMMITTER_DATE="${commit_date}" git commit -s -m "${PRE_COMMIT_MSG}${x}" --date "${commit_date}"
2647
fi
2748
done

0 commit comments

Comments
 (0)