diff --git a/Dockerfile.bitbucket_pipeline b/Dockerfile.bitbucket_pipeline new file mode 100644 index 00000000..b7560001 --- /dev/null +++ b/Dockerfile.bitbucket_pipeline @@ -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"] diff --git a/bitbucket_pipeline/entrypoint.sh b/bitbucket_pipeline/entrypoint.sh new file mode 100644 index 00000000..cbea4b87 --- /dev/null +++ b/bitbucket_pipeline/entrypoint.sh @@ -0,0 +1,2 @@ +#!/bin/bash +python /app/pr_agent/servers/bitbucket_pipeline_runner.py \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..65f2a195 --- /dev/null +++ b/docker-compose.yml @@ -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} \ No newline at end of file diff --git a/pr_agent/servers/bitbucket_pipeline_runner.py b/pr_agent/servers/bitbucket_pipeline_runner.py new file mode 100644 index 00000000..8a967756 --- /dev/null +++ b/pr_agent/servers/bitbucket_pipeline_runner.py @@ -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()) \ No newline at end of file diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 75dfcf97..d247f86b 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -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 = "" # 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://.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 diff --git a/pr_agent/tools/pr_description.py b/pr_agent/tools/pr_description.py index f30b0165..cd276785 100644 --- a/pr_agent/tools/pr_description.py +++ b/pr_agent/tools/pr_description.py @@ -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 ""