mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-04 21:00:40 +08:00
implement suggestions in bitbucket pipeline
This commit is contained in:
@ -1,5 +1,12 @@
|
|||||||
FROM python:3.10 as base
|
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
|
WORKDIR /app
|
||||||
ADD pyproject.toml .
|
ADD pyproject.toml .
|
||||||
ADD requirements.txt .
|
ADD requirements.txt .
|
||||||
|
@ -386,14 +386,14 @@ You can use our pre-build Bitbucket-Pipeline docker image to run as Bitbucket-Pi
|
|||||||
name: PR Agent Pipeline
|
name: PR Agent Pipeline
|
||||||
caches:
|
caches:
|
||||||
- pip
|
- pip
|
||||||
image: python:3.8 # Use an appropriate Python image with pip
|
image: python:3.8
|
||||||
services:
|
services:
|
||||||
- docker
|
- docker
|
||||||
script:
|
script:
|
||||||
- git clone https://github.com/Codium-ai/pr-agent.git
|
- git clone https://github.com/Codium-ai/pr-agent.git
|
||||||
- cd pr-agent
|
- cd pr-agent
|
||||||
- pip install docker-compose
|
- docker build -t bitbucket_runner:latest -f Dockerfile.bitbucket_pipeline .
|
||||||
- docker-compose up --build
|
- 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.
|
2. Add the following secret to your repository under Repository settings > Pipelines > Repository variables.
|
||||||
OPENAI_API_KEY: <your key>
|
OPENAI_API_KEY: <your key>
|
||||||
|
@ -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}
|
|
@ -5,13 +5,13 @@ from pr_agent.tools.pr_reviewer import PRReviewer
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
async def run_action():
|
async def run_action():
|
||||||
|
try:
|
||||||
pull_request_id = os.environ.get("BITBUCKET_PR_ID", '')
|
pull_request_id = os.environ.get("BITBUCKET_PR_ID", '')
|
||||||
slug = os.environ.get("BITBUCKET_REPO_SLUG", '')
|
slug = os.environ.get("BITBUCKET_REPO_SLUG", '')
|
||||||
workspace = os.environ.get("BITBUCKET_WORKSPACE", '')
|
workspace = os.environ.get("BITBUCKET_WORKSPACE", '')
|
||||||
bearer_token = os.environ.get('BITBUCKET_BEARER_TOKEN', None)
|
bearer_token = os.environ.get('BITBUCKET_BEARER_TOKEN', None)
|
||||||
OPENAI_KEY = os.environ.get('OPENAI_API_KEY') or os.environ.get('OPENAI.KEY')
|
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')
|
OPENAI_ORG = os.environ.get('OPENAI_ORG') or os.environ.get('OPENAI.ORG')
|
||||||
|
|
||||||
# Check if required environment variables are set
|
# Check if required environment variables are set
|
||||||
if not bearer_token:
|
if not bearer_token:
|
||||||
print("BITBUCKET_BEARER_TOKEN not set")
|
print("BITBUCKET_BEARER_TOKEN not set")
|
||||||
@ -20,17 +20,15 @@ async def run_action():
|
|||||||
if not OPENAI_KEY:
|
if not OPENAI_KEY:
|
||||||
print("OPENAI_KEY not set")
|
print("OPENAI_KEY not set")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Set the environment variables in the settings
|
# Set the environment variables in the settings
|
||||||
get_settings().set("BITBUCKET.BEARER_TOKEN", bearer_token)
|
get_settings().set("BITBUCKET.BEARER_TOKEN", bearer_token)
|
||||||
get_settings().set("OPENAI.KEY", OPENAI_KEY)
|
get_settings().set("OPENAI.KEY", OPENAI_KEY)
|
||||||
if OPENAI_ORG:
|
if OPENAI_ORG:
|
||||||
get_settings().set("OPENAI.ORG", OPENAI_ORG)
|
get_settings().set("OPENAI.ORG", OPENAI_ORG)
|
||||||
|
|
||||||
if pull_request_id and slug and workspace:
|
if pull_request_id and slug and workspace:
|
||||||
pr_url = f"https://bitbucket.org/{workspace}/{slug}/pull-requests/{pull_request_id}"
|
pr_url = f"https://bitbucket.org/{workspace}/{slug}/pull-requests/{pull_request_id}"
|
||||||
await PRReviewer(pr_url).run()
|
await PRReviewer(pr_url).run()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
asyncio.run(run_action())
|
asyncio.run(run_action())
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[config]
|
[config]
|
||||||
model="gpt-4"
|
model="gpt-4"
|
||||||
fallback_models=["gpt-3.5-turbo-16k"]
|
fallback_models=["gpt-3.5-turbo-16k"]
|
||||||
git_provider="bitbucket"
|
git_provider="github"
|
||||||
publish_output=true
|
publish_output=true
|
||||||
publish_output_progress=true
|
publish_output_progress=true
|
||||||
verbosity_level=0 # 0,1,2
|
verbosity_level=0 # 0,1,2
|
||||||
@ -56,7 +56,6 @@ extra_instructions = ""
|
|||||||
[github]
|
[github]
|
||||||
# The type of deployment to create. Valid values are 'app' or 'user'.
|
# The type of deployment to create. Valid values are 'app' or 'user'.
|
||||||
deployment_type = "user"
|
deployment_type = "user"
|
||||||
user_token = "" # A GitHub personal access token with 'repo' scope.
|
|
||||||
ratelimit_retries = 5
|
ratelimit_retries = 5
|
||||||
|
|
||||||
[github_app]
|
[github_app]
|
||||||
@ -102,21 +101,6 @@ polling_interval_seconds = 30
|
|||||||
# token to authenticate in the patch server
|
# token to authenticate in the patch server
|
||||||
# patch_server_token = ""
|
# 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 = ""
|
|
||||||
|
|
||||||
[litellm]
|
[litellm]
|
||||||
#use_client = false
|
#use_client = false
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user