diff --git a/Dockerfile.bitbucket_pipeline b/Dockerfile.bitbucket_pipeline index b7560001..889ee120 100644 --- a/Dockerfile.bitbucket_pipeline +++ b/Dockerfile.bitbucket_pipeline @@ -1,5 +1,12 @@ FROM python:3.10 as base +ENV OPENAI_API_KEY=${OPENAI_API_KEY} \ + BITBUCKET_BEARER_TOKEN=${BITBUCKET_BEARER_TOKEN} \ + BITBUCKET_PR_ID=${BITBUCKET_PR_ID} \ + BITBUCKET_REPO_SLUG=${BITBUCKET_REPO_SLUG} \ + BITBUCKET_WORKSPACE=${BITBUCKET_WORKSPACE} + + WORKDIR /app ADD pyproject.toml . ADD requirements.txt . diff --git a/INSTALL.md b/INSTALL.md index 4593dccf..b3ecd177 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -379,21 +379,21 @@ You can use our pre-build Bitbucket-Pipeline docker image to run as Bitbucket-Pi 1. Add the following file in your repository bitbucket_pipelines.yml - pipelines: + pipelines: pull-requests: - '**': + '**': - step: name: PR Agent Pipeline caches: - - pip - image: python:3.8 # Use an appropriate Python image with pip + - pip + image: python:3.8 services: - - docker + - docker script: - - git clone https://github.com/Codium-ai/pr-agent.git - - cd pr-agent - - pip install docker-compose - - docker-compose up --build + - 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 2. Add the following secret to your repository under Repository settings > Pipelines > Repository variables. OPENAI_API_KEY: diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index 3b4b4d3b..00000000 --- a/docker-compose.yml +++ /dev/null @@ -1,37 +0,0 @@ -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} \ No newline at end of file diff --git a/pr_agent/servers/bitbucket_pipeline_runner.py b/pr_agent/servers/bitbucket_pipeline_runner.py index 12c2c6d3..3c04e9ce 100644 --- a/pr_agent/servers/bitbucket_pipeline_runner.py +++ b/pr_agent/servers/bitbucket_pipeline_runner.py @@ -5,32 +5,30 @@ 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", '') - 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() - + 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()) - diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 3f86b330..a272e1f9 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="bitbucket" +git_provider="github" publish_output=true publish_output_progress=true verbosity_level=0 # 0,1,2 @@ -56,7 +56,6 @@ 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. ratelimit_retries = 5 [github_app] @@ -102,21 +101,6 @@ 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 = "" - [litellm] #use_client = false