Skip to content

Commit 2c7eb14

Browse files
Merge pull request #23 from gitbito/release/1.3.0-scripts
script change merged into release/1.3.0
2 parents 77189d8 + 03198cc commit 2c7eb14

File tree

3 files changed

+80
-7
lines changed

3 files changed

+80
-7
lines changed

cra-scripts/bito-cra.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ dependency_check.snyk_auth_token=
1414
review_comments=2
1515
server_port=10051
1616
cra_version=latest
17-
exclude_branches=
17+
exclude_branches=main,master
18+
exclude_files=*.xml,*.json,*.properties,.gitignore,*.yml,*.md
19+
exclude_draft_pr=True

cra-scripts/bito-cra.ps1

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,16 @@ function Validate-ReviewComments {
112112
}
113113
}
114114

115+
$crEventType = "automated"
116+
function ValidateCrEventType {
117+
param($crEventTypeVal)
118+
if ($crEventTypeVal -eq "manual"){
119+
return "manual"
120+
}else {
121+
return "automated"
122+
}
123+
}
124+
115125
# Function to display URL using IP address and port
116126
# Run docker ps -l command and store the output
117127
function Display-DockerUrl {
@@ -356,6 +366,8 @@ $optional_params_cli = @(
356366
"static_analysis_tool",
357367
"review_scope",
358368
"exclude_branches",
369+
"exclude_files",
370+
"exclude_draft_pr",
359371
"dependency_check",
360372
"dependency_check.snyk_auth_token",
361373
"cra_version",
@@ -364,6 +376,7 @@ $optional_params_cli = @(
364376
"output_path"
365377
"git.domain"
366378
"code_context"
379+
"cr_event_type"
367380
)
368381

369382
# Parameters that are required/optional in mode server
@@ -381,6 +394,8 @@ $optional_params_server = @(
381394
"static_analysis_tool",
382395
"review_scope",
383396
"exclude_branches",
397+
"exclude_files",
398+
"exclude_draft_pr",
384399
"dependency_check",
385400
"dependency_check.snyk_auth_token",
386401
"server_port",
@@ -389,6 +404,7 @@ $optional_params_server = @(
389404
"cli_path"
390405
"git.domain"
391406
"code_context"
407+
"cr_event_type"
392408
)
393409

394410
$bee_params = @(
@@ -457,7 +473,7 @@ foreach ($param in $required_params) {
457473
foreach ($param in $optional_params) {
458474
if ($param -eq "dependency_check.snyk_auth_token" -and $props["dependency_check"] -eq "True") {
459475
Ask-For-Param $param $false
460-
} elseif ($param -ne "dependency_check.snyk_auth_token" -and $param -ne "env" -and $param -ne "cli_path" -and $param -ne "output_path" -and $param -ne "static_analysis_tool" -and $param -ne "git.domain" -and $param -ne "review_scope" -and $param -ne "exclude_branches") {
476+
} elseif ($param -ne "dependency_check.snyk_auth_token" -and $param -ne "env" -and $param -ne "cli_path" -and $param -ne "output_path" -and $param -ne "static_analysis_tool" -and $param -ne "git.domain" -and $param -ne "review_scope" -and $param -ne "exclude_branches" -and $param -ne "exclude_files" -and $param -ne "exclude_draft_pr" -and $param -ne "cr_event_type") {
461477
Ask-For-Param $param $false
462478
}
463479
}
@@ -487,7 +503,11 @@ foreach ($param in $required_params + $bee_params + $optional_params) {
487503
$scopes = $($props[$param]) -replace ',\s*', ','
488504
$docker_cmd += " --$param='[$scopes]'"
489505
} elseif ($param -eq "exclude_branches") {
490-
$docker_cmd += " --exclude_branches=$($props[$param])"
506+
$docker_cmd += " --exclude_branches='$($props[$param])'"
507+
} elseif ($param -eq "exclude_files") {
508+
$docker_cmd += " --exclude_files='$($props[$param])'"
509+
} elseif ($param -eq "exclude_draft_pr") {
510+
$docker_cmd += " --exclude_draft_pr=$($props[$param])"
491511
} elseif ($param -eq "dependency_check") {
492512
$validated_boolean = Validate-Boolean $props[$param]
493513
$docker_cmd += " --dependency_check.enabled=$validated_boolean"
@@ -518,11 +538,14 @@ foreach ($param in $required_params + $bee_params + $optional_params) {
518538
} elseif ($param -eq "review_comments") {
519539
$review_comments = Validate-ReviewComments $props[$param]
520540
$docker_cmd += " --$param=$review_comments"
541+
} elseif ($param -eq "cr_event_type") {
542+
$crEventType = ValidateCrEventType $props[$param]
521543
} else {
522544
$docker_cmd += " --$param=$($props[$param])"
523545
}
524546
}
525547
}
548+
$docker_cmd += " --cr_event_type=$crEventType"
526549

527550
$docker_cmd = $docker_init_cmd + $docker_cmd
528551
$param_bito_access_key = "bito_cli.bito.access_key"

cra-scripts/bito-cra.sh

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ validate_env() {
9393
fi
9494
}
9595

96+
cr_event_type="automated"
97+
validate_cr_event_type() {
98+
local cr_event_type_val="$1"
99+
if [ "$cr_event_type_val" == "manual" ]; then
100+
cr_event_type=$cr_event_type_val
101+
echo
102+
fi
103+
}
104+
96105
# Function to validate a review_comments vallue i.e. 1 mapped to "FULLPOST" or 2 mapped to "INLINE"
97106
validate_review_comments() {
98107
local review_comments="$1"
@@ -373,6 +382,8 @@ optional_params_cli=(
373382
"static_analysis_tool"
374383
"review_scope"
375384
"exclude_branches"
385+
"exclude_files"
386+
"exclude_draft_pr"
376387
"dependency_check"
377388
"dependency_check.snyk_auth_token"
378389
"cra_version"
@@ -381,6 +392,8 @@ optional_params_cli=(
381392
"output_path"
382393
"git.domain"
383394
"code_context"
395+
"nexus_url"
396+
"cr_event_type"
384397
)
385398

386399
# Parameters that are required/optional in mode server
@@ -398,6 +411,8 @@ optional_params_server=(
398411
"static_analysis_tool"
399412
"review_scope"
400413
"exclude_branches"
414+
"exclude_files"
415+
"exclude_draft_pr"
401416
"dependency_check"
402417
"dependency_check.snyk_auth_token"
403418
"server_port"
@@ -406,6 +421,8 @@ optional_params_server=(
406421
"cli_path"
407422
"git.domain"
408423
"code_context"
424+
"nexus_url"
425+
"cr_event_type"
409426
)
410427

411428
bee_params=(
@@ -425,6 +442,7 @@ cra_version="latest"
425442

426443
# Docker pull command
427444
docker_pull='docker pull bitoai/cra:${cra_version}'
445+
nexus_url=
428446

429447
# Construct the docker run command
430448
docker_init_cmd='docker run --rm -it'
@@ -457,7 +475,9 @@ echo ""
457475
#echo Optional Parameters: "${optional_params[@]}"
458476

459477
# Append Docker Image and Tag Placeholder
460-
docker_cmd+=' bitoai/cra:${cra_version}'
478+
docker_repo="bitoai/cra"
479+
docker_cmd+=' ${docker_repo}:${cra_version}'
480+
461481

462482
# Ask for required parameters if they are not set
463483
for param in "${required_params[@]}"; do
@@ -468,7 +488,7 @@ done
468488
for param in "${optional_params[@]}"; do
469489
if [ "$param" == "dependency_check.snyk_auth_token" ] && [ "${props["dependency_check"]}" == "True" ]; then
470490
ask_for_param "$param" "False"
471-
elif [ "$param" != "dependency_check.snyk_auth_token" ] && [ "$param" != "env" ] && [ "$param" != "cli_path" ] && [ "$param" != "output_path" ] && [ "$param" != "static_analysis_tool" ] && [ "$param" != "git.domain" ] && [ "$param" != "review_scope" ] && [ "$param" != "exclude_branches" ]; then
491+
elif [ "$param" != "dependency_check.snyk_auth_token" ] && [ "$param" != "env" ] && [ "$param" != "cli_path" ] && [ "$param" != "output_path" ] && [ "$param" != "static_analysis_tool" ] && [ "$param" != "git.domain" ] && [ "$param" != "review_scope" ] && [ "$param" != "exclude_branches" ] && [ "$param" != "nexus_url" ] && [ "$param" != "exclude_files" ] && [ "$param" != "exclude_draft_pr" ] && [ "$param" != "cr_event_type" ]; then
472492
ask_for_param "$param" "False"
473493
fi
474494
done
@@ -504,7 +524,11 @@ for param in "${required_params[@]}" "${bee_params[@]}" "${optional_params[@]}";
504524
scopes=$(echo ${props[$param]} | sed 's/, */,/g')
505525
docker_cmd+=" --review_scope='[$scopes]'"
506526
elif [ "$param" == "exclude_branches" ]; then
507-
docker_cmd+=" --exclude_branches=${props[$param]}"
527+
docker_cmd+=" --exclude_branches='${props[$param]}'"
528+
elif [ "$param" == "exclude_files" ]; then
529+
docker_cmd+=" --exclude_files='${props[$param]}'"
530+
elif [ "$param" == "exclude_draft_pr" ]; then
531+
docker_cmd+=" --exclude_draft_pr=${props[$param]}"
508532
elif [ "$param" == "dependency_check" ]; then
509533
#validate the dependency check boolean value
510534
props[$param]=$(validate_boolean "${props[$param]}")
@@ -547,12 +571,17 @@ for param in "${required_params[@]}" "${bee_params[@]}" "${optional_params[@]}";
547571
echo "Invalid value provided for review_comments. Exiting."
548572
exit 1
549573
fi
574+
elif [ "$param" == "nexus_url" ]; then
575+
nexus_url=$(echo "${props[$param]}" | sed 's/^[ \t]*//;s/[ \t]*$//')
576+
elif [ "$param" == "cr_event_type" ]; then
577+
validate_cr_event_type "${props[$param]}"
550578
else
551579
docker_cmd+=" --$param=${props[$param]}"
552580
fi
553581

554582
fi
555583
done
584+
docker_cmd+=" --cr_event_type=${cr_event_type}"
556585

557586
docker_cmd=$docker_init_cmd$docker_cmd
558587
param_bito_access_key="bito_cli.bito.access_key"
@@ -573,8 +602,27 @@ fi
573602
echo "Running command: $(eval echo $docker_pull)"
574603
eval "$docker_pull"
575604

605+
606+
if [ "$?" == 0 ] ; then
607+
echo "Docker image pulled successfully."
608+
else
609+
if [[ -n "$nexus_url" ]]; then
610+
nexus_pull='docker pull ${nexus_url}/cra:${cra_version}'
611+
echo "Running command: $(eval echo $nexus_pull)"
612+
eval "$nexus_pull"
613+
if [ "$?" == 0 ]; then
614+
docker_repo='${nexus_url}/cra'
615+
docker_repo=$(eval echo "$docker_repo")
616+
echo "Successfully pulled docker image from Nexus."
617+
else
618+
echo "Failed to pull docker image from Nexus."
619+
fi
620+
fi
621+
fi
622+
623+
576624
if [ "$?" == 0 ]; then
577-
echo "Running command: $docker_cmd"
625+
echo "Running command: $(eval echo $docker_cmd)"
578626
eval "$docker_cmd"
579627

580628
if [ "$?" == 0 ] && [ "$mode" == "server" ]; then

0 commit comments

Comments
 (0)