@@ -12,7 +12,51 @@ if [ "$EVENT_NAME" = "pull_request" ]; then
12
12
else
13
13
INPUT_OPTIONS=" $INPUT_OPTIONS --cr_event_type=manual"
14
14
fi
15
- echo $INPUT_OPTIONS
15
+
16
+ # Function to remove spaces from the value
17
+ remove_spaces () {
18
+ echo " $1 " | tr -d ' '
19
+ }
20
+
21
+ # Function to convert a string to lowercase
22
+ to_lowercase () {
23
+ echo " $1 " | tr ' [:upper:]' ' [:lower:]'
24
+ }
25
+
26
+ process_input_options () {
27
+ local input=" $1 "
28
+ local docker_cmd_args=" "
29
+
30
+ # Use sed to add newlines before each '--' to simplify processing
31
+ local formatted_input=$( echo " $input " | sed ' s/ --/\n--/g' )
32
+
33
+ docker_cmd_args=$( echo " $formatted_input " | while IFS= read -r line
34
+ do
35
+ # Extract key by cutting until the first '='
36
+ key=$( echo " $line " | cut -d' =' -f1)
37
+
38
+ # Extract value by removing everything before the first '='
39
+ value=$( echo " $line " | cut -d' =' -f2-)
40
+
41
+ # Check if the argument is --review_scope, --exclude_files, or --exclude_branches and remove spaces
42
+ if [[ " $key " == " --review_scope" || " $key " == " --static_analysis_tool" ]]; then
43
+ value=$( remove_spaces " $value " )
44
+ value=$( to_lowercase " $value " )
45
+ elif [[ " $key " == " --exclude_files" || " $key " == " --exclude_branches" ]]; then
46
+ value=$( remove_spaces " $value " )
47
+ fi
48
+
49
+ # Append to the modified arguments
50
+ echo -n " $key =$value "
51
+ done)
52
+
53
+ # Return the docker command arguments
54
+ echo " $docker_cmd_args "
55
+ }
56
+
57
+ # Process the input arguments and get the modified result
58
+ docker_cmd_args=$( process_input_options " $INPUT_OPTIONS " )
59
+ echo " Docker Command Args: $docker_cmd_args "
16
60
17
61
SUPPORTED_COMMANDS=(" /review" " review" )
18
62
31
75
# Run the Docker container from the specified image
32
76
if [ " $valid_command " = true ]; then
33
77
docker pull bitoai/cra:latest >&2
34
- exec docker run bitoai/cra:latest --mode=cli --pr_url $INPUT_PR --command " $INPUT_COMMAND " rest $INPUT_OPTIONS
78
+ exec docker run bitoai/cra:latest --mode=cli --pr_url $INPUT_PR --command " $INPUT_COMMAND " rest $docker_cmd_args
35
79
else
36
80
echo " $INPUT_COMMAND is not supported"
37
81
exit 0 # Exit the script with a non-zero status code
0 commit comments