Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit a623bd8

Browse files
authored
Resolve fetching PR titles when approving PRs (#357)
1 parent 2266ba4 commit a623bd8

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

tests/functions.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ function variable_group_variable_create () {
157157
n=$4
158158
v=$5
159159
s=$6
160-
160+
161161
echo "Create variable '$n' in variable group"
162162
if [ "$s" = "secret" ]; then
163163
result=$(az pipelines variable-group variable create --id $id --org $org -p $p --name $n --value $v --secret)
@@ -172,7 +172,7 @@ function storage_account_exists () {
172172
sa_result=$(az storage account list --resource-group $rg)
173173
sa_exists=$(echo $sa_result | jq -r --arg sa_name "$sa_name" '.[].name | select(. == $sa_name ) != null')
174174
action=$3
175-
175+
176176
if [ "$sa_exists" = "true" ]; then
177177
echo "The storage account '$sa_name' exists "
178178
if [ "$action" == "delete" ]; then
@@ -358,7 +358,7 @@ function create_spk_project_and_service () {
358358
cd $TEST_WORKSPACE
359359
mkdir $repo_dir_name
360360
cd $repo_dir_name
361-
git init
361+
git init
362362

363363
$spk project init #>> $TEST_WORKSPACE/log.txt
364364
file_we_expect=("spk.log" ".gitignore" "bedrock.yaml" "maintainers.yaml" "hld-lifecycle.yaml")
@@ -378,18 +378,18 @@ function create_spk_project_and_service () {
378378
echo "$spk service create . -n "$repo_dir_name-service" -p "$repo_dir_name/chart" -g $helm_repo_url -b master"
379379
$spk service create . -n "$repo_dir_name-service" -p "$repo_dir_name/chart" -g $helm_repo_url -b master >> $TEST_WORKSPACE/log.txt
380380
directory_to_check="$TEST_WORKSPACE/$repo_dir_name"
381-
file_we_expect=(".gitignore" "build-update-hld.yaml" "Dockerfile" "maintainers.yaml" "hld-lifecycle.yaml" "spk.log" "bedrock.yaml")
381+
file_we_expect=(".gitignore" "build-update-hld.yaml" "Dockerfile" "maintainers.yaml" "hld-lifecycle.yaml" "spk.log" "bedrock.yaml")
382382
validate_directory $directory_to_check "${file_we_expect[@]}"
383-
}
383+
}
384384

385385
function create_helm_chart_v2 () {
386386
mkdir chart
387387
cd chart
388388
touch Chart.yaml
389-
eval "echo \"$(cat $1//test.Chart.yaml)\"" > Chart.yaml
390-
389+
eval "echo \"$(cat $1//test.Chart.yaml)\"" > Chart.yaml
390+
391391
touch values.yaml
392-
eval "echo \"$(cat $1//test.values.yaml)\"" > values.yaml
392+
eval "echo \"$(cat $1//test.values.yaml)\"" > values.yaml
393393

394394
touch .helmignore
395395
echo "
@@ -428,7 +428,7 @@ echo "
428428
function create_access_yaml () {
429429
touch access.yaml
430430
echo "$1: $2" >> access.yaml
431-
}
431+
}
432432

433433
function create_manifest_repo () {
434434
mkdir $1
@@ -493,7 +493,7 @@ function push_remote_git_repo () {
493493
git remote add origin https://service_account:$ACCESS_TOKEN_SECRET@$repo_url
494494
echo "git push"
495495
git push -u origin --all
496-
496+
497497
cd ..
498498
}
499499

@@ -520,14 +520,14 @@ function approve_pull_request () {
520520
echo "PR for '$pr_title' not found"
521521
exit 1
522522
fi
523-
real_title=$(echo $all_prs | jq -r --arg pr_title "$pr_title" 'select(.[].title | startswith($pr_title)) | .[].title')
523+
real_title=$(echo $all_prs | jq -r --arg pr_title "$pr_title" 'select(.[].title | startswith($pr_title)) | .[].title' | head -n 1)
524524
pull_request_id=$(echo $all_prs | jq -r --arg pr_title "$pr_title" 'select(.[].title | startswith($pr_title)) | .[0].pullRequestId')
525525
echo "Found pull request starting with phrase '$pr_title'"
526526
echo "Pull request id $pull_request_id is '$real_title'"
527527

528528
approve_result=$(az repos pr update --id "$pull_request_id" --auto-complete true --output json )
529529
approve_result="${approve_result//\\n/}" #Escape the JSON result
530-
530+
531531
if [ "$(echo $approve_result | jq '.mergeStatus' | grep 'succeeded')" != "" ]; then
532532
echo "PR $pull_request_id approved"
533533
else

0 commit comments

Comments
 (0)