Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bitbucket pipeline #304

Merged
merged 18 commits into from
Sep 22, 2023

Conversation

sarbjitsinghgrewal
Copy link
Contributor

Bitbucket Pipeline Review Creation

I have completed the Bitbucket Pipeline setup, which serves the purpose of generating reviews for pull requests. Whenever a user initiates a pull request on Bitbucket, this pipeline runs automatically and appends a review as a comment to the respective pull request.

Here's an overview of the workflow for this pipeline:

Step 1: We begin by cloning the repository from https://github.com/Codium-ai/pr-agent.git using this pipeline.

Step 2: The pipeline executes the command "cd pr-agent" to navigate into this directory.

Step 3: To build and run the file, we employ Docker Compose. As a prerequisite, we install Docker Compose with the command "pip install docker-compose."

Step 4: The review is created for the pull request by executing the command "docker-compose up --build." This command initiates the build and runs it, ultimately producing the review for the pull request.

New files introduced for this pipeline include:

docker-compose.yml: This file is employed to create the build and execute it.
Dockerfile.bitbucket_pipeline: This Dockerfile is utilized by the docker-compose file.
entrypoint.sh: You can find this file within the bitbucket_pipeline folder.
bitbucket_pipeline_runner.py: I have created this file in the servers folder, and it contains the actual script responsible for running the PRReviewer class.
Attached is a screenshot demonstrating a review created by this pipeline for reference.
image

@madgetr
Copy link

madgetr commented Sep 15, 2023

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

PR Analysis

  • 🎯 Main theme: Implementing Bitbucket Pipeline for PR Reviews
  • 📝 PR summary: This PR introduces a Bitbucket Pipeline setup for generating reviews for pull requests. It includes a new Python script, Dockerfile, and docker-compose file specifically for this pipeline. The pipeline clones the repository, navigates to the directory, installs Docker Compose, and runs the build to produce a review for the pull request.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • 🔒 Security concerns: No

PR Feedback

  • 💡 General suggestions: The PR is well-structured and the code changes are clear. However, it would be beneficial to include error handling in the Python script for cases where environment variables are not set. Also, consider adding logging for debugging purposes. Lastly, it's recommended to add tests for the new functionality.

  • 🤖 Code feedback:

    • relevant file: pr_agent/servers/bitbucket_pipeline_runner.py
      suggestion: Consider adding error handling for cases where the environment variables are not set. This will make the script more robust and easier to debug. [important]
      relevant line: pull_request_id = os.environ.get("BITBUCKET_PR_ID", '')

    • relevant file: pr_agent/servers/bitbucket_pipeline_runner.py
      suggestion: Consider adding logging statements to help with debugging. This can be especially helpful in a pipeline context where console output is often the only insight into what's happening. [medium]
      relevant line: async def run_action():

    • relevant file: Dockerfile.bitbucket_pipeline
      suggestion: Consider using a multi-stage build to reduce the size of the final Docker image. This can make the pipeline run faster and use less resources. [medium]
      relevant line: FROM python:3.10 as base

    • relevant file: docker-compose.yml
      suggestion: Consider using Docker Compose version 3.8 or later to take advantage of the latest features and improvements. [medium]
      relevant line: version: '3'

How to use

Tag me in a comment '@CodiumAI-Agent' and add one of the following commands:
/review [-i]: Request a review of your Pull Request. For an incremental review, which only considers changes since the last review, include the '-i' option.
/describe: Modify the PR title and description based on the contents of the PR.
/improve [--extended]: Suggest improvements to the code in the PR. Extended mode employs several calls, and provides a more thorough feedback.
/ask <QUESTION>: Pose a question about the PR.
/update_changelog: Update the changelog based on the PR's contents.

To edit any configuration parameter from configuration.toml, add --config_path=new_value
For example: /review --pr_reviewer.extra_instructions="focus on the file: ..."
To list the possible configuration parameters, use the /config command.

@mrT23
Copy link
Collaborator

mrT23 commented Sep 17, 2023

PR Analysis

  • 🎯 Main theme: Implementing Bitbucket Pipeline for PR Reviews
  • 📝 PR summary: This PR introduces a Bitbucket Pipeline setup to generate reviews for pull requests. The pipeline clones the repository, navigates to the directory, installs Docker Compose, and builds and runs the file. The review is then created for the pull request. The PR also includes the addition of new files and environment variables for the pipeline.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • Estimated effort to review [1-5]: 3
    This PR introduces a new feature and modifies several files. It requires a moderate level of effort to review, as the reviewer needs to understand the new pipeline setup and the implications of the changes.
  • 🔒 Security concerns: No
    The PR does not seem to introduce any obvious security concerns. The use of environment variables for sensitive data like tokens is a good practice. However, it's always important to ensure these environment variables are securely managed.

PR Feedback

  • 💡 General suggestions: The PR is well-structured and the changes are clearly explained in the description. However, it would be beneficial to add error handling in the new Python script to handle potential issues during the pipeline execution. Also, consider adding a cleanup step in the pipeline to remove any temporary files or resources created during the execution.

  • 🤖 Code feedback:

    • relevant file: pr_agent/servers/bitbucket_pipeline_runner.py
      suggestion: Consider adding error handling for potential issues during the pipeline execution. For instance, if the PR URL cannot be constructed correctly or if the PRReviewer cannot run successfully, it would be helpful to catch these exceptions and log meaningful error messages. [important]
      relevant line: await PRReviewer(pr_url).run()

    • relevant file: Dockerfile.bitbucket_pipeline
      suggestion: It's a good practice to minimize the number of layers in your Dockerfile to reduce the image size. You can achieve this by combining the ADD and RUN commands into a single RUN command that includes the removal of temporary files. [medium]
      relevant line: ADD pyproject.toml .

    • relevant file: docker-compose.yml
      suggestion: It's recommended to use versioned tags for Docker images to ensure the pipeline uses a consistent environment. Using the 'latest' tag can lead to unexpected changes when the image is updated. [medium]
      relevant line: image: python:3.8 # Use an appropriate Python image with pip

    • relevant file: pr_agent/servers/bitbucket_pipeline_runner.py
      suggestion: It's a good practice to avoid using print statements for logging in production code. Consider using a logging library which can provide more flexibility (like log levels) and output logs to various destinations. [medium]
      relevant line: print("BITBUCKET_BEARER_TOKEN not set")

Comment on lines 7 to 35
async def run_action():
pull_request_id = os.environ.get("BITBUCKET_PR_ID", '')
slug = os.environ.get("BITBUCKET_REPO_SLUG", '')
workspace = os.environ.get("BITBUCKET_WORKSPACE", '')
bearer_token = os.environ.get('BITBUCKET_BEARER_TOKEN', None)
OPENAI_KEY = os.environ.get('OPENAI_API_KEY') or os.environ.get('OPENAI.KEY')
OPENAI_ORG = os.environ.get('OPENAI_ORG') or os.environ.get('OPENAI.ORG')

# Check if required environment variables are set
if not bearer_token:
print("BITBUCKET_BEARER_TOKEN not set")
return

if not OPENAI_KEY:
print("OPENAI_KEY not set")
return

# Set the environment variables in the settings
get_settings().set("BITBUCKET.BEARER_TOKEN", bearer_token)
get_settings().set("OPENAI.KEY", OPENAI_KEY)
if OPENAI_ORG:
get_settings().set("OPENAI.ORG", OPENAI_ORG)

if pull_request_id and slug and workspace:
pr_url = f"https://bitbucket.org/{workspace}/{slug}/pull-requests/{pull_request_id}"
await PRReviewer(pr_url).run()

if __name__ == "__main__":
asyncio.run(run_action())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Consider handling exceptions for the async function run_action to prevent the program from crashing in case of errors.

Suggested change
async def run_action():
pull_request_id = os.environ.get("BITBUCKET_PR_ID", '')
slug = os.environ.get("BITBUCKET_REPO_SLUG", '')
workspace = os.environ.get("BITBUCKET_WORKSPACE", '')
bearer_token = os.environ.get('BITBUCKET_BEARER_TOKEN', None)
OPENAI_KEY = os.environ.get('OPENAI_API_KEY') or os.environ.get('OPENAI.KEY')
OPENAI_ORG = os.environ.get('OPENAI_ORG') or os.environ.get('OPENAI.ORG')
# Check if required environment variables are set
if not bearer_token:
print("BITBUCKET_BEARER_TOKEN not set")
return
if not OPENAI_KEY:
print("OPENAI_KEY not set")
return
# Set the environment variables in the settings
get_settings().set("BITBUCKET.BEARER_TOKEN", bearer_token)
get_settings().set("OPENAI.KEY", OPENAI_KEY)
if OPENAI_ORG:
get_settings().set("OPENAI.ORG", OPENAI_ORG)
if pull_request_id and slug and workspace:
pr_url = f"https://bitbucket.org/{workspace}/{slug}/pull-requests/{pull_request_id}"
await PRReviewer(pr_url).run()
if __name__ == "__main__":
asyncio.run(run_action())
async def run_action():
try:
pull_request_id = os.environ.get("BITBUCKET_PR_ID", '')
slug = os.environ.get("BITBUCKET_REPO_SLUG", '')
workspace = os.environ.get("BITBUCKET_WORKSPACE", '')
bearer_token = os.environ.get('BITBUCKET_BEARER_TOKEN', None)
OPENAI_KEY = os.environ.get('OPENAI_API_KEY') or os.environ.get('OPENAI.KEY')
OPENAI_ORG = os.environ.get('OPENAI_ORG') or os.environ.get('OPENAI.ORG')
# Check if required environment variables are set
if not bearer_token:
print("BITBUCKET_BEARER_TOKEN not set")
return
if not OPENAI_KEY:
print("OPENAI_KEY not set")
return
# Set the environment variables in the settings
get_settings().set("BITBUCKET.BEARER_TOKEN", bearer_token)
get_settings().set("OPENAI.KEY", OPENAI_KEY)
if OPENAI_ORG:
get_settings().set("OPENAI.ORG", OPENAI_ORG)
if pull_request_id and slug and workspace:
pr_url = f"https://bitbucket.org/{workspace}/{slug}/pull-requests/{pull_request_id}"
await PRReviewer(pr_url).run()
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
asyncio.run(run_action())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add support for pt comments?

Comment on lines 1 to 11
FROM python:3.10 as base

WORKDIR /app
ADD pyproject.toml .
ADD requirements.txt .
RUN pip install . && rm pyproject.toml requirements.txt
ENV PYTHONPATH=/app
ADD pr_agent pr_agent
ADD bitbucket_pipeline/entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Consider using a multi-stage build to reduce the size of the final Docker image.

Suggested change
FROM python:3.10 as base
WORKDIR /app
ADD pyproject.toml .
ADD requirements.txt .
RUN pip install . && rm pyproject.toml requirements.txt
ENV PYTHONPATH=/app
ADD pr_agent pr_agent
ADD bitbucket_pipeline/entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
# First stage: build
FROM python:3.10 as builder
WORKDIR /app
ADD pyproject.toml .
ADD requirements.txt .
RUN pip install . && rm pyproject.toml requirements.txt
# Second stage: runtime
FROM python:3.10-slim as runtime
COPY --from=builder /app /app
ENV PYTHONPATH=/app
ADD pr_agent pr_agent
ADD bitbucket_pipeline/entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that won't work, no dependencies in "runtime" target. But I suggest moving this to the docker/Dockerfile as a new target, follow the other examples in this file @sarbjitsinghgrewal

Comment on lines 1 to 37
version: '3'
services:
myapp:
build:
context: .
dockerfile: Dockerfile.bitbucket_pipeline
ports:
- "8080:80"
environment:
- BITBUCKET_BRANCH=${BITBUCKET_BRANCH}
- BITBUCKET_BUILD_NUMBER=${BITBUCKET_BUILD_NUMBER}
- BITBUCKET_CLONE_DIR=${BITBUCKET_CLONE_DIR}
- BITBUCKET_COMMIT=${BITBUCKET_COMMIT}
- BITBUCKET_GIT_HTTP_ORIGIN=${BITBUCKET_GIT_HTTP_ORIGIN}
- BITBUCKET_GIT_SSH_ORIGIN=${BITBUCKET_GIT_SSH_ORIGIN}
- BITBUCKET_PIPELINE_UUID=${BITBUCKET_PIPELINE_UUID}
- BITBUCKET_PROJECT_KEY=${BITBUCKET_PROJECT_KEY}
- BITBUCKET_PROJECT_UUID=${BITBUCKET_PROJECT_UUID}
- BITBUCKET_PR_DESTINATION_BRANCH=${BITBUCKET_PR_DESTINATION_BRANCH}
- BITBUCKET_PR_DESTINATION_COMMIT=${BITBUCKET_PR_DESTINATION_COMMIT}
- BITBUCKET_PR_ID=${BITBUCKET_PR_ID}
- BITBUCKET_REPO_FULL_NAME=${BITBUCKET_REPO_FULL_NAME}
- BITBUCKET_REPO_IS_PRIVATE=${BITBUCKET_REPO_IS_PRIVATE}
- BITBUCKET_REPO_OWNER=${BITBUCKET_REPO_OWNER}
- BITBUCKET_REPO_OWNER_UUID=${BITBUCKET_REPO_OWNER_UUID}
- BITBUCKET_REPO_SLUG=${BITBUCKET_REPO_SLUG}
- BITBUCKET_REPO_UUID=${BITBUCKET_REPO_UUID}
- BITBUCKET_SSH_KEY_FILE=${BITBUCKET_SSH_KEY_FILE}
- BITBUCKET_STEP_RUN_NUMBER=${BITBUCKET_STEP_RUN_NUMBER}
- BITBUCKET_STEP_TRIGGERER_UUID=${BITBUCKET_STEP_TRIGGERER_UUID}
- BITBUCKET_STEP_UUID=${BITBUCKET_STEP_UUID}
- BITBUCKET_WORKSPACE=${BITBUCKET_WORKSPACE}
- CI=${CI}
- DOCKER_HOST=${DOCKER_HOST}
- PIPELINES_JWT_TOKEN=${PIPELINES_JWT_TOKEN}
- OPENAI_API_KEY=${OPENAI_API_KEY}
- BITBUCKET_BEARER_TOKEN=${BITBUCKET_BEARER_TOKEN}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: Consider using version '3.8' or later for the Docker Compose file to take advantage of the latest features and options.

Suggested change
version: '3'
services:
myapp:
build:
context: .
dockerfile: Dockerfile.bitbucket_pipeline
ports:
- "8080:80"
environment:
- BITBUCKET_BRANCH=${BITBUCKET_BRANCH}
- BITBUCKET_BUILD_NUMBER=${BITBUCKET_BUILD_NUMBER}
- BITBUCKET_CLONE_DIR=${BITBUCKET_CLONE_DIR}
- BITBUCKET_COMMIT=${BITBUCKET_COMMIT}
- BITBUCKET_GIT_HTTP_ORIGIN=${BITBUCKET_GIT_HTTP_ORIGIN}
- BITBUCKET_GIT_SSH_ORIGIN=${BITBUCKET_GIT_SSH_ORIGIN}
- BITBUCKET_PIPELINE_UUID=${BITBUCKET_PIPELINE_UUID}
- BITBUCKET_PROJECT_KEY=${BITBUCKET_PROJECT_KEY}
- BITBUCKET_PROJECT_UUID=${BITBUCKET_PROJECT_UUID}
- BITBUCKET_PR_DESTINATION_BRANCH=${BITBUCKET_PR_DESTINATION_BRANCH}
- BITBUCKET_PR_DESTINATION_COMMIT=${BITBUCKET_PR_DESTINATION_COMMIT}
- BITBUCKET_PR_ID=${BITBUCKET_PR_ID}
- BITBUCKET_REPO_FULL_NAME=${BITBUCKET_REPO_FULL_NAME}
- BITBUCKET_REPO_IS_PRIVATE=${BITBUCKET_REPO_IS_PRIVATE}
- BITBUCKET_REPO_OWNER=${BITBUCKET_REPO_OWNER}
- BITBUCKET_REPO_OWNER_UUID=${BITBUCKET_REPO_OWNER_UUID}
- BITBUCKET_REPO_SLUG=${BITBUCKET_REPO_SLUG}
- BITBUCKET_REPO_UUID=${BITBUCKET_REPO_UUID}
- BITBUCKET_SSH_KEY_FILE=${BITBUCKET_SSH_KEY_FILE}
- BITBUCKET_STEP_RUN_NUMBER=${BITBUCKET_STEP_RUN_NUMBER}
- BITBUCKET_STEP_TRIGGERER_UUID=${BITBUCKET_STEP_TRIGGERER_UUID}
- BITBUCKET_STEP_UUID=${BITBUCKET_STEP_UUID}
- BITBUCKET_WORKSPACE=${BITBUCKET_WORKSPACE}
- CI=${CI}
- DOCKER_HOST=${DOCKER_HOST}
- PIPELINES_JWT_TOKEN=${PIPELINES_JWT_TOKEN}
- OPENAI_API_KEY=${OPENAI_API_KEY}
- BITBUCKET_BEARER_TOKEN=${BITBUCKET_BEARER_TOKEN}
version: '3.8'
services:
myapp:
build:
context: .
dockerfile: Dockerfile.bitbucket_pipeline
ports:
- "8080:80"
environment:
- BITBUCKET_BRANCH=${BITBUCKET_BRANCH}
- BITBUCKET_BUILD_NUMBER=${BITBUCKET_BUILD_NUMBER}
- BITBUCKET_CLONE_DIR=${BITBUCKET_CLONE_DIR}
- BITBUCKET_COMMIT=${BITBUCKET_COMMIT}
- BITBUCKET_GIT_HTTP_ORIGIN=${BITBUCKET_GIT_HTTP_ORIGIN}
- BITBUCKET_GIT_SSH_ORIGIN=${BITBUCKET_GIT_SSH_ORIGIN}
- BITBUCKET_PIPELINE_UUID=${BITBUCKET_PIPELINE_UUID}
- BITBUCKET_PROJECT_KEY=${BITBUCKET_PROJECT_KEY}
- BITBUCKET_PROJECT_UUID=${BITBUCKET_PROJECT_UUID}
- BITBUCKET_PR_DESTINATION_BRANCH=${BITBUCKET_PR_DESTINATION_BRANCH}
- BITBUCKET_PR_DESTINATION_COMMIT=${BITBUCKET_PR_DESTINATION_COMMIT}
- BITBUCKET_PR_ID=${BITBUCKET_PR_ID}
- BITBUCKET_REPO_FULL_NAME=${BITBUCKET_REPO_FULL_NAME}
- BITBUCKET_REPO_IS_PRIVATE=${BITBUCKET_REPO_IS_PRIVATE}
- BITBUCKET_REPO_OWNER=${BITBUCKET_REPO_OWNER}
- BITBUCKET_REPO_OWNER_UUID=${BITBUCKET_REPO_OWNER_UUID}
- BITBUCKET_REPO_SLUG=${BITBUCKET_REPO_SLUG}
- BITBUCKET_REPO_UUID=${BITBUCKET_REPO_UUID}
- BITBUCKET_SSH_KEY_FILE=${BITBUCKET_SSH_KEY_FILE}
- BITBUCKET_STEP_RUN_NUMBER=${BITBUCKET_STEP_RUN_NUMBER}
- BITBUCKET_STEP_TRIGGERER_UUID=${BITBUCKET_STEP_TRIGGERER_UUID}
- BITBUCKET_STEP_UUID=${BITBUCKET_STEP_UUID}
- BITBUCKET_WORKSPACE=${BITBUCKET_WORKSPACE}
- CI=${CI}
- DOCKER_HOST=${DOCKER_HOST}
- PIPELINES_JWT_TOKEN=${PIPELINES_JWT_TOKEN}
- OPENAI_API_KEY=${OPENAI_API_KEY}
- BITBUCKET_BEARER_TOKEN=${BITBUCKET_BEARER_TOKEN}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of docker compose here? Maybe you added it to the repo by mistake? It's not documented anywhere and I think it's not necessary. It's the responsibility of the user to host the docker image properly. We might need to add better documentation about it in the future

Comment on lines 1 to 11
FROM python:3.10 as base

WORKDIR /app
ADD pyproject.toml .
ADD requirements.txt .
RUN pip install . && rm pyproject.toml requirements.txt
ENV PYTHONPATH=/app
ADD pr_agent pr_agent
ADD bitbucket_pipeline/entrypoint.sh /
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that won't work, no dependencies in "runtime" target. But I suggest moving this to the docker/Dockerfile as a new target, follow the other examples in this file @sarbjitsinghgrewal

Comment on lines 1 to 37
version: '3'
services:
myapp:
build:
context: .
dockerfile: Dockerfile.bitbucket_pipeline
ports:
- "8080:80"
environment:
- BITBUCKET_BRANCH=${BITBUCKET_BRANCH}
- BITBUCKET_BUILD_NUMBER=${BITBUCKET_BUILD_NUMBER}
- BITBUCKET_CLONE_DIR=${BITBUCKET_CLONE_DIR}
- BITBUCKET_COMMIT=${BITBUCKET_COMMIT}
- BITBUCKET_GIT_HTTP_ORIGIN=${BITBUCKET_GIT_HTTP_ORIGIN}
- BITBUCKET_GIT_SSH_ORIGIN=${BITBUCKET_GIT_SSH_ORIGIN}
- BITBUCKET_PIPELINE_UUID=${BITBUCKET_PIPELINE_UUID}
- BITBUCKET_PROJECT_KEY=${BITBUCKET_PROJECT_KEY}
- BITBUCKET_PROJECT_UUID=${BITBUCKET_PROJECT_UUID}
- BITBUCKET_PR_DESTINATION_BRANCH=${BITBUCKET_PR_DESTINATION_BRANCH}
- BITBUCKET_PR_DESTINATION_COMMIT=${BITBUCKET_PR_DESTINATION_COMMIT}
- BITBUCKET_PR_ID=${BITBUCKET_PR_ID}
- BITBUCKET_REPO_FULL_NAME=${BITBUCKET_REPO_FULL_NAME}
- BITBUCKET_REPO_IS_PRIVATE=${BITBUCKET_REPO_IS_PRIVATE}
- BITBUCKET_REPO_OWNER=${BITBUCKET_REPO_OWNER}
- BITBUCKET_REPO_OWNER_UUID=${BITBUCKET_REPO_OWNER_UUID}
- BITBUCKET_REPO_SLUG=${BITBUCKET_REPO_SLUG}
- BITBUCKET_REPO_UUID=${BITBUCKET_REPO_UUID}
- BITBUCKET_SSH_KEY_FILE=${BITBUCKET_SSH_KEY_FILE}
- BITBUCKET_STEP_RUN_NUMBER=${BITBUCKET_STEP_RUN_NUMBER}
- BITBUCKET_STEP_TRIGGERER_UUID=${BITBUCKET_STEP_TRIGGERER_UUID}
- BITBUCKET_STEP_UUID=${BITBUCKET_STEP_UUID}
- BITBUCKET_WORKSPACE=${BITBUCKET_WORKSPACE}
- CI=${CI}
- DOCKER_HOST=${DOCKER_HOST}
- PIPELINES_JWT_TOKEN=${PIPELINES_JWT_TOKEN}
- OPENAI_API_KEY=${OPENAI_API_KEY}
- BITBUCKET_BEARER_TOKEN=${BITBUCKET_BEARER_TOKEN}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of docker compose here? Maybe you added it to the repo by mistake? It's not documented anywhere and I think it's not necessary. It's the responsibility of the user to host the docker image properly. We might need to add better documentation about it in the future

Comment on lines 7 to 35
async def run_action():
pull_request_id = os.environ.get("BITBUCKET_PR_ID", '')
slug = os.environ.get("BITBUCKET_REPO_SLUG", '')
workspace = os.environ.get("BITBUCKET_WORKSPACE", '')
bearer_token = os.environ.get('BITBUCKET_BEARER_TOKEN', None)
OPENAI_KEY = os.environ.get('OPENAI_API_KEY') or os.environ.get('OPENAI.KEY')
OPENAI_ORG = os.environ.get('OPENAI_ORG') or os.environ.get('OPENAI.ORG')

# Check if required environment variables are set
if not bearer_token:
print("BITBUCKET_BEARER_TOKEN not set")
return

if not OPENAI_KEY:
print("OPENAI_KEY not set")
return

# Set the environment variables in the settings
get_settings().set("BITBUCKET.BEARER_TOKEN", bearer_token)
get_settings().set("OPENAI.KEY", OPENAI_KEY)
if OPENAI_ORG:
get_settings().set("OPENAI.ORG", OPENAI_ORG)

if pull_request_id and slug and workspace:
pr_url = f"https://bitbucket.org/{workspace}/{slug}/pull-requests/{pull_request_id}"
await PRReviewer(pr_url).run()

if __name__ == "__main__":
asyncio.run(run_action())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add support for pt comments?

@@ -1,7 +1,7 @@
[config]
model="gpt-4"
fallback_models=["gpt-3.5-turbo-16k"]
git_provider="github"
git_provider="bitbucket"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
git_provider="bitbucket"
git_provider="github"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not change the default value here!

@@ -55,6 +55,7 @@ extra_instructions = ""
[github]
# The type of deployment to create. Valid values are 'app' or 'user'.
deployment_type = "user"
user_token = "" # A GitHub personal access token with 'repo' scope.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
user_token = "" # A GitHub personal access token with 'repo' scope.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be placed in the .secrets.toml file!

@@ -100,6 +101,21 @@ polling_interval_seconds = 30
# token to authenticate in the patch server
# patch_server_token = ""


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't belong here! Should be placed by every user in their .sercrets.toml file

Comment on lines +382 to +396
pipelines:
pull-requests:
'**':
- step:
name: PR Agent Pipeline
caches:
- pip
image: python:3.8
services:
- docker
script:
- git clone https://github.com/Codium-ai/pr-agent.git
- cd pr-agent
- docker build -t bitbucket_runner:latest -f Dockerfile.bitbucket_pipeline .
- docker run -e OPENAI_API_KEY=$OPENAI_API_KEY -e BITBUCKET_BEARER_TOKEN=$BITBUCKET_BEARER_TOKEN -e BITBUCKET_PR_ID=$BITBUCKET_PR_ID -e BITBUCKET_REPO_SLUG=$BITBUCKET_REPO_SLUG -e BITBUCKET_WORKSPACE=$BITBUCKET_WORKSPACE bitbucket_runner:latest
Copy link
Collaborator

@hussam789 hussam789 Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please surround it code blocks: ```yaml
The environment variable should be in the yaml or run separately? if its separate, please use different code block.

@hussam789 hussam789 merged commit fda47bb into Codium-ai:main Sep 22, 2023
1 check passed
yochail pushed a commit to yochail/pr-agent that referenced this pull request Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants