From 12fecb0dc9db28555291ed55809cdb2350518dad Mon Sep 17 00:00:00 2001 From: Andre Challier Date: Thu, 28 Mar 2024 09:37:18 +0100 Subject: [PATCH] implemented assets webhook --- webhooks-git/assets-hook.sh | 37 +++++++++++++++++++++++++++++++++++ webhooks-git/programm-hook.sh | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/webhooks-git/assets-hook.sh b/webhooks-git/assets-hook.sh index 05a7907..7cf9c30 100644 --- a/webhooks-git/assets-hook.sh +++ b/webhooks-git/assets-hook.sh @@ -1,2 +1,39 @@ #!/bin/bash +#!/bin/bash + +# Check if correct number of arguments are provided +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Echo parameters +echo "Webhook recieved for repository: $repository_name and branch: $branch_name" + +repository_name="$2" +branch_name=$(basename "$1") + +if [ "$branch_name" != "main" ]; then + echo "Error: This hook must only update branch main, not $branch_name" + exit 1 +fi + +ASSETS_DIRECTORY="/html/branches/assets" +ASSETS_REPOSITORY="git_assets:AG-IT/assets.git" + +# Check if the assets directory exists +if [ -d "$ASSETS_DIRECTORY" ]; then + echo "Directory $ASSETS_DIRECTORY exists, performing git pull..." + # Change directory to branch directory + cd "$ASSETS_DIRECTORY" + # Perform git pull + echo "Updating $ASSETS_DIRECTORY" + git pull origin main +else + echo "Directory $ASSETS_DIRECTORY does not exist, cloning branch..." + # Create branches directory if it doesn't exist + mkdir -p branches + # Clone the branch + git clone --depth 1 --branch "$branch_name" --single-branch "$ASSETS_REPOSITORY" "$branch_dir" +fi \ No newline at end of file diff --git a/webhooks-git/programm-hook.sh b/webhooks-git/programm-hook.sh index 212890b..c2ef161 100644 --- a/webhooks-git/programm-hook.sh +++ b/webhooks-git/programm-hook.sh @@ -16,7 +16,7 @@ PROGRAMM_REPOSITORY="git_programm:AG-Programm/parteiprogramm.git" echo "Webhook recieved for repository: $repository_name and branch: $branch_name" # Check if the branch directory exists -branch_dir="$BRANCES_FOLDER/$(basename "$branch_name")" +branch_dir="$BRANCHES_FOLDER/$(basename "$branch_name")" if [ -d "$branch_dir" ]; then echo "Directory $branch_dir exists, performing git pull..." # Change directory to branch directory