diff --git a/README.md b/README.md index 836e401..2200085 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ First, generate a GitHub personal access token (PAT) with minimal permissions fo - https://github.com/settings/personal-access-tokens/ - limit to the specific repository -- contents (read) +- contents (write, needs for branches) - PRs (write) Install (token will be needed here) diff --git a/network-glue/Dockerfile b/network-glue/Dockerfile index c01ba73..2fd9d99 100644 --- a/network-glue/Dockerfile +++ b/network-glue/Dockerfile @@ -1,4 +1,4 @@ FROM ghcr.io/flant/shell-operator:latest -RUN apk add git +RUN apk add git curl ADD hooks /hooks diff --git a/network-glue/hooks/bin/clone-repo.sh b/network-glue/hooks/bin/clone-repo.sh index 335bdb7..2fe83a0 100644 --- a/network-glue/hooks/bin/clone-repo.sh +++ b/network-glue/hooks/bin/clone-repo.sh @@ -19,7 +19,7 @@ fi # Clone the repository using the GitHub token echo "Cloning the repository..." rm -rf "$REPO_DIR" -git clone https://"${GIT_TOKEN}":x-oauth-basic@"$REPO_URL" "$REPO_DIR" +git clone https://"${GIT_TOKEN}":x-oauth-basic@"${REPO_URL#https://}" "$REPO_DIR" cd "$REPO_DIR" # Create a new branch for the changes diff --git a/network-glue/hooks/bin/create-pr.sh b/network-glue/hooks/bin/create-pr.sh index 6d6b785..1bad48b 100644 --- a/network-glue/hooks/bin/create-pr.sh +++ b/network-glue/hooks/bin/create-pr.sh @@ -11,6 +11,8 @@ set -u # BRANCH_NAME # FILE_TO_UPDATE # Configuration +GIT_USER="shell-operator" +GIT_EMAIL="shell-operator@example.com" COMMIT_MESSAGE="Update configuration file" PR_TITLE="Proposal: Update Configuration $FILE_TO_UPDATE" PR_BODY="This PR proposes updates to the configuration file." @@ -23,8 +25,11 @@ if [ -z "$GIT_TOKEN" ]; then fi # Add and commit the changes +cd "$REPO_DIR" git add "$FILE_TO_UPDATE" -echo "Committing the changes..." +echo "Committing the changes with $GIT_USER <$GIT_EMAIL>..." +git config --global user.name "$GIT_USER" +git config --global user.email "$GIT_EMAIL" git commit -m "$COMMIT_MESSAGE" # Push the changes to the new branch @@ -40,7 +45,7 @@ echo "Resolved repo owner and name: $REPO_OWNER, $REPO_NAME" echo "Creating a pull request..." curl -X POST \ - -H "Authorization: token ${GITHUB_TOKEN}" \ + -H "Authorization: token ${GIT_TOKEN}" \ -H "Accept: application/vnd.github.v3+json" \ --fail -d @- \ diff --git a/network-glue/hooks/hook.sh b/network-glue/hooks/hook.sh index 2263a2e..815fb79 100755 --- a/network-glue/hooks/hook.sh +++ b/network-glue/hooks/hook.sh @@ -24,7 +24,7 @@ else target=$(jq -r '.[0].object.spec.target.networkCIDR' "${BINDING_CONTEXT_PATH}") targetPort=$(jq -r '.[0].object.spec.target.port' "${BINDING_CONTEXT_PATH}") - export REPO_URL="$REPO_URL" + export REPO_URL="$(echo $REPO_URL | tr -d '\n ')" # strip newlines export REPO_DIR=/git export BRANCH_NAME="feature/update-config-$(date +%Y%m%d-%H%M%S)" export FILE_TO_UPDATE="$REPO_DIR/$namespace-$name.json"