Skip to content

Commit 902d6a4

Browse files
Update bito-cra.ps1 - release 1.4.8
1 parent d3cae92 commit 902d6a4

File tree

1 file changed

+50
-3
lines changed

1 file changed

+50
-3
lines changed

cra-scripts/bito-cra.ps1

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ function ValidateCrEventType {
122122
}
123123
}
124124

125+
$postingToPr = "True"
126+
function ValidatePostingToPr {
127+
param($boolean_val)
128+
# Convert the input to title case (first letter uppercase, rest lowercase)
129+
$boolean_val = $boolean_val.Substring(0,1).ToUpper() + $boolean_val.Substring(1).ToLower()
130+
131+
# Check if the converted value is either "True" or "False"
132+
if ($boolean_val -ne "True" -and $boolean_val -ne "False") {
133+
return $postingToPr
134+
}
135+
136+
# Return the properly cased boolean value
137+
return $boolean_val
138+
139+
}
140+
125141
# Function to display URL using IP address and port
126142
# Run docker ps -l command and store the output
127143
function Display-DockerUrl {
@@ -156,6 +172,7 @@ function Display-Usage {
156172
Write-Host "Usage-2: $PSCommandPrefix service start | restart <path-to-properties-file>"
157173
Write-Host "Usage-3: $PSCommandPrefix service stop"
158174
Write-Host "Usage-4: $PSCommandPrefix service status"
175+
Write-Host "Usage-5: $PSCommandPrefix <path-to-properties-file> pr_url=<url-value>"
159176
}
160177

161178
function Check-PropertyFile {
@@ -257,6 +274,18 @@ if ($args.Count -lt 1) {
257274
$properties_file = $null
258275
$action_directory = $null
259276
$force_mode = $null
277+
$pr_url_arg = $null
278+
279+
function Process-PrUrlOrActionDirParam {
280+
param ($func_local_arg)
281+
282+
if ($func_local_arg -like "pr_url=*") {
283+
$pr_url_arg = $arg -replace "pr_url=", ""
284+
} else {
285+
$action_directory = Check-ActionDirectory $func_local_arg
286+
}
287+
}
288+
260289
if ($args.Count -gt 1) {
261290
if ($args[0] -eq "service") {
262291
switch ($args[1]) {
@@ -311,7 +340,15 @@ if ($args.Count -gt 1) {
311340

312341
# Note down the hidden parameter for action directory
313342
if ($args.Count -eq 2) {
314-
$action_directory = Check-ActionDirectory $args[1]
343+
#check if 2nd argument is like pr_url=<value> then extract value else check the action_directory
344+
Process-PrUrlOrActionDirParam $args[1]
345+
}
346+
347+
if ($args.Count -eq 3) {
348+
#check if 2nd argument is like pr_url=<value> then extract value else check the action_directory
349+
Process-PrUrlOrActionDirParam $args[1]
350+
#check if 3rd argument is like pr_url=<value> then extract value else check the action_directory
351+
Process-PrUrlOrActionDirParam $args[2]
315352
}
316353
}
317354
}
@@ -334,6 +371,11 @@ Get-Content $properties_file | ForEach-Object {
334371
}
335372
}
336373

374+
# Override pr_url if provided as an argument
375+
if ($pr_url_arg) {
376+
$props["pr_url"] = $pr_url_arg
377+
}
378+
337379
# Function to ask for missing parameters
338380
function Ask-For-Param {
339381
param($param_name, $exit_on_empty)
@@ -377,6 +419,7 @@ $optional_params_cli = @(
377419
"git.domain"
378420
"code_context"
379421
"cr_event_type"
422+
"posting_to_pr"
380423
)
381424

382425
# Parameters that are required/optional in mode server
@@ -473,7 +516,7 @@ foreach ($param in $required_params) {
473516
foreach ($param in $optional_params) {
474517
if ($param -eq "dependency_check.snyk_auth_token" -and $props["dependency_check"] -eq "True") {
475518
Ask-For-Param $param $false
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") {
519+
} 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" -and $param -ne "posting_to_pr") {
477520
Ask-For-Param $param $false
478521
}
479522
}
@@ -540,12 +583,16 @@ foreach ($param in $required_params + $bee_params + $optional_params) {
540583
$docker_cmd += " --$param=$review_comments"
541584
} elseif ($param -eq "cr_event_type") {
542585
$crEventType = ValidateCrEventType $props[$param]
543-
} else {
586+
} elseif ($param -eq "posting_to_pr") {
587+
$postingToPr = ValidatePostingToPr $props[$param]
588+
}
589+
else {
544590
$docker_cmd += " --$param=$($props[$param])"
545591
}
546592
}
547593
}
548594
$docker_cmd += " --cr_event_type=$crEventType"
595+
$docker_cmd += " --posting_to_pr=$postingToPr"
549596
$docker_cmd = $docker_init_cmd + $docker_cmd
550597

551598
function Encrypt-GitSecret {

0 commit comments

Comments
 (0)