Skip to content

Commit 65fd0e5

Browse files
Update entrypoint.sh - Handle spaces and lowercases
1 parent 1387649 commit 65fd0e5

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

entrypoint.sh

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,51 @@ else
1414
fi
1515
echo $INPUT_OPTIONS
1616

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

0 commit comments

Comments
 (0)