Skip to content

Commit 570776e

Browse files
Merge pull request #22 from gitbito/release/1.3.0
refactored test_cra.yml and added new properties
2 parents 544a37a + a2bd916 commit 570776e

File tree

5 files changed

+100
-31
lines changed

5 files changed

+100
-31
lines changed

.github/workflows/test_cra.yml

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
name: Run code review agent on every pull request, respond to user comments
1515

1616
steps:
17-
- name: Set Options Environment Variable for Issue Comment
18-
if: github.event_name == 'issue_comment'
17+
- name: Set Options Environment Variable
1918
run: |
19+
echo "EVENT_NAME=${{ github.event_name }}" >> $GITHUB_ENV
2020
GIT_DOMAIN_OPTION=""
2121
if [[ -n "${{ vars.GIT_DOMAIN }}" ]]; then
2222
GIT_DOMAIN_OPTION=" --git.domain=${{ vars.GIT_DOMAIN }}"
@@ -33,7 +33,16 @@ jobs:
3333
if [[ -n "${{ vars.EXCLUDE_BRANCHES }}" ]]; then
3434
EXCLUDE_BRANCHES_OPTION=" --exclude_branches=${{ vars.EXCLUDE_BRANCHES }}"
3535
fi
36-
echo "OPTIONS=--static_analysis.fb_infer.enabled=True --code_feedback=True --dependency_check.enabled=False --bee.path=/automation-platform --bee.actn_dir=/automation-platform/default_bito_ad/bito_modules --git.access_token=${{ secrets.GIT_ACCESS_TOKEN }} --bito_cli.bito.access_key=${{ secrets.BITO_ACCESS_KEY }}${GIT_DOMAIN_OPTION}${STATIC_ANALYSIS_TOOL_OPTION}${REVIEW_SCOPE_OPTION}${EXCLUDE_BRANCHES_OPTION}" >> $GITHUB_ENV
36+
EXCLUDE_FILES_OPTION=""
37+
if [[ -n "${{ vars.EXCLUDE_FILES }}" ]]; then
38+
EXCLUDE_FILES_OPTION=" --exclude_files=${{ vars.EXCLUDE_FILES }}"
39+
fi
40+
EXCLUDE_DRAFT_PR_OPTION=""
41+
if [[ -n "${{ vars.EXCLUDE_DRAFT_PR }}" ]]; then
42+
EXCLUDE_DRAFT_PR_OPTION=" --exclude_draft_pr=${{ vars.EXCLUDE_DRAFT_PR }}"
43+
fi
44+
echo "OPTIONS=--static_analysis.fb_infer.enabled=True --code_feedback=True --dependency_check.enabled=False --bee.path=/automation-platform --bee.actn_dir=/automation-platform/default_bito_ad/bito_modules --git.access_token=${{ secrets.GIT_ACCESS_TOKEN }} --bito_cli.bito.access_key=${{ secrets.BITO_ACCESS_KEY }}${GIT_DOMAIN_OPTION}${STATIC_ANALYSIS_TOOL_OPTION}${REVIEW_SCOPE_OPTION}${EXCLUDE_BRANCHES_OPTION}${EXCLUDE_FILES_OPTION}${EXCLUDE_DRAFT_PR_OPTION}" >> $GITHUB_ENV
45+
3746
- name: Code Review Agent - Issue Comment
3847
if: github.event_name == 'issue_comment'
3948
uses: gitbito/codereviewagent@main
@@ -42,26 +51,6 @@ jobs:
4251
command: ${{ github.event.comment.body }}
4352
options: ${{ env.OPTIONS }}
4453

45-
- name: Set Options Environment Variable for Pull Request
46-
if: github.event_name == 'pull_request'
47-
run: |
48-
GIT_DOMAIN_OPTION=""
49-
if [[ -n "${{ vars.GIT_DOMAIN }}" ]]; then
50-
GIT_DOMAIN_OPTION=" --git.domain=${{ vars.GIT_DOMAIN }}"
51-
fi
52-
STATIC_ANALYSIS_TOOL_OPTION=""
53-
if [[ -n "${{ vars.STATIC_ANALYSIS_TOOL }}" ]]; then
54-
STATIC_ANALYSIS_TOOL_OPTION=" --static_analysis_tool=${{ vars.STATIC_ANALYSIS_TOOL }}"
55-
fi
56-
REVIEW_SCOPE_OPTION=""
57-
if [[ -n "${{ vars.REVIEW_SCOPE }}" ]]; then
58-
REVIEW_SCOPE_OPTION=" --review_scope=${{ vars.REVIEW_SCOPE }}"
59-
fi
60-
EXCLUDE_BRANCHES_OPTION=""
61-
if [[ -n "${{ vars.EXCLUDE_BRANCHES }}" ]]; then
62-
EXCLUDE_BRANCHES_OPTION=" --exclude_branches=${{ vars.EXCLUDE_BRANCHES }}"
63-
fi
64-
echo "OPTIONS=--static_analysis.fb_infer.enabled=True --code_feedback=True --dependency_check.enabled=False --bee.path=/automation-platform --bee.actn_dir=/automation-platform/default_bito_ad/bito_modules --git.access_token=${{ secrets.GIT_ACCESS_TOKEN }} --bito_cli.bito.access_key=${{ secrets.BITO_ACCESS_KEY }}${GIT_DOMAIN_OPTION}${STATIC_ANALYSIS_TOOL_OPTION}${REVIEW_SCOPE_OPTION}${EXCLUDE_BRANCHES_OPTION}" >> $GITHUB_ENV
6554
- name: Code Review Agent action step
6655
if: github.event_name == 'pull_request'
6756
uses: gitbito/codereviewagent@main

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

entrypoint.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@
55
echo $INPUT_PR
66
echo $INPUT_COMMAND
77
echo $INPUT_OPTIONS
8+
echo $EVENT_NAME
9+
10+
if [ "$EVENT_NAME" = "pull_request" ]; then
11+
INPUT_OPTIONS="$INPUT_OPTIONS --cr_event_type=automated"
12+
else
13+
INPUT_OPTIONS="$INPUT_OPTIONS --cr_event_type=manual"
14+
fi
15+
echo $INPUT_OPTIONS
816

917
SUPPORTED_COMMANDS=("/review" "review")
1018

1119
#INPUT_COMMAND=$(echo "$INPUT_COMMAND" | tr -d '[:space:]')
1220
INPUT_COMMAND=$(echo "$INPUT_COMMAND" | xargs)
1321

14-
1522
# Check if the command starts with any of the supported commands
1623
for command in "${SUPPORTED_COMMANDS[@]}"; do
1724
if [[ "$INPUT_COMMAND" =~ ^$command ]]; then

0 commit comments

Comments
 (0)