@@ -75,21 +75,40 @@ steps:
7575 set -e
7676
7777 # Retrieve most recent commit hash from HLD repo
78- commit_hash=$(git rev-parse HEAD)
78+ commit_hash=$(git rev-parse HEAD | cut -c1-7 )
7979 echo "Commit Hash: $commit_hash"
8080
8181 # Clone Generated Repo and copy generated components over
8282 echo "Cloning Generated Repo: $GENERATED_REPO"
8383 git clone $GENERATED_REPO
84+ repo_url=$GENERATED_REPO
8485
8586 # Extract repo name from url
86- repo_url=$GENERATED_REPO
8787 repo=${repo_url##*/}
8888 repo_name=${repo%.*}
8989
9090 cd "$repo_name"
91+
92+ git pull
93+
9194 rsync -rv --exclude=.terraform $HOME/$PROJECT_DIRECTORY-generated .
9295
96+ # Check if PR branch already exists:
97+ pr_list=$(git ls-remote origin)
98+ if [[ $pr_list == *"pr-$commit_hash"* ]]; then
99+ echo "PR Branch already exist. Iterating..."
100+ count=$(git ls-remote origin | grep "pr-$commit_hash" | wc -l | tr -d " ")
101+ count=$((count + 1))
102+ PR_BRANCH_NAME=pr-$commit_hash-$count
103+ echo "PR BRANCH NAME: $PR_BRANCH_NAME"
104+ git checkout -b $PR_BRANCH_NAME
105+ else
106+ echo "PR Branch does not exist. Creating a new PR Branch"
107+ PR_BRANCH_NAME=pr-$commit_hash-1
108+ echo "PR BRANCH NAME: $PR_BRANCH_NAME"
109+ git checkout -b $PR_BRANCH_NAME
110+ fi
111+
93112 # Set git identity
94113 git config user.email "admin@azuredevops.com"
95114 git config user.name "Automated Account"
@@ -101,7 +120,7 @@ steps:
101120
102121 # Format Terraform files
103122 terraform fmt
104-
123+
105124 # Add generated files to repository
106125 git status
107126 git add .
@@ -142,4 +161,4 @@ steps:
142161 fi
143162 env :
144163 ACCESS_TOKEN_SECRET : $(ACCESS_TOKEN_SECRET)
145- displayName : ' Commit and Push to Generated Repository'
164+ displayName : ' Commit and Push to Generated Repository'
0 commit comments