Skip to content

Commit eb10472

Browse files
Create bito-actions.sh
1 parent d6a112b commit eb10472

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

bito-action-script/bito-actions.sh

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
# Function to read property values from the file
4+
read_property() {
5+
local property_key=$1
6+
local property_file=$2
7+
local property_value=$(grep -w "${property_key}" "${property_file}" | cut -d'=' -f2)
8+
echo "${property_value}"
9+
}
10+
11+
# Initialize variables with default empty values
12+
agent_instance_url=""
13+
agent_instance_secret=""
14+
git_url=""
15+
16+
# Check if the first argument is a file
17+
if [ -f "$1" ]; then
18+
PROPERTY_FILE=$1
19+
shift
20+
21+
# Read initial values from the property file
22+
agent_instance_url=$(read_property "agent_instance_url" "${PROPERTY_FILE}")
23+
agent_instance_secret=$(read_property "agent_instance_secret" "${PROPERTY_FILE}")
24+
git_url=$(read_property "git_url" "${PROPERTY_FILE}")
25+
fi
26+
27+
# Override with command line arguments if provided
28+
for arg in "$@"
29+
do
30+
case $arg in
31+
agent_instance_url=*)
32+
agent_instance_url="${arg#*=}"
33+
;;
34+
agent_instance_secret=*)
35+
agent_instance_secret="${arg#*=}"
36+
;;
37+
git_url=*)
38+
git_url="${arg#*=}"
39+
;;
40+
*)
41+
echo "Unknown argument: $arg"
42+
;;
43+
esac
44+
done
45+
46+
47+
# Check if any of the required properties are empty
48+
if [ -z "$agent_instance_url" ]; then
49+
echo "Error: agent_instance_url is empty"
50+
exit 1
51+
fi
52+
53+
if [ -z "$agent_instance_secret" ]; then
54+
echo "Error: agent_instance_secret is empty"
55+
exit 1
56+
fi
57+
58+
if [ -z "$git_url" ]; then
59+
echo "Error: git_url is empty"
60+
exit 1
61+
fi
62+
63+
# Print properties
64+
echo "Agent Instance URL: $agent_instance_url"
65+
echo "Git URL: $git_url"
66+
67+
# Execute the curl command
68+
eval "curl --location '$agent_instance_url' \
69+
--header 'X-Bito-Action-Token: $agent_instance_secret' \
70+
--header 'Content-Type: application/json' \
71+
--data '{
72+
\"git_url\": \"$git_url\",
73+
\"command\": \"review\",
74+
\"arguments\": {}
75+
}'"

0 commit comments

Comments
 (0)