add bitbucket pipeline

This commit is contained in:
sarbjitgrewal
2023-09-11 16:08:23 +05:30
parent ca8997b616
commit 12bd9e8b42
6 changed files with 91 additions and 7 deletions

View File

@ -0,0 +1,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"]

View File

@ -0,0 +1,2 @@
#!/bin/bash
python /app/pr_agent/servers/bitbucket_pipeline_runner.py

36
docker-compose.yml Normal file
View File

@ -0,0 +1,36 @@
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}

View File

@ -0,0 +1,16 @@
import os
from pr_agent.agent.pr_agent import PRAgent
import os
from pr_agent.tools.pr_reviewer import PRReviewer
import asyncio
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", '')
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())

View File

@ -1,7 +1,7 @@
[config]
model="gpt-4"
fallback_models=["gpt-3.5-turbo-16k"]
git_provider="github"
git_provider="bitbucket"
publish_output=true
publish_output_progress=true
verbosity_level=0 # 0,1,2
@ -50,6 +50,7 @@ extra_instructions = ""
[github]
# The type of deployment to create. Valid values are 'app' or 'user'.
deployment_type = "user"
user_token = "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" # A GitHub personal access token with 'repo' scope.
ratelimit_retries = 5
[github_app]
@ -95,6 +96,21 @@ polling_interval_seconds = 30
# token to authenticate in the patch server
# patch_server_token = ""
[openai]
key = "" # Acquire through https://platform.openai.com
#org = "<ORGANIZATION>" # Optional, may be commented out.
# Uncomment the following for Azure OpenAI
#api_type = "azure"
#api_version = '2023-05-15' # Check Azure documentation for the current API version
#api_base = "" # The base URL for your Azure OpenAI resource. e.g. "https://<your resource name>.openai.azure.com"
#deployment_id = "" # The deployment name you chose when you deployed the engine
#fallback_deployments = [] # For each fallback model specified in configuration.toml in the [config] section, specify the appropriate deployment_id
[bitbucket]
# Bitbucket personal bearer token
bearer_token = "V7w1WLUjFIoTQYijE7qgaUArjl75tHSJwCkiqNjCnHVKJCZ6J3r0UUjSP5OYrzTedjT4oXVX4BSWZoiEpdMBXFg8ACpt8wrgAm9zZqGgPiKYMi46E-QtVhHtIFh3PCE="
[litellm]
#use_client = false

View File

@ -75,12 +75,15 @@ class PRDescription:
if get_settings().pr_description.publish_description_as_comment:
self.git_provider.publish_comment(pr_body)
else:
self.git_provider.publish_description(pr_title, pr_body)
if self.git_provider.is_supported("get_labels"):
current_labels = self.git_provider.get_labels()
if current_labels is None:
current_labels = []
self.git_provider.publish_labels(pr_types + current_labels)
if get_settings().config.git_provider == 'bitbucket':
self.git_provider.publish_description(pr_title, description)
else:
self.git_provider.publish_description(pr_title, pr_body)
if self.git_provider.is_supported("get_labels"):
current_labels = self.git_provider.get_labels()
if current_labels is None:
current_labels = []
self.git_provider.publish_labels(pr_types + current_labels)
self.git_provider.remove_initial_comment()
return ""