Compare commits

...

36 Commits

Author SHA1 Message Date
fe3527de3c Add exception handling for applying repo settings failure 2023-11-03 12:23:49 +02:00
b99c769b53 Merge pull request #415 from zmeir/zmeir-patch-2
Refactor Command Handling for Different Triggers
2023-11-02 18:32:42 +02:00
60bdfb78df Merge pull request #424 from Codium-ai/ok/bitbucket_fix
Update Bitbucket Provider to Use 'position' Instead of 'start_line' for Inline Comments
2023-11-02 18:31:18 +02:00
c0b3c76884 Merge remote-tracking branch 'origin/main' into ok/bitbucket_fix 2023-11-02 15:27:11 +02:00
e1370a8385 Update publish_inline_comments in bitbucket_provider.py to use 'position' instead of 'start_line' 2023-11-02 15:24:47 +02:00
d0f3a4139d Merge pull request #422 from Codium-ai/pr_review_fix_type_example
small fix to pr type example yaml
2023-11-02 11:48:49 +02:00
3ddc7e79d1 Update pr_reviewer_prompts.toml 2023-11-02 11:45:34 +02:00
3e14edfd4e Merge pull request #421 from zmeir/patch-1
Fix error in `get_main_pr_languages` when the diff is empty
2023-11-02 01:20:36 -07:00
15573e2286 Fix error in get_main_pr_languages when the diff is empty
This can happen for example when you have one commit add a line to a file and the next commit deletes that line. Then if those are the only 2 commits in the PR the diff will be empty.
2023-11-02 10:10:54 +02:00
ce64877063 Merge pull request #419 from KennyDizi/fix_synstax_error
Fix Syntax Error in f-string Expression
2023-11-02 08:23:17 +02:00
6666a128ee Update Usage.md 2023-11-01 18:36:12 +02:00
9fbf89670d Improve expression portion of f-strings 2023-11-01 19:11:52 +07:00
ad1c51c536 Fix SyntaxError: f-string expression part cannot include a backslash 2023-11-01 19:06:29 +07:00
9ab7ccd20d Merge pull request #416 from zmeir/patch-1
Fix formatting when last commit message contains _
2023-11-01 13:13:31 +02:00
c907f93ab8 Merge pull request #418 from KennyDizi/fix/configuration-typo
Fix Typo and Update Comment for Ollama Configuration
2023-10-31 11:14:51 -07:00
29a8cf8357 fix typo for ollama 2023-10-31 20:38:27 +07:00
7b6a6c7164 Fix formatting when last commit message contains _ 2023-10-31 10:05:13 +02:00
cf4d007737 Fix commands list for push trigger 2023-10-31 00:00:48 +02:00
a751bb0ef0 Merge pull request #414 from Codium-ai/ok/fix_github_bug
Bugfix: ignored github_app.commands on .pr-agent.toml
2023-10-30 20:28:54 +02:00
26d6280a20 Merge remote-tracking branch 'origin/main' into ok/fix_github_bug 2023-10-30 20:19:41 +02:00
32a19fdab6 Merge pull request #413 from Codium-ai/ok/bitbucket_repo_settings
Update Method to Fetch Repository Settings in bitbucket_provider.py
2023-10-30 20:18:59 +02:00
775ccb3f25 Refactor _perform_commands function in github_app.py to improve command handling 2023-10-30 20:14:25 +02:00
a1c6c57f7b Merge remote-tracking branch 'origin/main' into ok/bitbucket_repo_settings 2023-10-30 18:38:08 +02:00
73bb70fef4 Update get_repo_settings in bitbucket_provider.py to fetch file via API request 2023-10-30 18:36:46 +02:00
dcac6c145c Merge pull request #412 from Codium-ai/ok/fix_gitlab_bug
Update get_repo_settings to decode file from target branch in gitlab_…
2023-10-30 17:04:09 +02:00
4bda9dfe04 Update get_repo_settings to decode file from target branch in gitlab_provider.py 2023-10-30 17:01:49 +02:00
66644f0224 Merge pull request #411 from Codium-ai/ok/fix_gitlab_bug
Add Logging Context to Handle Request Calls in gitlab_webhook.py
2023-10-30 16:53:40 +02:00
e74bb80668 Refactor get_repo_settings method in gitlab_provider.py to decode file contents 2023-10-30 16:45:47 +02:00
e06fb534d3 Merge remote-tracking branch 'origin/main' into ok/fix_gitlab_bug 2023-10-30 16:34:03 +02:00
71a341855e Add log_context to handle_request calls in gitlab_webhook.py 2023-10-30 16:00:09 +02:00
7d949ad6e2 Update GENERATE_CUSTOM_LABELS.md 2023-10-30 15:20:17 +02:00
4b5f86fcf0 Merge pull request #410 from Codium-ai/fix_link_in_install
small fix in link in install.md
2023-10-30 02:58:52 -07:00
cd11f51df0 small fix in link in install.md 2023-10-30 11:47:24 +02:00
b40c0b9b23 Merge pull request #409 from zmeir/patch-1
Fix call to `_get_previous_review_comment`
2023-10-30 01:28:12 -07:00
816ddeeb9e Fix call to _get_previous_review_comment
Hey @mrT23, I thinks there's a problem with moving this line to after `self.git_provider.publish_comment(pr_comment)`.

The reason I originally placed it here is because otherwise, if you run `/review --pr_reviewer.remove_previous_review_comment=true` it will publish your review and then immediately after delete it, because it will look for the previous review comment only after you published your new review - so it will take your new review as the previous one. In order to get the real "previous" review you must collect the comments list before publishing a review, so placing this method call first ensures that.

The method `self._get_previous_review_comment()` is a no-op if `pr_reviewer.remove_previous_review_comment=false` so I see no downside in keeping it before `self.git_provider.publish_comment(pr_comment)`

Additionally, the check for `if previous_review_comment:` is redundant because it's done internally in `self._remove_previous_review_comment`. I thought it looked cleaner without this extra nesting here, but if you think more verbosity is better I'll keep it.
2023-10-30 09:06:51 +02:00
11f01a226c Update RELEASE_NOTES.md 2023-10-30 08:22:36 +02:00
13 changed files with 40 additions and 21 deletions

View File

@ -368,7 +368,7 @@ PYTHONPATH="/PATH/TO/PROJECTS/pr-agent" python pr_agent/cli.py \
``` ```
WEBHOOK_SECRET=$(python -c "import secrets; print(secrets.token_hex(10))") WEBHOOK_SECRET=$(python -c "import secrets; print(secrets.token_hex(10))")
``` ```
3. Follow the instructions to build the Docker image, setup a secrets file and deploy on your own server from [Method 5](#method-5-run-as-a-github-app) steps 4-7. 3. Follow the instructions to build the Docker image, setup a secrets file and deploy on your own server from [Method 5](#run-as-a-github-app) steps 4-7.
4. In the secrets file, fill in the following: 4. In the secrets file, fill in the following:
- Your OpenAI key. - Your OpenAI key.
- In the [gitlab] section, fill in personal_access_token and shared_secret. The access token can be a personal access token, or a group or project access token. - In the [gitlab] section, fill in personal_access_token and shared_secret. The access token can be a personal access token, or a group or project access token.

View File

@ -9,9 +9,10 @@
### Added::Algo ### Added::Algo
- New tool - [generate_labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/GENERATE_CUSTOM_LABELS.md) - New tool - [generate_labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/GENERATE_CUSTOM_LABELS.md)
- New ability to use [customize labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/GENERATE_CUSTOM_LABELS.md#how-to-enable-custom-labels) on the `review` and `describe` tools. - New ability to use [customize labels](https://github.com/Codium-ai/pr-agent/blob/main/docs/GENERATE_CUSTOM_LABELS.md#how-to-enable-custom-labels) on the `review` and `describe` tools.
- New tool - [add_docs](https://github.com/Codium-ai/pr-agent/blob/main/docs/ADD_DOCUMENTATION.md)
- GitHub Action: Can now use a `.pr_agent.toml` file to control configuration parameters (see [Usage Guide](./Usage.md#working-with-github-action)). - GitHub Action: Can now use a `.pr_agent.toml` file to control configuration parameters (see [Usage Guide](./Usage.md#working-with-github-action)).
- GitHub App: Added ability to trigger tools on [push events](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#github-app-automatic-tools-for-new-code-pr-push) - GitHub App: Added ability to trigger tools on [push events](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#github-app-automatic-tools-for-new-code-pr-push)
- Support custom domain URLs for azure devops integration (see [link](https://github.com/Codium-ai/pr-agent/pull/381)). - Support custom domain URLs for Azure devops integration (see [link](https://github.com/Codium-ai/pr-agent/pull/381)).
- PR Description default mode is now in [bullet points](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L35). - PR Description default mode is now in [bullet points](https://github.com/Codium-ai/pr-agent/blob/main/pr_agent/settings/configuration.toml#L35).
### Added::Documentation ### Added::Documentation

View File

@ -108,12 +108,22 @@ Any configuration value in [configuration file](pr_agent/settings/configuration.
### Working with GitHub App ### Working with GitHub App
When running PR-Agent from [GitHub App](INSTALL.md#method-5-run-as-a-github-app), the default configurations from a pre-built docker will be initially loaded. When running PR-Agent from GitHub App, the default [configuration file](pr_agent/settings/configuration.toml) from a pre-built docker will be initially loaded.
By uploading a local `.pr_agent.toml` file, you can edit and customize any configuration parameter.
For example, if you set in `.pr_agent.toml`:
```
[pr_reviewer]
num_code_suggestions=1
```
Than you will overwrite the default number of code suggestions to be 1.
#### GitHub app automatic tools #### GitHub app automatic tools
The [github_app](pr_agent/settings/configuration.toml#L56) section defines GitHub app specific configurations. The [github_app](pr_agent/settings/configuration.toml#L76) section defines GitHub app-specific configurations.
In this section you can define configurations to control the conditions for which tools will **run automatically**. In this section you can define configurations to control the conditions for which tools will **run automatically**.
Note that a local `.pr_agent.toml` file enables you to edit and customize the default parameters of any tool, not just the ones that are run automatically.
##### GitHub app automatic tools for PR actions ##### GitHub app automatic tools for PR actions
The GitHub app can respond to the following actions on a PR: The GitHub app can respond to the following actions on a PR:
@ -151,7 +161,7 @@ handle_pr_actions = []
``` ```
##### GitHub app automatic tools for new code (PR push) ##### GitHub app automatic tools for new code (PR push)
In addition the running automatic tools when a PR is opened, the GitHub app can also respond to new code that is pushed to an open PR. In addition to running automatic tools when a PR is opened, the GitHub app can also respond to new code that is pushed to an open PR.
The configuration toggle `handle_push_trigger` can be used to enable this feature. The configuration toggle `handle_push_trigger` can be used to enable this feature.
The configuration parameter `push_commands` defines the list of tools that will be **run automatically** when new code is pushed to the PR. The configuration parameter `push_commands` defines the list of tools that will be **run automatically** when new code is pushed to the PR.

View File

@ -10,6 +10,7 @@ For example:
If we wish to add detect changes to SQL queries in a given PR, we can add the following custom label along with its description: If we wish to add detect changes to SQL queries in a given PR, we can add the following custom label along with its description:
<kbd><img src=./../pics/custom_labels_list.png width="768"></kbd> <kbd><img src=./../pics/custom_labels_list.png width="768"></kbd>
When running the `generate_labels` tool on a PR that includes changes in SQL queries, it will automatically suggest the custom label: When running the `generate_labels` tool on a PR that includes changes in SQL queries, it will automatically suggest the custom label:
<kbd><img src=./../pics/custom_label_published.png width="768"></kbd> <kbd><img src=./../pics/custom_label_published.png width="768"></kbd>

View File

@ -41,9 +41,10 @@ class BitbucketProvider(GitProvider):
def get_repo_settings(self): def get_repo_settings(self):
try: try:
contents = self.repo_obj.get_contents( url = (f"https://api.bitbucket.org/2.0/repositories/{self.workspace_slug}/{self.repo_slug}/src/"
".pr_agent.toml", ref=self.pr.head.sha f"{self.pr.destination_branch}/.pr_agent.toml")
).decoded_content response = requests.request("GET", url, headers=self.headers)
contents = response.text.encode('utf-8')
return contents return contents
except Exception: except Exception:
return "" return ""
@ -182,7 +183,7 @@ class BitbucketProvider(GitProvider):
def publish_inline_comments(self, comments: list[dict]): def publish_inline_comments(self, comments: list[dict]):
for comment in comments: for comment in comments:
self.publish_inline_comment(comment['body'], comment['start_line'], comment['path']) self.publish_inline_comment(comment['body'], comment['position'], comment['path'])
def get_title(self): def get_title(self):
return self.pr.title return self.pr.title

View File

@ -143,6 +143,9 @@ def get_main_pr_language(languages, files) -> str:
if not languages: if not languages:
get_logger().info("No languages detected") get_logger().info("No languages detected")
return main_language_str return main_language_str
if not files:
get_logger().info("No files in diff")
return main_language_str
try: try:
top_language = max(languages, key=languages.get).lower() top_language = max(languages, key=languages.get).lower()

View File

@ -315,7 +315,7 @@ class GitLabProvider(GitProvider):
def get_repo_settings(self): def get_repo_settings(self):
try: try:
contents = self.gl.projects.get(self.id_project).files.get(file_path='.pr_agent.toml', ref=self.mr.source_branch) contents = self.gl.projects.get(self.id_project).files.get(file_path='.pr_agent.toml', ref=self.mr.target_branch).decode()
return contents return contents
except Exception: except Exception:
return "" return ""

View File

@ -27,7 +27,8 @@ def apply_repo_settings(pr_url):
get_settings().unset(section) get_settings().unset(section)
get_settings().set(section, section_dict, merge=False) get_settings().set(section, section_dict, merge=False)
get_logger().info(f"Applying repo settings for section {section}, contents: {contents}") get_logger().info(f"Applying repo settings for section {section}, contents: {contents}")
except Exception as e:
get_logger().exception("Failed to apply repo settings", e)
finally: finally:
if repo_settings_file: if repo_settings_file:
try: try:

View File

@ -122,7 +122,7 @@ async def handle_request(body: Dict[str, Any], event: str):
if body.get("requested_reviewer", {}).get("login", "") != bot_user: if body.get("requested_reviewer", {}).get("login", "") != bot_user:
return {} return {}
get_logger().info(f"Performing review for {api_url=} because of {event=} and {action=}") get_logger().info(f"Performing review for {api_url=} because of {event=} and {action=}")
await _perform_commands(get_settings().github_app.pr_commands, agent, body, api_url, log_context) await _perform_commands("pr_commands", agent, body, api_url, log_context)
# handle pull_request event with synchronize action - "push trigger" for new commits # handle pull_request event with synchronize action - "push trigger" for new commits
elif event == 'pull_request' and action == 'synchronize' and get_settings().github_app.handle_push_trigger: elif event == 'pull_request' and action == 'synchronize' and get_settings().github_app.handle_push_trigger:
@ -174,7 +174,7 @@ async def handle_request(body: Dict[str, Any], event: str):
get_logger().info(f"Skipping incremental review because there was no initial review for {api_url=} yet") get_logger().info(f"Skipping incremental review because there was no initial review for {api_url=} yet")
return {} return {}
get_logger().info(f"Performing incremental review for {api_url=} because of {event=} and {action=}") get_logger().info(f"Performing incremental review for {api_url=} because of {event=} and {action=}")
await _perform_commands(get_settings().github_app.push_commands, agent, body, api_url, log_context) await _perform_commands("push_commands", agent, body, api_url, log_context)
finally: finally:
# release the waiting task block # release the waiting task block
@ -203,8 +203,9 @@ def _check_pull_request_event(action: str, body: dict, log_context: dict, bot_us
return pull_request, api_url return pull_request, api_url
async def _perform_commands(commands: List[str], agent: PRAgent, body: dict, api_url: str, log_context: dict): async def _perform_commands(commands_conf: str, agent: PRAgent, body: dict, api_url: str, log_context: dict):
apply_repo_settings(api_url) apply_repo_settings(api_url)
commands = get_settings().get(f"github_app.{commands_conf}")
for command in commands: for command in commands:
split_command = command.split(" ") split_command = command.split(" ")
command = split_command[0] command = split_command[0]

View File

@ -58,13 +58,13 @@ async def gitlab_webhook(background_tasks: BackgroundTasks, request: Request):
if data.get('object_kind') == 'merge_request' and data['object_attributes'].get('action') in ['open', 'reopen']: if data.get('object_kind') == 'merge_request' and data['object_attributes'].get('action') in ['open', 'reopen']:
get_logger().info(f"A merge request has been opened: {data['object_attributes'].get('title')}") get_logger().info(f"A merge request has been opened: {data['object_attributes'].get('title')}")
url = data['object_attributes'].get('url') url = data['object_attributes'].get('url')
handle_request(background_tasks, url, "/review") handle_request(background_tasks, url, "/review", log_context)
elif data.get('object_kind') == 'note' and data['event_type'] == 'note': elif data.get('object_kind') == 'note' and data['event_type'] == 'note':
if 'merge_request' in data: if 'merge_request' in data:
mr = data['merge_request'] mr = data['merge_request']
url = mr.get('url') url = mr.get('url')
body = data.get('object_attributes', {}).get('note') body = data.get('object_attributes', {}).get('note')
handle_request(background_tasks, url, body) handle_request(background_tasks, url, body, log_context)
return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"}))

View File

@ -34,7 +34,7 @@ key = "" # Optional, uncomment if you want to use Huggingface Inference API. Acq
api_base = "" # the base url for your huggingface inference endpoint api_base = "" # the base url for your huggingface inference endpoint
[ollama] [ollama]
api_base = "" # the base url for your huggingface inference endpoint api_base = "" # the base url for your local Llama 2, Code Llama, and other models inference endpoint. Acquire through https://ollama.ai/
[github] [github]
# ---- Set the following only for deployment type == "user" # ---- Set the following only for deployment type == "user"

View File

@ -151,7 +151,7 @@ PR Analysis:
PR summary: |- PR summary: |-
xxx xxx
Type of PR: |- Type of PR: |-
Bug fix ...
{%- if require_score %} {%- if require_score %}
Score: 89 Score: 89
{%- endif %} {%- endif %}

View File

@ -116,9 +116,9 @@ class PRReviewer:
if get_settings().config.publish_output: if get_settings().config.publish_output:
get_logger().info('Pushing PR review...') get_logger().info('Pushing PR review...')
previous_review_comment = self._get_previous_review_comment()
self.git_provider.publish_comment(pr_comment) self.git_provider.publish_comment(pr_comment)
self.git_provider.remove_initial_comment() self.git_provider.remove_initial_comment()
previous_review_comment = self._get_previous_review_comment()
if previous_review_comment: if previous_review_comment:
self._remove_previous_review_comment(previous_review_comment) self._remove_previous_review_comment(previous_review_comment)
if get_settings().pr_reviewer.inline_code_comments: if get_settings().pr_reviewer.inline_code_comments:
@ -239,7 +239,8 @@ class PRReviewer:
last_commit_msg = self.incremental.commits_range[0].commit.message if self.incremental.commits_range else "" last_commit_msg = self.incremental.commits_range[0].commit.message if self.incremental.commits_range else ""
incremental_review_markdown_text = f"Starting from commit {last_commit_url}" incremental_review_markdown_text = f"Starting from commit {last_commit_url}"
if last_commit_msg: if last_commit_msg:
incremental_review_markdown_text += f" \n_({last_commit_msg.splitlines(keepends=False)[0]})_" replacement = last_commit_msg.splitlines(keepends=False)[0].replace('_', r'\_')
incremental_review_markdown_text += f" \n_({replacement})_"
data = OrderedDict(data) data = OrderedDict(data)
data.update({'Incremental PR Review': { data.update({'Incremental PR Review': {
"⏮️ Review for commits since previous PR-Agent review": incremental_review_markdown_text}}) "⏮️ Review for commits since previous PR-Agent review": incremental_review_markdown_text}})