From eb10472259c7c6ed1347dee53db79bc9dde2a659 Mon Sep 17 00:00:00 2001 From: rishabhbohra-bito <157113574+rishabhbohra-bito@users.noreply.github.com> Date: Thu, 8 Aug 2024 10:38:52 +0530 Subject: [PATCH 1/4] Create bito-actions.sh --- bito-action-script/bito-actions.sh | 75 ++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 bito-action-script/bito-actions.sh diff --git a/bito-action-script/bito-actions.sh b/bito-action-script/bito-actions.sh new file mode 100644 index 0000000..8b64d86 --- /dev/null +++ b/bito-action-script/bito-actions.sh @@ -0,0 +1,75 @@ +#!/bin/bash + +# Function to read property values from the file +read_property() { + local property_key=$1 + local property_file=$2 + local property_value=$(grep -w "${property_key}" "${property_file}" | cut -d'=' -f2) + echo "${property_value}" +} + +# Initialize variables with default empty values +agent_instance_url="" +agent_instance_secret="" +git_url="" + +# Check if the first argument is a file +if [ -f "$1" ]; then + PROPERTY_FILE=$1 + shift + + # Read initial values from the property file + agent_instance_url=$(read_property "agent_instance_url" "${PROPERTY_FILE}") + agent_instance_secret=$(read_property "agent_instance_secret" "${PROPERTY_FILE}") + git_url=$(read_property "git_url" "${PROPERTY_FILE}") +fi + +# Override with command line arguments if provided +for arg in "$@" +do + case $arg in + agent_instance_url=*) + agent_instance_url="${arg#*=}" + ;; + agent_instance_secret=*) + agent_instance_secret="${arg#*=}" + ;; + git_url=*) + git_url="${arg#*=}" + ;; + *) + echo "Unknown argument: $arg" + ;; + esac +done + + +# Check if any of the required properties are empty +if [ -z "$agent_instance_url" ]; then + echo "Error: agent_instance_url is empty" + exit 1 +fi + +if [ -z "$agent_instance_secret" ]; then + echo "Error: agent_instance_secret is empty" + exit 1 +fi + +if [ -z "$git_url" ]; then + echo "Error: git_url is empty" + exit 1 +fi + +# Print properties +echo "Agent Instance URL: $agent_instance_url" +echo "Git URL: $git_url" + +# Execute the curl command +eval "curl --location '$agent_instance_url' \ +--header 'X-Bito-Action-Token: $agent_instance_secret' \ +--header 'Content-Type: application/json' \ +--data '{ + \"git_url\": \"$git_url\", + \"command\": \"review\", + \"arguments\": {} +}'" From 7847f3f2da6dc9c4be30b56c90886749031b298e Mon Sep 17 00:00:00 2001 From: rishabhbohra-bito <157113574+rishabhbohra-bito@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:44:08 +0530 Subject: [PATCH 2/4] Added sample property file for bito actions --- bito-action-script/bito_action.properties.sample | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 bito-action-script/bito_action.properties.sample diff --git a/bito-action-script/bito_action.properties.sample b/bito-action-script/bito_action.properties.sample new file mode 100644 index 0000000..1644196 --- /dev/null +++ b/bito-action-script/bito_action.properties.sample @@ -0,0 +1,3 @@ +agent_instance_url= +agent_instance_secret= +git_url= From 65b0c79ea7b4f77ba2df6550bd8e259e9acd702f Mon Sep 17 00:00:00 2001 From: rishabhbohra-bito <157113574+rishabhbohra-bito@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:46:19 +0530 Subject: [PATCH 3/4] BITO-5464 bug-fixes in bito action script --- bito-action-script/bito-actions.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bito-action-script/bito-actions.sh b/bito-action-script/bito-actions.sh index 8b64d86..4cb7a54 100644 --- a/bito-action-script/bito-actions.sh +++ b/bito-action-script/bito-actions.sh @@ -4,8 +4,8 @@ read_property() { local property_key=$1 local property_file=$2 - local property_value=$(grep -w "${property_key}" "${property_file}" | cut -d'=' -f2) - echo "${property_value}" + local property_value=$(grep -w "${property_key}" "${property_file}" | cut -d'=' -f2-) + echo "${property_value//\"}" } # Initialize variables with default empty values @@ -30,12 +30,15 @@ do case $arg in agent_instance_url=*) agent_instance_url="${arg#*=}" + agent_instance_url="${agent_instance_url//\"}" ;; agent_instance_secret=*) agent_instance_secret="${arg#*=}" + agent_instance_secret="${agent_instance_secret//\"}" ;; git_url=*) git_url="${arg#*=}" + git_url="${git_url//\"}" ;; *) echo "Unknown argument: $arg" @@ -43,7 +46,6 @@ do esac done - # Check if any of the required properties are empty if [ -z "$agent_instance_url" ]; then echo "Error: agent_instance_url is empty" @@ -62,6 +64,7 @@ fi # Print properties echo "Agent Instance URL: $agent_instance_url" +echo "Agent Instance Secret: $agent_instance_secret" echo "Git URL: $git_url" # Execute the curl command From 9ba26f70da144157e8ffd9eb8a2fbd77484ba048 Mon Sep 17 00:00:00 2001 From: rishabhbohra-bito <157113574+rishabhbohra-bito@users.noreply.github.com> Date: Thu, 8 Aug 2024 17:48:26 +0530 Subject: [PATCH 4/4] removed the secret log message --- bito-action-script/bito-actions.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/bito-action-script/bito-actions.sh b/bito-action-script/bito-actions.sh index 4cb7a54..6b4e0eb 100644 --- a/bito-action-script/bito-actions.sh +++ b/bito-action-script/bito-actions.sh @@ -64,7 +64,6 @@ fi # Print properties echo "Agent Instance URL: $agent_instance_url" -echo "Agent Instance Secret: $agent_instance_secret" echo "Git URL: $git_url" # Execute the curl command