mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-03 04:10:49 +08:00
bitbucket pipeline for adding reviews
This commit is contained in:
58
INSTALL.md
58
INSTALL.md
@ -16,6 +16,7 @@ There are several ways to use PR-Agent:
|
||||
- [Method 6: Deploy as a Lambda Function](INSTALL.md#method-6---deploy-as-a-lambda-function)
|
||||
- [Method 7: AWS CodeCommit](INSTALL.md#method-7---aws-codecommit-setup)
|
||||
- [Method 8: Run a GitLab webhook server](INSTALL.md#method-8---run-a-gitlab-webhook-server)
|
||||
- [Method 9: Run as a Bitbucket Pipeline](INSTALL.md#method-9-run-as-a-bitbucket-pipeline)
|
||||
---
|
||||
|
||||
### Method 1: Use Docker image (no installation required)
|
||||
@ -370,4 +371,61 @@ In the "Trigger" section, check the ‘comments’ and ‘merge request events
|
||||
6. Test your installation by opening a merge request or commenting or a merge request using one of CodiumAI's commands.
|
||||
|
||||
|
||||
|
||||
### Method 9: Run as a Bitbucket Pipeline
|
||||
|
||||
|
||||
You can use our pre-build Bitbucket-Pipeline docker image to run as Bitbucket-Pipeline.
|
||||
|
||||
1. Add the following file in your repository bitbucket_pipelines.yml
|
||||
|
||||
pipelines:
|
||||
pull-requests:
|
||||
'**':
|
||||
- step:
|
||||
name: PR Agent Pipeline
|
||||
caches:
|
||||
- pip
|
||||
image: python:3.8 # Use an appropriate Python image with pip
|
||||
services:
|
||||
- docker
|
||||
script:
|
||||
- git clone https://github.com/Codium-ai/pr-agent.git
|
||||
- cd pr-agent
|
||||
- pip install docker-compose
|
||||
- docker-compose up --build
|
||||
|
||||
2. Add the following secret to your repository under Repository settings > Pipelines > Repository variables.
|
||||
OPENAI_API_KEY: <your key>
|
||||
BITBUCKET_BEARER_TOKEN: <your token>
|
||||
|
||||
3. To get BITBUCKET_BEARER_TOKEN follow these steps
|
||||
So here is my step by step tutorial
|
||||
i) Insert your workspace name instead of {workspace_name} and go to the following link in order to create an OAuth consumer.
|
||||
|
||||
https://bitbucket.org/{workspace_name}/workspace/settings/api
|
||||
|
||||
set callback URL to http://localhost:8976 (doesn't need to be a real server there)
|
||||
select permissions: repository -> read
|
||||
|
||||
ii) use consumer's Key as a {client_id} and open the following URL in the browser
|
||||
|
||||
https://bitbucket.org/site/oauth2/authorize?client_id={client_id}&response_type=code
|
||||
|
||||
iii)
|
||||
after you press "Grant access" in the browser it will redirect you to
|
||||
|
||||
http://localhost:8976?code=<CODE>
|
||||
|
||||
iv) use the code from the previous step and consumer's Key as a {client_id}, and consumer's Secret as {client_secret}
|
||||
|
||||
curl -X POST -u "{client_id}:{client_secret}" \
|
||||
https://bitbucket.org/site/oauth2/access_token \
|
||||
-d grant_type=authorization_code \
|
||||
-d code={code} \
|
||||
|
||||
|
||||
After completing this steps, you just to place this access token in the repository varibles.
|
||||
|
||||
|
||||
=======
|
||||
|
@ -158,6 +158,7 @@ There are several ways to use PR-Agent:
|
||||
- [Method 6: Deploy as a Lambda Function](INSTALL.md#method-6---deploy-as-a-lambda-function)
|
||||
- [Method 7: AWS CodeCommit](INSTALL.md#method-7---aws-codecommit-setup)
|
||||
- [Method 8: Run a GitLab webhook server](INSTALL.md#method-8---run-a-gitlab-webhook-server)
|
||||
- [Method 9: Run as a Bitbucket Pipeline](INSTALL.md#method-9-run-as-a-bitbucket-pipeline)
|
||||
|
||||
## How it works
|
||||
|
||||
|
@ -9,13 +9,23 @@ async def run_action():
|
||||
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}"
|
||||
|
Reference in New Issue
Block a user