From 640c0c2bf8f3f2e71b49c8cfa7445a9ff1ea60f8 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Mon, 8 Mar 2021 18:02:15 -0800 Subject: [PATCH 01/33] manifest generation diff first pass --- gitops/azure-devops/build.sh | 44 +++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 2b751b6..9185a70 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -68,7 +68,7 @@ function download_fab() { echo "Latest Fabrikate Version: $VERSION_TO_DOWNLOAD" os='' get_os os - fab_wget=$(wget -SO- "https://github.com/Microsoft/fabrikate/releases/download/$VERSION_TO_DOWNLOAD/fab-v$VERSION_TO_DOWNLOAD-$os-amd64.zip" 2>&1 | grep -E -i "302") + fab_wget=$(wget -q -SO- "https://github.com/Microsoft/fabrikate/releases/download/$VERSION_TO_DOWNLOAD/fab-v$VERSION_TO_DOWNLOAD-$os-amd64.zip" 2>&1 | grep -E -i "302") if [[ $fab_wget == *"302 Found"* ]]; then echo "Fabrikate $VERSION_TO_DOWNLOAD downloaded successfully." else @@ -90,6 +90,12 @@ function install_hld() { repo_name=${repo%%.*} echo "Setting HLD path to $repo_name" cd "$repo_name" + + # if branch name is specified, switch to that HLD branch + if [ -z "$HLD_BRANCH" ]; then + git checkout $HLD_BRANCH + fi + echo "HLD DOWNLOADED SUCCESSFULLY" } @@ -145,6 +151,42 @@ function fab_generate() { fi } +function manifest_diff_into_pr() { + echo $1 + echo $2 + HLD_BRANCH=$2 + + install_fab + fab_generate + git_connect + + rm -rf */ + + if [ -z "$FAB_ENVS" ]; then + cp -a $manifest_files_location/. . + else + IFS=',' read -ra ENV <<< "$FAB_ENVS" + for i in "${ENV[@]}" + do + cp -R ../generated/$i ./ + done + fi + + if [[ $(git status --porcelain) ]]; then + echo "The following diff will be applied to cluster-manifests upon merge:" > diff.txt + git diff | tee -a diff.txt + MESSAGE=$(sed 's/^.\{1,\}$/"&"/' diff.txt) + echo "az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000})" + + # description only allows 4000 characters at max + az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000}) + else + echo "Manifest generation files will not be modified at all." + az repos pr update --id $1 --description "Manifest generation files will not be modified at all." + fi + +} + # Support backward compat for a bit function get_spk_version() { # shellcheck disable=SC2153 From a2f8a517fa81fc971c3adfa258008b616a6df7be Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Mon, 8 Mar 2021 18:19:09 -0800 Subject: [PATCH 02/33] download fabrikate zip as a random filename --- gitops/azure-devops/build.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 9185a70..586555c 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -74,8 +74,9 @@ function download_fab() { else echo "There was an error when downloading Fabrikate. Please check version number and try again." fi - wget "https://github.com/Microsoft/fabrikate/releases/download/$VERSION_TO_DOWNLOAD/fab-v$VERSION_TO_DOWNLOAD-$os-amd64.zip" - unzip "fab-v$VERSION_TO_DOWNLOAD-$os-amd64.zip" -d fab + filename=$(uuidgen) + wget -q -O "$filename.zip" "https://github.com/Microsoft/fabrikate/releases/download/$VERSION_TO_DOWNLOAD/fab-v$VERSION_TO_DOWNLOAD-$os-amd64.zip" + unzip "$filename.zip" -d fab export PATH=$PATH:$HOME/fab } @@ -155,7 +156,8 @@ function manifest_diff_into_pr() { echo $1 echo $2 HLD_BRANCH=$2 - + + download_fab install_fab fab_generate git_connect @@ -230,13 +232,13 @@ function download_spk() { echo "Deprecated SPK Version: $SPK_VERSION_TO_DOWNLOAD" os='' get_os_bedrock os - spk_wget=$(wget -SO- "https://github.com/microsoft/bedrock-cli/releases/download/$SPK_VERSION_TO_DOWNLOAD/spk-$os" 2>&1 | grep -E -i "302") + spk_wget=$(wget -q -SO- "https://github.com/microsoft/bedrock-cli/releases/download/$SPK_VERSION_TO_DOWNLOAD/spk-$os" 2>&1 | grep -E -i "302") if [[ $spk_wget == *"302 Found"* ]]; then echo "SPK $SPK_VERSION_TO_DOWNLOAD downloaded successfully." else echo "There was an error when downloading SPK. Please check version number and try again." fi - wget "https://github.com/microsoft/bedrock-cli/releases/download/$SPK_VERSION_TO_DOWNLOAD/spk-$os" + wget -q "https://github.com/microsoft/bedrock-cli/releases/download/$SPK_VERSION_TO_DOWNLOAD/spk-$os" mkdir spk mv spk-$os spk/spk chmod +x spk/spk From 1c10a5feb48c8571964d887a83e88526bb5b3cc9 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Mon, 8 Mar 2021 18:24:22 -0800 Subject: [PATCH 03/33] do not silence wget output --- gitops/azure-devops/build.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 586555c..7d38816 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -68,7 +68,7 @@ function download_fab() { echo "Latest Fabrikate Version: $VERSION_TO_DOWNLOAD" os='' get_os os - fab_wget=$(wget -q -SO- "https://github.com/Microsoft/fabrikate/releases/download/$VERSION_TO_DOWNLOAD/fab-v$VERSION_TO_DOWNLOAD-$os-amd64.zip" 2>&1 | grep -E -i "302") + fab_wget=$(wget -SO- "https://github.com/Microsoft/fabrikate/releases/download/$VERSION_TO_DOWNLOAD/fab-v$VERSION_TO_DOWNLOAD-$os-amd64.zip" 2>&1 | grep -E -i "302") if [[ $fab_wget == *"302 Found"* ]]; then echo "Fabrikate $VERSION_TO_DOWNLOAD downloaded successfully." else @@ -232,7 +232,7 @@ function download_spk() { echo "Deprecated SPK Version: $SPK_VERSION_TO_DOWNLOAD" os='' get_os_bedrock os - spk_wget=$(wget -q -SO- "https://github.com/microsoft/bedrock-cli/releases/download/$SPK_VERSION_TO_DOWNLOAD/spk-$os" 2>&1 | grep -E -i "302") + spk_wget=$(wget -SO- "https://github.com/microsoft/bedrock-cli/releases/download/$SPK_VERSION_TO_DOWNLOAD/spk-$os" 2>&1 | grep -E -i "302") if [[ $spk_wget == *"302 Found"* ]]; then echo "SPK $SPK_VERSION_TO_DOWNLOAD downloaded successfully." else @@ -258,7 +258,7 @@ function download_bedrock() { else echo "There was an error when downloading Bedrock CLI. Please check version number and try again." fi - wget "https://github.com/microsoft/bedrock-cli/releases/download/$CLI_VERSION_TO_DOWNLOAD/bedrock-$os" + wget -q "https://github.com/microsoft/bedrock-cli/releases/download/$CLI_VERSION_TO_DOWNLOAD/bedrock-$os" mkdir bedrock mv bedrock-$os bedrock/bedrock chmod +x bedrock/bedrock From 5a8d526ea66d37982df7a86fc72b46aa93d9855f Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Mon, 8 Mar 2021 18:47:32 -0800 Subject: [PATCH 04/33] debugging fab generate diff --- gitops/azure-devops/build.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 7d38816..c87bef5 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -74,9 +74,9 @@ function download_fab() { else echo "There was an error when downloading Fabrikate. Please check version number and try again." fi - filename=$(uuidgen) - wget -q -O "$filename.zip" "https://github.com/Microsoft/fabrikate/releases/download/$VERSION_TO_DOWNLOAD/fab-v$VERSION_TO_DOWNLOAD-$os-amd64.zip" - unzip "$filename.zip" -d fab + filename="$(uuidgen).zip" + wget -q -O $filename "https://github.com/Microsoft/fabrikate/releases/download/$VERSION_TO_DOWNLOAD/fab-v$VERSION_TO_DOWNLOAD-$os-amd64.zip" + unzip $filename -d fab export PATH=$PATH:$HOME/fab } @@ -145,7 +145,7 @@ function fab_generate() { # generated folder should still not be empty if find "generated" -mindepth 1 -print -quit 2>/dev/null | grep -q .; then export manifest_files_location=$(pwd) - echo "Manifest files have been generated in 'pwd'." + echo "Manifest files have been generated in $manifest_files_location." else echo "Manifest files could not be generated in 'pwd', quitting..." exit 1 @@ -162,21 +162,27 @@ function manifest_diff_into_pr() { fab_generate git_connect + ls -al + echo "about to replace manifests with new ones" rm -rf */ if [ -z "$FAB_ENVS" ]; then cp -a $manifest_files_location/. . + ls -al else IFS=',' read -ra ENV <<< "$FAB_ENVS" for i in "${ENV[@]}" do cp -R ../generated/$i ./ done + + ls -al fi if [[ $(git status --porcelain) ]]; then echo "The following diff will be applied to cluster-manifests upon merge:" > diff.txt git diff | tee -a diff.txt + cat diff.txt MESSAGE=$(sed 's/^.\{1,\}$/"&"/' diff.txt) echo "az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000})" From c6f6a56f193755b1dcca5cad4c31520fd6d042ae Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Mon, 8 Mar 2021 18:54:11 -0800 Subject: [PATCH 05/33] fix manifest_files_location path --- gitops/azure-devops/build.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index c87bef5..5713479 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -144,7 +144,7 @@ function fab_generate() { # In the case that all components are removed from the source hld, # generated folder should still not be empty if find "generated" -mindepth 1 -print -quit 2>/dev/null | grep -q .; then - export manifest_files_location=$(pwd) + export manifest_files_location=$(pwd)/generated/ echo "Manifest files have been generated in $manifest_files_location." else echo "Manifest files could not be generated in 'pwd', quitting..." @@ -167,7 +167,7 @@ function manifest_diff_into_pr() { rm -rf */ if [ -z "$FAB_ENVS" ]; then - cp -a $manifest_files_location/. . + cp -a $manifest_files_location. . ls -al else IFS=',' read -ra ENV <<< "$FAB_ENVS" @@ -306,8 +306,8 @@ function git_commit() { echo "GIT REMOVE" rm -rf ./*/ git rm -rf ./*/ - echo "COPY YAML FILES FROM $manifest_files_location/generated/ TO REPO DIRECTORY..." - cp -r "$manifest_files_location/generated/"* . + echo "COPY YAML FILES FROM $manifest_files_location TO REPO DIRECTORY..." + cp -r "$manifest_files_location"* . echo "GIT ADD" git add -A From 475d4a3eb64d3ab2df99f9b5caa9072dae374f60 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Mon, 8 Mar 2021 18:59:06 -0800 Subject: [PATCH 06/33] fix HLD_BRANCH issue --- gitops/azure-devops/build.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 5713479..9c2aef3 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -94,6 +94,9 @@ function install_hld() { # if branch name is specified, switch to that HLD branch if [ -z "$HLD_BRANCH" ]; then + echo "HLD_BRANCH is not specified, skip changing branch" + else + echo "Switching to HLD branch $HLD_BRANCH" git checkout $HLD_BRANCH fi From a89a3e19996466bacd6464e1fc250e2fd426d43a Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 09:47:26 -0800 Subject: [PATCH 07/33] introduce ```diff --- gitops/azure-devops/build.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 9c2aef3..b5dd753 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -184,8 +184,9 @@ function manifest_diff_into_pr() { if [[ $(git status --porcelain) ]]; then echo "The following diff will be applied to cluster-manifests upon merge:" > diff.txt + echo \`\`\`diff >> diff.txt git diff | tee -a diff.txt - cat diff.txt + echo \`\`\` >> diff.txt MESSAGE=$(sed 's/^.\{1,\}$/"&"/' diff.txt) echo "az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000})" From a8fb7bd78edfd99e3cd372fc1b1d010f43896b96 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 09:52:52 -0800 Subject: [PATCH 08/33] escape the backslashes --- gitops/azure-devops/build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index b5dd753..26e6741 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -184,9 +184,9 @@ function manifest_diff_into_pr() { if [[ $(git status --porcelain) ]]; then echo "The following diff will be applied to cluster-manifests upon merge:" > diff.txt - echo \`\`\`diff >> diff.txt + echo "\\\`\\\`\\\`diff" >> diff.txt git diff | tee -a diff.txt - echo \`\`\` >> diff.txt + echo "\\\`\\\`\\\`" >> diff.txt MESSAGE=$(sed 's/^.\{1,\}$/"&"/' diff.txt) echo "az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000})" From 633cb6438e7c9197bddeafde7aef0f566d610387 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 10:23:31 -0800 Subject: [PATCH 09/33] escape the double dashes --- gitops/azure-devops/build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 26e6741..58b3b44 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -188,6 +188,7 @@ function manifest_diff_into_pr() { git diff | tee -a diff.txt echo "\\\`\\\`\\\`" >> diff.txt MESSAGE=$(sed 's/^.\{1,\}$/"&"/' diff.txt) + MESSAGE=$(echo "${MESSAGE//--/}") echo "az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000})" # description only allows 4000 characters at max From daa213aced88baa5b13acfd36383dba30557c5b8 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 11:56:17 -0800 Subject: [PATCH 10/33] Use REST API instead of az cli to update description --- gitops/azure-devops/build.sh | 38 ++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 58b3b44..27cb562 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -84,8 +84,19 @@ function download_fab() { # Install the HLD repo if it's not running as part of the HLD build pipeline function install_hld() { echo "DOWNLOADING HLD REPO" - echo "git clone $HLD_PATH" - git clone "$HLD_PATH" + + # Remove http(s):// protocol from URL so we can insert PA token + repo_url=$HLD_PATH + repo_url="${repo_url#http://}" + repo_url="${repo_url#https://}" + + echo "GIT CLONE: https://automated:@$repo_url" + git clone "https://automated:$ACCESS_TOKEN_SECRET@$repo_url" + retVal=$? && [ $retVal -ne 0 ] && exit $retVal + + # echo "git clone $HLD_PATH" + # git clone "$HLD_PATH" + # Extract repo name from url repo=${HLD_PATH##*/} repo_name=${repo%%.*} @@ -184,15 +195,26 @@ function manifest_diff_into_pr() { if [[ $(git status --porcelain) ]]; then echo "The following diff will be applied to cluster-manifests upon merge:" > diff.txt - echo "\\\`\\\`\\\`diff" >> diff.txt + # echo "\\\`\\\`\\\`diff" >> diff.txt + echo "\`\`\`diff" >> diff.txt git diff | tee -a diff.txt - echo "\\\`\\\`\\\`" >> diff.txt + echo "\`\`\`" >> diff.txt + # echo "\\\`\\\`\\\`" >> diff.txt MESSAGE=$(sed 's/^.\{1,\}$/"&"/' diff.txt) - MESSAGE=$(echo "${MESSAGE//--/}") - echo "az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000})" - # description only allows 4000 characters at max - az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000}) + MESSAGE=$(echo ${MESSAGE:0:4000}) + encoded_token=$(echo -n ':$ACCESS_TOKEN_SECRET' | base64) + + # echo "az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000})" + # az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000}) + + HLD_PATH="${HLD_PATH#http://}" + HLD_PATH="${HLD_PATH#https://}" + arr=($(echo "$HLD_PATH" | tr '/' '\n')) + + echo "curl \"https://dev.azure.com/${a[2]}/${a[3]}/_apis/git/repositories/${a[5]}/pullrequests/$1\?api-version\=6.0\" -X PATCH -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{\"description\": \"$MESSAGE\"}\"" + + curl "https://dev.azure.com/${a[2]}/${a[3]}/_apis/git/repositories/${a[5]}/pullrequests/$1\?api-version\=6.0" -X PATCH -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{\"description\": \"$MESSAGE\"}" else echo "Manifest generation files will not be modified at all." az repos pr update --id $1 --description "Manifest generation files will not be modified at all." From a9fba5c49fecab4b351d91c2a4208700dcd98ad3 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 12:07:52 -0800 Subject: [PATCH 11/33] debugging --- gitops/azure-devops/build.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 27cb562..826b1b4 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -211,6 +211,8 @@ function manifest_diff_into_pr() { HLD_PATH="${HLD_PATH#http://}" HLD_PATH="${HLD_PATH#https://}" arr=($(echo "$HLD_PATH" | tr '/' '\n')) + echo "HLD_PATH=$HLD_PATH" + echo $arr echo "curl \"https://dev.azure.com/${a[2]}/${a[3]}/_apis/git/repositories/${a[5]}/pullrequests/$1\?api-version\=6.0\" -X PATCH -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{\"description\": \"$MESSAGE\"}\"" From eff49d881026402b919a0af5bd4f558514d0679a Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 12:20:47 -0800 Subject: [PATCH 12/33] more debugging --- gitops/azure-devops/build.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 826b1b4..1e93b1f 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -208,13 +208,16 @@ function manifest_diff_into_pr() { # echo "az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000})" # az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000}) + # IFS='/' read -r -a arr <<< "$HLD_PATH" HLD_PATH="${HLD_PATH#http://}" HLD_PATH="${HLD_PATH#https://}" arr=($(echo "$HLD_PATH" | tr '/' '\n')) echo "HLD_PATH=$HLD_PATH" - echo $arr + echo "${arr[4]}" + echo "${arr[2]}" + echo "${arr[1]}" - echo "curl \"https://dev.azure.com/${a[2]}/${a[3]}/_apis/git/repositories/${a[5]}/pullrequests/$1\?api-version\=6.0\" -X PATCH -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{\"description\": \"$MESSAGE\"}\"" + echo "curl \"https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullrequests/$1\?api-version\=6.0\" -X PATCH -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{\"description\": \"$MESSAGE\"}\"" curl "https://dev.azure.com/${a[2]}/${a[3]}/_apis/git/repositories/${a[5]}/pullrequests/$1\?api-version\=6.0" -X PATCH -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{\"description\": \"$MESSAGE\"}" else From 6cd4196ec22629032714a2560c099c21381a1566 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 12:24:05 -0800 Subject: [PATCH 13/33] No double quotes needed --- gitops/azure-devops/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 1e93b1f..7a7992a 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -200,7 +200,7 @@ function manifest_diff_into_pr() { git diff | tee -a diff.txt echo "\`\`\`" >> diff.txt # echo "\\\`\\\`\\\`" >> diff.txt - MESSAGE=$(sed 's/^.\{1,\}$/"&"/' diff.txt) + # MESSAGE=$(sed 's/^.\{1,\}$/"&"/' diff.txt) # description only allows 4000 characters at max MESSAGE=$(echo ${MESSAGE:0:4000}) encoded_token=$(echo -n ':$ACCESS_TOKEN_SECRET' | base64) From 7e2e3acc4288ff6c7756f1e22127c3c15cb58d83 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 12:28:39 -0800 Subject: [PATCH 14/33] No double quotes needed --- gitops/azure-devops/build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 7a7992a..c5c82e3 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -216,6 +216,7 @@ function manifest_diff_into_pr() { echo "${arr[4]}" echo "${arr[2]}" echo "${arr[1]}" + echo $MESSAGE echo "curl \"https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullrequests/$1\?api-version\=6.0\" -X PATCH -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{\"description\": \"$MESSAGE\"}\"" From 508a71562c28c2e910742b123917f49f35ada5fc Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 12:41:48 -0800 Subject: [PATCH 15/33] No double quotes needed --- gitops/azure-devops/build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index c5c82e3..dbac0ce 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -202,6 +202,7 @@ function manifest_diff_into_pr() { # echo "\\\`\\\`\\\`" >> diff.txt # MESSAGE=$(sed 's/^.\{1,\}$/"&"/' diff.txt) # description only allows 4000 characters at max + MESSAGE=$(cat diff.txt) MESSAGE=$(echo ${MESSAGE:0:4000}) encoded_token=$(echo -n ':$ACCESS_TOKEN_SECRET' | base64) From 176760cebbe032454438b76d3d66c34043c88eb9 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 13:00:52 -0800 Subject: [PATCH 16/33] No double quotes needed --- gitops/azure-devops/build.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index dbac0ce..6a9ec65 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -196,15 +196,15 @@ function manifest_diff_into_pr() { if [[ $(git status --porcelain) ]]; then echo "The following diff will be applied to cluster-manifests upon merge:" > diff.txt # echo "\\\`\\\`\\\`diff" >> diff.txt - echo "\`\`\`diff" >> diff.txt + echo "\\\`\\\`\\\`diff" >> diff.txt git diff | tee -a diff.txt - echo "\`\`\`" >> diff.txt + echo "\\\`\\\`\\\`" >> diff.txt # echo "\\\`\\\`\\\`" >> diff.txt # MESSAGE=$(sed 's/^.\{1,\}$/"&"/' diff.txt) # description only allows 4000 characters at max MESSAGE=$(cat diff.txt) MESSAGE=$(echo ${MESSAGE:0:4000}) - encoded_token=$(echo -n ':$ACCESS_TOKEN_SECRET' | base64) + encoded_token=$(echo -n ":$ACCESS_TOKEN_SECRET" | base64) # echo "az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000})" # az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000}) @@ -219,9 +219,11 @@ function manifest_diff_into_pr() { echo "${arr[1]}" echo $MESSAGE - echo "curl \"https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullrequests/$1\?api-version\=6.0\" -X PATCH -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{\"description\": \"$MESSAGE\"}\"" + url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullrequests/$1\?api-version\=6.0" + + echo "curl $url -X PATCH -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{\"description\": \"$MESSAGE\"}\"" - curl "https://dev.azure.com/${a[2]}/${a[3]}/_apis/git/repositories/${a[5]}/pullrequests/$1\?api-version\=6.0" -X PATCH -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{\"description\": \"$MESSAGE\"}" + curl $url -X PATCH -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{\"description\": \"$MESSAGE\"}" else echo "Manifest generation files will not be modified at all." az repos pr update --id $1 --description "Manifest generation files will not be modified at all." From 16918b734bf49df7a333b8eaa7dd2fe86460f029 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 13:11:28 -0800 Subject: [PATCH 17/33] escape the slashes --- gitops/azure-devops/build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 6a9ec65..c490e2f 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -221,9 +221,9 @@ function manifest_diff_into_pr() { url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullrequests/$1\?api-version\=6.0" - echo "curl $url -X PATCH -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{\"description\": \"$MESSAGE\"}\"" + echo "curl $url -X PATCH -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{\\\"description\\\": \\\"$MESSAGE\\\"}\"" - curl $url -X PATCH -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{\"description\": \"$MESSAGE\"}" + curl $url -X PATCH -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{\\\"description\\\": \\\"$MESSAGE\\\"}" else echo "Manifest generation files will not be modified at all." az repos pr update --id $1 --description "Manifest generation files will not be modified at all." From c69e86618129577616f8c36e518d9de192a9f189 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 15:09:26 -0800 Subject: [PATCH 18/33] post as a comment --- gitops/azure-devops/build.sh | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index c490e2f..e0b8439 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -203,7 +203,6 @@ function manifest_diff_into_pr() { # MESSAGE=$(sed 's/^.\{1,\}$/"&"/' diff.txt) # description only allows 4000 characters at max MESSAGE=$(cat diff.txt) - MESSAGE=$(echo ${MESSAGE:0:4000}) encoded_token=$(echo -n ":$ACCESS_TOKEN_SECRET" | base64) # echo "az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000})" @@ -217,18 +216,24 @@ function manifest_diff_into_pr() { echo "${arr[4]}" echo "${arr[2]}" echo "${arr[1]}" + MESSAGE=$(awk '$1=$1' ORS=' \\n ' diff.txt) + MESSAGE=$(echo ${MESSAGE:0:4000}) echo $MESSAGE - url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullrequests/$1\?api-version\=6.0" + # url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullrequests/$1\?api-version\=6.0" + url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullRequests/$1/threads?api-version=6.0" - echo "curl $url -X PATCH -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{\\\"description\\\": \\\"$MESSAGE\\\"}\"" + echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}\"" - curl $url -X PATCH -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{\\\"description\\\": \\\"$MESSAGE\\\"}" + curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}" + + # echo "curl $url -X PATCH -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{\\\"description\\\": \\\"$MESSAGE\\\"}\"" + + # curl $url -X PATCH -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{\\\"description\\\": \\\"$MESSAGE\\\"}" else echo "Manifest generation files will not be modified at all." az repos pr update --id $1 --description "Manifest generation files will not be modified at all." fi - } # Support backward compat for a bit From e86ba6da62df0242fdb2f52d36b29faf3afe27c2 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 15:22:41 -0800 Subject: [PATCH 19/33] post as a comment --- gitops/azure-devops/build.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index e0b8439..ed7cb94 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -225,6 +225,9 @@ function manifest_diff_into_pr() { echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}\"" + cmd="curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}\"" + eval "$cmd" + curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}" # echo "curl $url -X PATCH -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{\\\"description\\\": \\\"$MESSAGE\\\"}\"" From eb76143b0e505fab3738d1c9893944cf471255ff Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 15:39:59 -0800 Subject: [PATCH 20/33] lots of debugging --- gitops/azure-devops/build.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index ed7cb94..27e6710 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -224,12 +224,20 @@ function manifest_diff_into_pr() { url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullRequests/$1/threads?api-version=6.0" echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}\"" - + + echo "try 1" cmd="curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}\"" + echo $cmd eval "$cmd" + echo "try 2" + echo curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}" curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}" + echo "try 3" + echo curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}" + curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}" + # echo "curl $url -X PATCH -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{\\\"description\\\": \\\"$MESSAGE\\\"}\"" # curl $url -X PATCH -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{\\\"description\\\": \\\"$MESSAGE\\\"}" From 650aba7b2b294849bafdb9b69b284592bc0395e6 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 17:04:30 -0800 Subject: [PATCH 21/33] lots of debugging --- gitops/azure-devops/build.sh | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 27e6710..a92df02 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -216,27 +216,40 @@ function manifest_diff_into_pr() { echo "${arr[4]}" echo "${arr[2]}" echo "${arr[1]}" - MESSAGE=$(awk '$1=$1' ORS=' \\n ' diff.txt) + # MESSAGE=$(awk '$1=$1' ORS=' \\n ' diff.txt) MESSAGE=$(echo ${MESSAGE:0:4000}) echo $MESSAGE # url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullrequests/$1\?api-version\=6.0" url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullRequests/$1/threads?api-version=6.0" - echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}\"" + JSON_STRING=$( jq -n --arg comment "$MESSAGE" \ + '{comments: [ { content: $comment } ] }' ) + echo "try 0" + echo curl -X POST $url -H "Content-Type:application/json" --data "$JSON_STRING" -H "Authorization: Basic $encoded_token" + curl -X POST $url -H "Content-Type:application/json" --data "$JSON_STRING" -H "Authorization: Basic $encoded_token" echo "try 1" cmd="curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}\"" echo $cmd eval "$cmd" - - echo "try 2" - echo curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}" - curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}" - echo "try 3" - echo curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}" - curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}" + # echo "try 1.1" + # abcd="{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]} " + # curl -X POST $url -H "Content-Type:application/json" --data "$abcd" -H "Authorization: Basic $encoded_token" + + # echo "\ntry 2" + # echo curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}" + # curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}" + + # echo "\ntry 3" + # data="\"{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}\"" + # echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \\\"$data\\\"" + # curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data $data + + # echo "\ntry 4" + # echo curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}" + # curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}" # echo "curl $url -X PATCH -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{\\\"description\\\": \\\"$MESSAGE\\\"}\"" From a360ae88893e103c35fa0a06194459bb926cd7c7 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 17:15:26 -0800 Subject: [PATCH 22/33] lots of debugging --- gitops/azure-devops/build.sh | 40 ++++++------------------------------ 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index a92df02..1d94d5c 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -196,9 +196,9 @@ function manifest_diff_into_pr() { if [[ $(git status --porcelain) ]]; then echo "The following diff will be applied to cluster-manifests upon merge:" > diff.txt # echo "\\\`\\\`\\\`diff" >> diff.txt - echo "\\\`\\\`\\\`diff" >> diff.txt + echo "\`\`\`diff" >> diff.txt git diff | tee -a diff.txt - echo "\\\`\\\`\\\`" >> diff.txt + echo "\`\`\`" >> diff.txt # echo "\\\`\\\`\\\`" >> diff.txt # MESSAGE=$(sed 's/^.\{1,\}$/"&"/' diff.txt) # description only allows 4000 characters at max @@ -212,48 +212,20 @@ function manifest_diff_into_pr() { HLD_PATH="${HLD_PATH#http://}" HLD_PATH="${HLD_PATH#https://}" arr=($(echo "$HLD_PATH" | tr '/' '\n')) - echo "HLD_PATH=$HLD_PATH" - echo "${arr[4]}" - echo "${arr[2]}" - echo "${arr[1]}" + # echo "HLD_PATH=$HLD_PATH" + # echo "${arr[4]}" + # echo "${arr[2]}" + # echo "${arr[1]}" # MESSAGE=$(awk '$1=$1' ORS=' \\n ' diff.txt) MESSAGE=$(echo ${MESSAGE:0:4000}) echo $MESSAGE - # url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullrequests/$1\?api-version\=6.0" url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullRequests/$1/threads?api-version=6.0" JSON_STRING=$( jq -n --arg comment "$MESSAGE" \ '{comments: [ { content: $comment } ] }' ) - echo "try 0" echo curl -X POST $url -H "Content-Type:application/json" --data "$JSON_STRING" -H "Authorization: Basic $encoded_token" curl -X POST $url -H "Content-Type:application/json" --data "$JSON_STRING" -H "Authorization: Basic $encoded_token" - - echo "try 1" - cmd="curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}\"" - echo $cmd - eval "$cmd" - - # echo "try 1.1" - # abcd="{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]} " - # curl -X POST $url -H "Content-Type:application/json" --data "$abcd" -H "Authorization: Basic $encoded_token" - - # echo "\ntry 2" - # echo curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}" - # curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}" - - # echo "\ntry 3" - # data="\"{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}\"" - # echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \\\"$data\\\"" - # curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data $data - - # echo "\ntry 4" - # echo curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}" - # curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}" - - # echo "curl $url -X PATCH -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{\\\"description\\\": \\\"$MESSAGE\\\"}\"" - - # curl $url -X PATCH -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{\\\"description\\\": \\\"$MESSAGE\\\"}" else echo "Manifest generation files will not be modified at all." az repos pr update --id $1 --description "Manifest generation files will not be modified at all." From c69ba709645b48752c35d00ee9f7609a4f48765c Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Tue, 9 Mar 2021 17:27:30 -0800 Subject: [PATCH 23/33] lots of debugging --- gitops/azure-devops/build.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 1d94d5c..c2f501c 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -220,12 +220,23 @@ function manifest_diff_into_pr() { MESSAGE=$(echo ${MESSAGE:0:4000}) echo $MESSAGE + # url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullrequests/$1\?api-version\=6.0" url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullRequests/$1/threads?api-version=6.0" - + echo "------------------------------------------------------------" JSON_STRING=$( jq -n --arg comment "$MESSAGE" \ '{comments: [ { content: $comment } ] }' ) - echo curl -X POST $url -H "Content-Type:application/json" --data "$JSON_STRING" -H "Authorization: Basic $encoded_token" + echo "curl -X POST $url -H \"Content-Type:application/json\" --data \"$JSON_STRING\" -H \"Authorization: Basic $encoded_token\"" curl -X POST $url -H "Content-Type:application/json" --data "$JSON_STRING" -H "Authorization: Basic $encoded_token" + echo "------------------------------------------------------------" + + echo "\ntry 2" + echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}\"" + curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}" + + echo "\ntry 3" + echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}\"" + curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}" + else echo "Manifest generation files will not be modified at all." az repos pr update --id $1 --description "Manifest generation files will not be modified at all." From 50edf5489311acb6ed48a3f520bee36c43f5abbd Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Wed, 10 Mar 2021 09:02:43 -0800 Subject: [PATCH 24/33] lots of debugging --- gitops/azure-devops/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index c2f501c..4f584dc 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -216,7 +216,7 @@ function manifest_diff_into_pr() { # echo "${arr[4]}" # echo "${arr[2]}" # echo "${arr[1]}" - # MESSAGE=$(awk '$1=$1' ORS=' \\n ' diff.txt) + MESSAGE=$(awk '$1=$1' ORS=' \\n ' diff.txt) MESSAGE=$(echo ${MESSAGE:0:4000}) echo $MESSAGE From 924ec363a23b338e2113a6eb6ccc6d5de45a0c4c Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Wed, 10 Mar 2021 09:10:43 -0800 Subject: [PATCH 25/33] lots of debugging --- gitops/azure-devops/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 4f584dc..5d76c61 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -216,7 +216,7 @@ function manifest_diff_into_pr() { # echo "${arr[4]}" # echo "${arr[2]}" # echo "${arr[1]}" - MESSAGE=$(awk '$1=$1' ORS=' \\n ' diff.txt) + MESSAGE=$(awk '$1=$1' ORS=' \n ' diff.txt) MESSAGE=$(echo ${MESSAGE:0:4000}) echo $MESSAGE From c6f38edf03f27c513af88b6d0c1774baf2dd7754 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Wed, 10 Mar 2021 09:14:58 -0800 Subject: [PATCH 26/33] lots of debugging --- gitops/azure-devops/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 5d76c61..4f584dc 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -216,7 +216,7 @@ function manifest_diff_into_pr() { # echo "${arr[4]}" # echo "${arr[2]}" # echo "${arr[1]}" - MESSAGE=$(awk '$1=$1' ORS=' \n ' diff.txt) + MESSAGE=$(awk '$1=$1' ORS=' \\n ' diff.txt) MESSAGE=$(echo ${MESSAGE:0:4000}) echo $MESSAGE From a0a1c4fc8e880463bc1c088a2eaeeb7378379676 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Wed, 10 Mar 2021 09:24:45 -0800 Subject: [PATCH 27/33] lots of debugging --- gitops/azure-devops/build.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 4f584dc..9e6ea69 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -222,12 +222,7 @@ function manifest_diff_into_pr() { # url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullrequests/$1\?api-version\=6.0" url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullRequests/$1/threads?api-version=6.0" - echo "------------------------------------------------------------" - JSON_STRING=$( jq -n --arg comment "$MESSAGE" \ - '{comments: [ { content: $comment } ] }' ) - echo "curl -X POST $url -H \"Content-Type:application/json\" --data \"$JSON_STRING\" -H \"Authorization: Basic $encoded_token\"" - curl -X POST $url -H "Content-Type:application/json" --data "$JSON_STRING" -H "Authorization: Basic $encoded_token" - echo "------------------------------------------------------------" + echo "\ntry 2" echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}\"" @@ -237,6 +232,13 @@ function manifest_diff_into_pr() { echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}\"" curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}" + echo "\n------------------------------------------------------------" + JSON_STRING=$( jq -n --arg comment "$MESSAGE" \ + '{comments: [ { content: $comment } ] }' ) + echo "curl -X POST $url -H \"Content-Type:application/json\" --data \"$JSON_STRING\" -H \"Authorization: Basic $encoded_token\"" + curl -X POST $url -H "Content-Type:application/json" --data "$JSON_STRING" -H "Authorization: Basic $encoded_token" + echo "\n------------------------------------------------------------" + else echo "Manifest generation files will not be modified at all." az repos pr update --id $1 --description "Manifest generation files will not be modified at all." From 3fed281f7d4cc90e46c3b883f6ebd45daefe62b2 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Wed, 10 Mar 2021 09:54:38 -0800 Subject: [PATCH 28/33] lots of debugging --- gitops/azure-devops/build.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 9e6ea69..b6168c3 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -224,20 +224,20 @@ function manifest_diff_into_pr() { url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullRequests/$1/threads?api-version=6.0" - echo "\ntry 2" - echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}\"" - curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}" + # echo "\ntry 2" + # echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}\"" + # curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}" echo "\ntry 3" echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}\"" curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}" - echo "\n------------------------------------------------------------" - JSON_STRING=$( jq -n --arg comment "$MESSAGE" \ - '{comments: [ { content: $comment } ] }' ) - echo "curl -X POST $url -H \"Content-Type:application/json\" --data \"$JSON_STRING\" -H \"Authorization: Basic $encoded_token\"" - curl -X POST $url -H "Content-Type:application/json" --data "$JSON_STRING" -H "Authorization: Basic $encoded_token" - echo "\n------------------------------------------------------------" + # echo "\n------------------------------------------------------------" + # JSON_STRING=$( jq -n --arg comment "$MESSAGE" \ + # '{comments: [ { content: $comment } ] }' ) + # echo "curl -X POST $url -H \"Content-Type:application/json\" --data \"$JSON_STRING\" -H \"Authorization: Basic $encoded_token\"" + # curl -X POST $url -H "Content-Type:application/json" --data "$JSON_STRING" -H "Authorization: Basic $encoded_token" + # echo "\n------------------------------------------------------------" else echo "Manifest generation files will not be modified at all." From 8fa2f4faff19d7d2afec9ac75adc245c4369054b Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Wed, 10 Mar 2021 10:09:32 -0800 Subject: [PATCH 29/33] code cleanup --- gitops/azure-devops/build.sh | 51 ++++++++++-------------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index b6168c3..5673e1d 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -193,55 +193,32 @@ function manifest_diff_into_pr() { ls -al fi + encoded_token=$(echo -n ":$ACCESS_TOKEN_SECRET" | base64) + + url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullRequests/$1/threads?api-version=6.0" + + # Break down the HLD path to extract org, project and repo name + HLD_PATH="${HLD_PATH#http://}" + HLD_PATH="${HLD_PATH#https://}" + arr=($(echo "$HLD_PATH" | tr '/' '\n')) + if [[ $(git status --porcelain) ]]; then echo "The following diff will be applied to cluster-manifests upon merge:" > diff.txt - # echo "\\\`\\\`\\\`diff" >> diff.txt echo "\`\`\`diff" >> diff.txt git diff | tee -a diff.txt echo "\`\`\`" >> diff.txt - # echo "\\\`\\\`\\\`" >> diff.txt - # MESSAGE=$(sed 's/^.\{1,\}$/"&"/' diff.txt) - # description only allows 4000 characters at max - MESSAGE=$(cat diff.txt) - encoded_token=$(echo -n ":$ACCESS_TOKEN_SECRET" | base64) - - # echo "az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000})" - # az repos pr update --id $1 --description $(echo ${MESSAGE:0:4000}) - - # IFS='/' read -r -a arr <<< "$HLD_PATH" - HLD_PATH="${HLD_PATH#http://}" - HLD_PATH="${HLD_PATH#https://}" - arr=($(echo "$HLD_PATH" | tr '/' '\n')) - # echo "HLD_PATH=$HLD_PATH" - # echo "${arr[4]}" - # echo "${arr[2]}" - # echo "${arr[1]}" + + # separate them out by new line characters MESSAGE=$(awk '$1=$1' ORS=' \\n ' diff.txt) - MESSAGE=$(echo ${MESSAGE:0:4000}) - echo $MESSAGE - # url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullrequests/$1\?api-version\=6.0" - url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullRequests/$1/threads?api-version=6.0" + # description only allows 4000 characters at max + MESSAGE=$(echo ${MESSAGE:0:4000}) - - # echo "\ntry 2" - # echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}\"" - # curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \\\"comments\\\": [ { \\\"content\\\": \\\"$MESSAGE\\\" } ]}" - - echo "\ntry 3" - echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}\"" curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}" - # echo "\n------------------------------------------------------------" - # JSON_STRING=$( jq -n --arg comment "$MESSAGE" \ - # '{comments: [ { content: $comment } ] }' ) - # echo "curl -X POST $url -H \"Content-Type:application/json\" --data \"$JSON_STRING\" -H \"Authorization: Basic $encoded_token\"" - # curl -X POST $url -H "Content-Type:application/json" --data "$JSON_STRING" -H "Authorization: Basic $encoded_token" - # echo "\n------------------------------------------------------------" - else echo "Manifest generation files will not be modified at all." - az repos pr update --id $1 --description "Manifest generation files will not be modified at all." + curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"Manifest generation files will not be modified at all.\" } ]}" fi } From a44c7e583adf40eefb179c4bdd23d5b487e1a7ab Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Wed, 10 Mar 2021 10:13:57 -0800 Subject: [PATCH 30/33] code cleanup --- gitops/azure-devops/build.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 5673e1d..2142bd4 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -195,12 +195,12 @@ function manifest_diff_into_pr() { encoded_token=$(echo -n ":$ACCESS_TOKEN_SECRET" | base64) - url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullRequests/$1/threads?api-version=6.0" - # Break down the HLD path to extract org, project and repo name HLD_PATH="${HLD_PATH#http://}" HLD_PATH="${HLD_PATH#https://}" arr=($(echo "$HLD_PATH" | tr '/' '\n')) + + url="https://dev.azure.com/${arr[1]}/${arr[2]}/_apis/git/repositories/${arr[4]}/pullRequests/$1/threads?api-version=6.0" if [[ $(git status --porcelain) ]]; then echo "The following diff will be applied to cluster-manifests upon merge:" > diff.txt @@ -213,9 +213,8 @@ function manifest_diff_into_pr() { # description only allows 4000 characters at max MESSAGE=$(echo ${MESSAGE:0:4000}) - + echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}\"" curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}" - else echo "Manifest generation files will not be modified at all." curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"Manifest generation files will not be modified at all.\" } ]}" From 893be9a1550b7f1999de1751df11669e81d541e0 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Wed, 10 Mar 2021 10:18:52 -0800 Subject: [PATCH 31/33] more code cleanup --- gitops/azure-devops/build.sh | 7 ------- 1 file changed, 7 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index 2142bd4..cd3e5c7 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -167,8 +167,6 @@ function fab_generate() { } function manifest_diff_into_pr() { - echo $1 - echo $2 HLD_BRANCH=$2 download_fab @@ -176,21 +174,16 @@ function manifest_diff_into_pr() { fab_generate git_connect - ls -al - echo "about to replace manifests with new ones" rm -rf */ if [ -z "$FAB_ENVS" ]; then cp -a $manifest_files_location. . - ls -al else IFS=',' read -ra ENV <<< "$FAB_ENVS" for i in "${ENV[@]}" do cp -R ../generated/$i ./ done - - ls -al fi encoded_token=$(echo -n ":$ACCESS_TOKEN_SECRET" | base64) From ed7c7a02e8fed5e7ee88ea751b5a0db8c20f1f57 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Wed, 10 Mar 2021 10:24:09 -0800 Subject: [PATCH 32/33] No longer a need to cap it at 4000 characters --- gitops/azure-devops/build.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index cd3e5c7..e8cf343 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -203,10 +203,7 @@ function manifest_diff_into_pr() { # separate them out by new line characters MESSAGE=$(awk '$1=$1' ORS=' \\n ' diff.txt) - - # description only allows 4000 characters at max - MESSAGE=$(echo ${MESSAGE:0:4000}) - echo "curl -X POST $url -H \"Authorization: Basic $encoded_token\" -H \"Content-Type:application/json\" --data \"{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}\"" + curl -X POST $url -H "Authorization: Basic $encoded_token" -H "Content-Type:application/json" --data "{ \"comments\": [ { \"content\": \"$MESSAGE\" } ]}" else echo "Manifest generation files will not be modified at all." From 1f060e9d5a7901480dcae55a383f31e758a5fe26 Mon Sep 17 00:00:00 2001 From: Samiya Akhtar Date: Wed, 10 Mar 2021 14:09:55 -0800 Subject: [PATCH 33/33] remove commented code --- gitops/azure-devops/build.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/gitops/azure-devops/build.sh b/gitops/azure-devops/build.sh index e8cf343..288a77f 100644 --- a/gitops/azure-devops/build.sh +++ b/gitops/azure-devops/build.sh @@ -94,9 +94,6 @@ function install_hld() { git clone "https://automated:$ACCESS_TOKEN_SECRET@$repo_url" retVal=$? && [ $retVal -ne 0 ] && exit $retVal - # echo "git clone $HLD_PATH" - # git clone "$HLD_PATH" - # Extract repo name from url repo=${HLD_PATH##*/} repo_name=${repo%%.*}