dadi-staging-webhook/webhooks-git/dadi-staging-hook.sh

38 lines
1.1 KiB
Bash

#!/bin/bash
# Check if correct number of arguments are provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <repository_name> <branch_name>"
exit 1
fi
repository_name="$1"
branch_name="${2#refs/heads}"
BRANCHES_FOLDER="/html/branches"
DADI_STAGING_REPOSITORY="git_dadi-staging:AG-IT/KlDaDiSeite.git"
# Echo parameters
echo "Webhook recieved for repository: $repository_name and branch: $branch_name"
# Check if the branch directory exists
safe_branch_name="${branch_name//\//-}"
branch_dir="$BRANCHES_FOLDER/$safe_branch_name"
if [ -d "$branch_dir" ]; then
echo "Directory $branch_dir exists, performing git pull..."
# Change directory to branch directory
cd "$branch_dir"
# Perform git pull
echo "Updating $branch_dir"
git pull origin "$branch_name"
else
echo "Directory $branch_dir does not exist, cloning branch..."
# Create branches directory if it doesn't exist
mkdir -p "$BRANCHES_FOLDER"
# Clone the branch
git clone --depth 1 --branch "$branch_name" --single-branch "$DADI_STAGING_REPOSITORY" "$branch_dir"
# reinitialize index.html
./generate_index_html.sh
fi