Skip to content

Commit 933d112

Browse files
Merge pull request #31 from gitbito/BITO-5464
Create bito-actions.sh
2 parents d6a112b + 46929ee commit 933d112

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

bito-action-script/bito-actions.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
agent_instance_url="${agent_instance_url//\"}"
34+
;;
35+
agent_instance_secret=*)
36+
agent_instance_secret="${arg#*=}"
37+
agent_instance_secret="${agent_instance_secret//\"}"
38+
;;
39+
git_url=*)
40+
git_url="${arg#*=}"
41+
git_url="${git_url//\"}"
42+
;;
43+
*)
44+
echo "Unknown argument: $arg"
45+
;;
46+
esac
47+
done
48+
49+
# Check if any of the required properties are empty
50+
if [ -z "$agent_instance_url" ]; then
51+
echo "Error: agent_instance_url is empty"
52+
exit 1
53+
fi
54+
55+
if [ -z "$agent_instance_secret" ]; then
56+
echo "Error: agent_instance_secret is empty"
57+
exit 1
58+
fi
59+
60+
if [ -z "$git_url" ]; then
61+
echo "Error: git_url is empty"
62+
exit 1
63+
fi
64+
65+
# Print properties
66+
echo "Agent Instance URL: $agent_instance_url"
67+
echo "Git URL: $git_url"
68+
69+
# Execute the curl command
70+
eval "curl --location '$agent_instance_url' \
71+
--header 'X-Bito-Action-Token: $agent_instance_secret' \
72+
--header 'Content-Type: application/json' \
73+
--data '{
74+
\"git_url\": \"$git_url\",
75+
\"command\": \"review\",
76+
\"arguments\": {}
77+
}'"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
agent_instance_url=
2+
agent_instance_secret=
3+
git_url=

0 commit comments

Comments
 (0)