Created
August 15, 2023 22:56
-
-
Save QuentinN42/320b56c149f7b30eefc94832c7395d41 to your computer and use it in GitHub Desktop.
Sync your gitlab commits history with gihub.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Create a git repo on github | |
# Put this script inside | |
# Update USERNAME | |
# Run this script | |
# Push | |
PRE_COMMIT_MSG='auto: ' | |
USERNAME='QuentinN42' | |
function modif(){ | |
cat changes | grep -q "true" && echo "false" > changes || echo "true" > changes | |
} | |
todo="$(curl -s "https://gitlab.com/users/${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' | |
for x in $todo; | |
do | |
echo "Processing ${x}" | |
if [[ ! $already_done =~ $x ]]; then | |
modif | |
git add changes | |
git commit -s -m "${PRE_COMMIT_MSG}${x}" --date="$(date -d "$(echo "${x}" | cut -d- -f-3)")" | |
fi | |
done |
And you might also want to update the git author date with GIT_COMMITER_DATE
export IFS=$'\n'
for x in $todo;
do
echo "Processing ${x}"
if [[ ! $already_done =~ $x ]]; then
modif
git add changes
commit_date="$(echo "${x}" | cut -d- -f-3)"
commit_message="${PRE_COMMIT_MSG}${x}"
GIT_COMMITTER_DATE="$(date -d "${commit_date}" '+%Y-%m-%d %H:%M:%S')" git commit -s -m "${commit_message}" --date "$(date -d "${commit_date}" '+%Y-%m-%d %H:%M:%S')"
fi
done
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seemingly not working with
sh
as the function keyword is not POSIX compliant (cf bashism )