From d8de89ae33e37e21306a6cad23fa1bc483904c1d Mon Sep 17 00:00:00 2001 From: Zohar Meir <33152084+zmeir@users.noreply.github.com> Date: Mon, 16 Oct 2023 16:37:10 +0300 Subject: [PATCH 1/3] Get previous incremental review When getting the last commit in `/review -i` consider also the last __incremental__ review, not just the last __full__ review Full disclosure I'm not really sure the `/review -i` feature work very well - I might be wrong but it seemed like the actual review in fact addressed all the changes in the PR, and not just the ones from the last review (even though it adds a link to the commit of the last review). I think the commit list gathered in `/review -i` doesn't propagate the actual list the reviewer uses. Again, I might be wrong, just took a brief glance at it. --- pr_agent/git_providers/github_provider.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/git_providers/github_provider.py b/pr_agent/git_providers/github_provider.py index e5f62eb3..dcdd5692 100644 --- a/pr_agent/git_providers/github_provider.py +++ b/pr_agent/git_providers/github_provider.py @@ -78,7 +78,7 @@ class GithubProvider(GitProvider): self.previous_review = None self.comments = list(self.pr.get_issue_comments()) for index in range(len(self.comments) - 1, -1, -1): - if self.comments[index].body.startswith("## PR Analysis"): + if self.comments[index].body.startswith("## PR Analysis") or self.comments[index].body.startswith("## Incremental PR Review"): self.previous_review = self.comments[index] break From d41fe0cf799698c991e9a74099c6edfc0e8f6b75 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Tue, 17 Oct 2023 19:45:04 +0300 Subject: [PATCH 2/3] comment --- pr_agent/tools/pr_similar_issue.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/tools/pr_similar_issue.py b/pr_agent/tools/pr_similar_issue.py index 9ccd73a6..8f212a28 100644 --- a/pr_agent/tools/pr_similar_issue.py +++ b/pr_agent/tools/pr_similar_issue.py @@ -47,7 +47,7 @@ class PRSimilarIssue: # check if index exists, and if repo is already indexed run_from_scratch = False - if run_from_scratch: + if run_from_scratch: # for debugging if not index_name in pinecone.list_indexes(): get_logger().info('Removing index...') pinecone.init(api_key=api_key, environment=environment) From ff04d459d77b8286162178d60d8fb3bab1dffd3e Mon Sep 17 00:00:00 2001 From: Ori Kotek Date: Wed, 18 Oct 2023 15:46:43 +0300 Subject: [PATCH 3/3] Update Bitbucket Pipeline instructions in INSTALL.md, remove redundant functionality --- Dockerfile.bitbucket_pipeline | 18 -------- INSTALL.md | 45 +++---------------- bitbucket_pipeline/entrypoint.sh | 2 - pr_agent/servers/bitbucket_pipeline_runner.py | 34 -------------- 4 files changed, 7 insertions(+), 92 deletions(-) delete mode 100644 Dockerfile.bitbucket_pipeline delete mode 100644 bitbucket_pipeline/entrypoint.sh delete mode 100644 pr_agent/servers/bitbucket_pipeline_runner.py diff --git a/Dockerfile.bitbucket_pipeline b/Dockerfile.bitbucket_pipeline deleted file mode 100644 index 889ee120..00000000 --- a/Dockerfile.bitbucket_pipeline +++ /dev/null @@ -1,18 +0,0 @@ -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 . -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/INSTALL.md b/INSTALL.md index 492dc25c..b1e2c486 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -375,59 +375,28 @@ In the "Trigger" section, check the ‘comments’ and ‘merge request events ### Method 9: Run as a Bitbucket Pipeline -You can use our pre-build Bitbucket-Pipeline docker image to run as Bitbucket-Pipeline. +You can use the Bitbucket Pipeline system to run PR-Agent on every pull request open or update. 1. Add the following file in your repository bitbucket_pipelines.yml ```yaml - pipelines: +pipelines: pull-requests: '**': - step: - name: PR Agent Pipeline - caches: - - pip - image: python:3.8 + name: PR Agent Review + image: python:3.10 services: - docker script: - - 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 + - docker run -e CONFIG.GIT_PROVIDER=bitbucket -e OPENAI.KEY=$OPENAI_API_KEY -e BITBUCKET.BEARER_TOKEN=$BITBUCKET_BEARER_TOKEN codiumai/pr-agent:latest --pr_url=https://bitbucket.org/$BITBUCKET_WORKSPACE/$BITBUCKET_REPO_SLUG/pull-requests/$BITBUCKET_PR_ID review ``` -2. Add the following secret to your repository under Repository settings > Pipelines > Repository variables. +2. Add the following secure variables to your repository under Repository settings > Pipelines > Repository variables. OPENAI_API_KEY: BITBUCKET_BEARER_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= - - 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. +You can get a Bitbucket token for your repository by following Repository Settings -> Security -> Access Tokens ======= diff --git a/bitbucket_pipeline/entrypoint.sh b/bitbucket_pipeline/entrypoint.sh deleted file mode 100644 index cbea4b87..00000000 --- a/bitbucket_pipeline/entrypoint.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -python /app/pr_agent/servers/bitbucket_pipeline_runner.py \ No newline at end of file diff --git a/pr_agent/servers/bitbucket_pipeline_runner.py b/pr_agent/servers/bitbucket_pipeline_runner.py deleted file mode 100644 index 3c04e9ce..00000000 --- a/pr_agent/servers/bitbucket_pipeline_runner.py +++ /dev/null @@ -1,34 +0,0 @@ -import os -from pr_agent.agent.pr_agent import PRAgent -from pr_agent.config_loader import get_settings -from pr_agent.tools.pr_reviewer import PRReviewer -import asyncio - -async def run_action(): - 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())