Skip to content

Commit 399e323

Browse files
Merge pull request #33 from gitbito/BITO-5464-pr_url
Update bito-actions.sh - change git_url to pr_url
2 parents 933d112 + 758e468 commit 399e323

File tree

3 files changed

+122
-10
lines changed

3 files changed

+122
-10
lines changed

bito-action-script/README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Bito Action
2+
3+
This document provides a step-by-step guide for setting up and running the Bito Action Script. The Bito Action Script allows you to configure and run automated code reviews using the Bito Code Review Agent (CRA). It enables you to seamlessly integrate the CRA into your Continuous Integration/Continuous Deployment (CI/CD) pipeline. Follow the instructions below to configure and execute the script successfully.
4+
5+
## Steps for Setup
6+
7+
### 1. Login to Bito
8+
9+
- Navigate to the Bito platform: [Bito Login](https://alpha.bito.ai/auth/login).
10+
- Use your credentials to log in to your account.
11+
12+
### 2. Create a New Agent Configuration Instance
13+
14+
- After logging in, go to **Configured Agents**.
15+
- Select **Code Review Agent (CRA)**.
16+
- Click on **Create New Instance**.
17+
18+
### 3. Configure the CRA Agent
19+
20+
- **Git Access Token:** During the setup process, you'll need to provide a Git access token to allow the CRA to access your repositories. Please refer to [Bito Documentation](https://docs.bito.ai/) to create a Git access token.
21+
22+
- **Agent Credentials:** After a successful configuration, you'll receive a unique **Agent Instance URL** and **Agent Instance Secret**. These credentials are essential for configuring the Bito Action Script.
23+
24+
- **Webhook Configuration:** After configuring the CRA, set up the webhook in your selected Git provider. This webhook is necessary to gather analytical data, such as acceptance rates and feedback. Please refer to [Webhook Configuration Documentation](https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-as-a-self-hosted-service/install-run-via-webhooks-service#webhook-setup-guide).
25+
26+
### 4. Download Bito Action Script
27+
28+
- Download the Bito Action Script and a sample configuration file from the following repository: [Bito Action Script on GitHub](https://github.com/gitbito/CodeReviewAgent/tree/main/bito-action-script).
29+
30+
### 5. Update the Property File
31+
32+
- Open the `bito_action.properties` file located in the downloaded script folder.
33+
- Update the following properties with the information provided during the CRA configuration:
34+
35+
- agent_instance_url=<your_agent_instance_url>
36+
- agent_instance_secret=<your_agent_instance_secret>
37+
- pr_url=<your_git_repository_url> (Optional if using the runtime URL method)
38+
39+
### 6. Run the Bito Action Script
40+
41+
You can run the Bito Action Script in two different ways, depending on your preference:
42+
43+
#### Option 1: Using the Property File and Runtime Git URL
44+
45+
- Ensure the `bito_action.properties` file is updated with the correct values.
46+
- Run the following command:
47+
48+
```bash
49+
bash ./bito_actions.sh bito_action.properties pr_url=<pr_url>
50+
```
51+
- Replace <pr_url> with the pull request URL you want to review.
52+
53+
#### Option 2: Using Runtime Values
54+
55+
- Provide all necessary values directly in the command line:
56+
57+
```bash
58+
bash ./bito_actions.sh agent_instance_url=<agent_instance_url> agent_instance_secret=<secret> pr_url=<pr_url>
59+
```
60+
- Replace <agent_instance_url>, <secret>, and <pr_url> with your specific values.
61+
62+
### 7. Integrate Bito Action Script into CI/CD Pipeline
63+
64+
- Incorporate the Bito Action Script into your CI/CD pipeline by including the appropriate commands in your build or deployment scripts.
65+
66+
- This integration ensures that code reviews are automatically triggered as part of the pipeline, enhancing your development workflow by enforcing code quality checks on every code change.
67+
68+
## Script Responses
69+
70+
During execution, the script will return various responses based on the success or failure of the process. Below are the possible responses:
71+
72+
### 1. Success
73+
**Response:**
74+
```plaintext
75+
Success:- Job Started with Id : ce82fae8-05da-4389-bddc-86ed583ab053
76+
77+
```
78+
### 2. Invalid Secret
79+
**Response:**
80+
```plaintext
81+
{"status":1,"response":"Secret is not valid","created":"2024-08-09T12:32:23.060340616Z"}
82+
83+
```
84+
### 3. Invalid Instance URL
85+
**Response:**
86+
```plaintext
87+
{"status":1,"response":"webhook is invalid: Please create a new instance","created":"2024-08-09T12:33:07.050869506Z"}
88+
89+
```
90+
### 4. Missing Input Data for Script
91+
**Response:**
92+
```plaintext
93+
Error: pr_url is empty
94+
95+
```
96+
97+
## Example Property File
98+
99+
Below is a sample `bito_action.properties` file:
100+
```plaintext
101+
agent_instance_url=your_agent_instance_url
102+
agent_instance_secret=your_agent_secret
103+
pr_url=
104+
105+
```
106+
107+
## Conclusion
108+
109+
You are now ready to use the Bito Action Script for automated code reviews through CI/CD Pipelines. Ensure all configurations are correct before running the script. If you encounter any issues, consult the [Bito Documentation](https://docs.bito.ai/) or reach out to Bito support for assistance.
110+
111+
112+

bito-action-script/bito-actions.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ read_property() {
1111
# Initialize variables with default empty values
1212
agent_instance_url=""
1313
agent_instance_secret=""
14-
git_url=""
14+
pr_url=""
1515

1616
# Check if the first argument is a file
1717
if [ -f "$1" ]; then
@@ -21,7 +21,7 @@ if [ -f "$1" ]; then
2121
# Read initial values from the property file
2222
agent_instance_url=$(read_property "agent_instance_url" "${PROPERTY_FILE}")
2323
agent_instance_secret=$(read_property "agent_instance_secret" "${PROPERTY_FILE}")
24-
git_url=$(read_property "git_url" "${PROPERTY_FILE}")
24+
pr_url=$(read_property "pr_url" "${PROPERTY_FILE}")
2525
fi
2626

2727
# Override with command line arguments if provided
@@ -36,9 +36,9 @@ do
3636
agent_instance_secret="${arg#*=}"
3737
agent_instance_secret="${agent_instance_secret//\"}"
3838
;;
39-
git_url=*)
40-
git_url="${arg#*=}"
41-
git_url="${git_url//\"}"
39+
pr_url=*)
40+
pr_url="${arg#*=}"
41+
pr_url="${pr_url//\"}"
4242
;;
4343
*)
4444
echo "Unknown argument: $arg"
@@ -57,21 +57,21 @@ if [ -z "$agent_instance_secret" ]; then
5757
exit 1
5858
fi
5959

60-
if [ -z "$git_url" ]; then
61-
echo "Error: git_url is empty"
60+
if [ -z "$pr_url" ]; then
61+
echo "Error: pr_url is empty"
6262
exit 1
6363
fi
6464

6565
# Print properties
6666
echo "Agent Instance URL: $agent_instance_url"
67-
echo "Git URL: $git_url"
67+
echo "Git URL: $pr_url"
6868

6969
# Execute the curl command
7070
eval "curl --location '$agent_instance_url' \
7171
--header 'X-Bito-Action-Token: $agent_instance_secret' \
7272
--header 'Content-Type: application/json' \
7373
--data '{
74-
\"git_url\": \"$git_url\",
74+
\"git_url\": \"$pr_url\",
7575
\"command\": \"review\",
7676
\"arguments\": {}
7777
}'"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
agent_instance_url=
22
agent_instance_secret=
3-
git_url=
3+
pr_url=

0 commit comments

Comments
 (0)