Skip to content

Commit

Permalink
chore: multi-stage docker build with colored logging outputs (#36)
Browse files Browse the repository at this point in the history
* chore: multi-stage docker build with colored logging outputs

* chore: add missing main.sh logging change
  • Loading branch information
RytisBa authored Nov 7, 2023
1 parent dfb4e0e commit c9645d0
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/robin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
name: Review the open PR
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: ./
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
20 changes: 14 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
FROM alpine:3.15
FROM alpine:3.18 as docpars

RUN apk add --no-cache bash curl jq wget
RUN mkdir -p "$HOME/bin" && \
cd "$HOME/bin" && \
wget https://github.com/denisidoro/docpars/releases/download/v0.2.0/docpars-v0.2.0-x86_64-unknown-linux-musl.tar.gz && tar xvfz docpars-v0.2.0-x86_64-unknown-linux-musl.tar.gz -C ./ && \
chmod +x docpars
ENV DOCPARS_VERSION=v0.3.0

RUN apk add --no-cache wget && \
wget https://github.com/denisidoro/docpars/releases/download/${DOCPARS_VERSION}/docpars-${DOCPARS_VERSION}-x86_64-unknown-linux-musl.tar.gz \
-O docpars.tar.gz && \
tar xvfz docpars.tar.gz -C ./ && \
chmod +x docpars

FROM alpine:3.18 as final

COPY --from=docpars /docpars /usr/local/bin/docpars

RUN apk add --no-cache bash curl jq

COPY entrypoint.sh /entrypoint.sh

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ Great emphasis has been put on ensuring a performant runtime.

| Metric | Value |
|----------------|-----------|
| Docker Image Size | 18.5MB |
| Docker Image Size | 15.6MB |
| Average Action Runtime | 14s |

The Docker image for Robin AI has a size of 18.5MB, which is relatively small and should be quick to download and use. On average, the Robin AI Github action runtime is 14 seconds, which means that it should be able to process pull requests quickly and efficiently. These metrics may vary depending on factors such as the size and complexity of the code being reviewed, the speed of the internet connection, and the availability of Open AI's API.
The Docker image for Robin AI has a size of 15.6MB, which is relatively small and should be quick to download and use. On average, the Robin AI Github action runtime is 14 seconds, which means that it should be able to process pull requests quickly and efficiently. These metrics may vary depending on factors such as the size and complexity of the code being reviewed, the speed of the internet connection, and the availability of Open AI's API.

## Demo

Expand Down
23 changes: 12 additions & 11 deletions src/gpt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,33 @@ Example output:\n
<summary>Score: 80</summary> \
<br> \
Improvements: \
- some bullet points \
<br> \
```relevant-coding-language \
<ul> \
<li> some bullet points </li> \
</ul> \r\n\r\n
\`\`\`relevant-coding-language \
example code here \
``` \
\`\`\` \
</details>
EOF
)

gpt::prompt_model() {
local -r git_diff="$1"
local -r git_diff="${1}"

local -r body=$(curl -sSL \
local -r response=$(curl -sSL \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPEN_AI_API_KEY" \
-d "$(jq -n --arg model "$GPT_MODEL" --arg prompt "$INITIAL_PROMPT" --arg git_diff "$git_diff" '{model: $model, messages: [{role: "user", content: $prompt}, {role: "user", content: $git_diff}]}')" \
"https://api.openai.com/v1/chat/completions")

local -r error=$(echo "$body" | jq -r '.error')
local -r error=$(echo "$response" | jq -r '.error')

if [[ "$error" != "null" ]]; then
echoerr "API request failed: $error"
exit 1
kill -s TERM $TOP_PID
utils::log_error "API request to 'api.openai.com' failed: $error"
fi

local -r response=$(echo "$body" | jq -r '.choices[0].message.content')
local -r body=$(echo "$response" | jq -r '.choices[0].message.content')

echo "$response"
echo "$body"
}
10 changes: 6 additions & 4 deletions src/main.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

trap "exit 1" TERM
export TOP_PID=$$

source "$HOME_DIR/src/utils.sh"
source "$HOME_DIR/src/github.sh"
source "$HOME_DIR/src/gpt.sh"
Expand All @@ -9,7 +12,7 @@ source "$HOME_DIR/src/gpt.sh"
##? Usage:
##? main.sh --github_token=<token> --open_ai_api_key=<token> --gpt_model_name=<name> --github_api_url=<url> --files_to_ignore=<files>
main() {
eval "$(/root/bin/docpars -h "$(grep "^##?" "$HOME_DIR/src/main.sh" | cut -c 5-)" : "$@")"
eval "$(docpars -h "$(grep "^##?" "$HOME_DIR/src/main.sh" | cut -c 5-)" : "$@")"

utils::verify_required_env_vars

Expand All @@ -22,15 +25,14 @@ main() {
local -r commit_diff=$(github::get_commit_diff "$pr_number" "$files_to_ignore")

if [ -z "$commit_diff" ]; then
echo "Nothing in the commit diff."
utils::log_info "Nothing in the commit diff."
exit
fi

local -r gpt_response=$(gpt::prompt_model "$commit_diff")

if [ -z "$gpt_response" ]; then
echoerr "GPT's response was NULL. Double check your API key and billing details."
exit 1
utils::log_error "GPT's response was NULL. Double check your API key and billing details."
fi

github::comment "$gpt_response" "$pr_number"
Expand Down
12 changes: 8 additions & 4 deletions src/utils.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#!/usr/bin/env bash

echoerr() {
echo "$@" 1>&2
utils::log_info() {
echo -e "[\\e[1;94mINFO\\e[0m] $@"
}

utils::log_error() {
echo -e "[\\e[1;91mERROR\\e[0m] $@" 1>&2
exit 1
}

utils::verify_required_env_vars() {
Expand All @@ -15,7 +20,6 @@ utils::verify_required_env_vars() {

utils::env_variable_exist() {
if [[ -z "${!1}" ]]; then
echoerr "The env variable $1 is required."
exit 1
utils::log_error "The env variable '$1' is required."
fi
}

0 comments on commit c9645d0

Please sign in to comment.