diff --git a/README.md b/README.md
index bb8dac7e..c00fb63a 100644
--- a/README.md
+++ b/README.md
@@ -31,24 +31,20 @@ Making pull requests less painful with an AI agent
- [Why use PR-Agent?](#why-use-pr-agent)
## News and Updates
+### Feb 21, 2024
+- Added a new command, `/help`, to easily provide a list of available tools and their descriptions, and run them interactively.
+
+
+
+
+
+
+
+
+- GitLab webhook now supports controlling which commands will [run automatically](./docs/USAGE.md#working-with-gitlab-webhook) when a new PR is opened.
### Feb 18, 2024
- Introducing the `CI Feedback` tool 💎. The tool automatically triggers when a PR has a failed check. It analyzes the failed check, and provides summarized logs and analysis. Note that this feature requires read access to GitHub 'checks' and 'actions'. See [here](./docs/CI_FEEDBACK.md) for more details.
-
-
-
-
-
-→
-
-
-
-
-
- New ability - you can run `/ask` on specific lines of code in the PR from the PR's diff view. See [here](./docs/ASK.md#ask-lines) for more details.
-
-
-
-
- Introducing support for [Azure DevOps Webhooks](./Usage.md#azure-devops-webhook), as well as bug fixes and improved support for several ADO commands.
@@ -59,15 +55,7 @@ The `review` tool has been revamped, aiming to make the feedback clearer and mor
A new feature was added to the `review` tool - [Auto-approve PRs](./docs/REVIEW.md#auto-approval-1). If enabled, this feature enables to automatically approve PRs that meet specific criteria, by commenting on a PR: `/review auto_approve`.
### Feb 2, 2024
-Added ["PR Actions" 💎](https://www.codium.ai/images/pr_agent/pr-actions.mp4) - interactively trigger PR-Agent tools from the PR page.
-
-
-### Jan 28, 2024
-- 💎 Test - A new tool, [`/test component_name`](https://github.com/Codium-ai/pr-agent/blob/main/docs/TEST.md), was added to PR-Agent Pro. The tool will generate tests for a specific component, based on the PR code changes.
-- 💎 Analyze - The [`/analyze`](https://github.com/Codium-ai/pr-agent/blob/main/docs/Analyze.md) tool was updated and simplified. It now presents a summary of the code components that were changed in the PR.
-### Jan 21, 2024
-- 💎 Custom suggestions - A new tool, `/custom_suggestions`, was added to PR-Agent Pro. The tool will propose only suggestions that follow specific guidelines defined by the user.
-See [here](https://github.com/Codium-ai/pr-agent/blob/main/docs/CUSTOM_SUGGESTIONS.md) for more details.
+Added ["PR Actions"](https://www.codium.ai/images/pr_agent/pr-actions.mp4) 💎 - interactively trigger PR-Agent tools from the PR page.
## Overview
diff --git a/Usage.md b/Usage.md
index a84f854e..c2f91bd0 100644
--- a/Usage.md
+++ b/Usage.md
@@ -6,6 +6,7 @@
- [Online Usage](#online-usage)
- [GitHub App](#working-with-github-app)
- [GitHub Action](#working-with-github-action)
+- [GitLab Webhook](#working-with-gitlab-webhook)
- [BitBucket App](#working-with-bitbucket-self-hosted-app)
- [Azure DevOps Provider](#azure-devops-provider)
- [Additional Configurations Walkthrough](#appendix---additional-configurations-walkthrough)
@@ -237,6 +238,16 @@ For example, you can set an environment variable: `pr_description.add_original_u
[pr_description]
add_original_user_description = false
```
+### Working with GitLab Webhook
+After setting up a GitLab webhook, to control which commands will run automatically when a new PR is opened, you can set the `pr_commands` parameter in the configuration file, similar to the GitHub App:
+```
+[gitlab]
+pr_commands = [
+ "/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true",
+ "/review --pr_reviewer.num_code_suggestions=0",
+ "/improve",
+]
+```
### Working with BitBucket Self-Hosted App
Similar to GitHub app, when running PR-Agent from BitBucket App, the default [configuration file](pr_agent/settings/configuration.toml) from a pre-built docker will be initially loaded.
diff --git a/docs/CI_FEEDBACK.md b/docs/CI_FEEDBACK.md
index 4658ee67..7e14df78 100644
--- a/docs/CI_FEEDBACK.md
+++ b/docs/CI_FEEDBACK.md
@@ -28,4 +28,4 @@ where `{repo_name}` is the name of the repository, `{run_number}` is the run num
- `enable_auto_checks_feedback` - if set to true, the tool will automatically provide feedback when a check is failed. Default is true.
- `excluded_checks_list` - a list of checks to exclude from the feedback, for example: ["check1", "check2"]. Default is an empty list.
- `persistent_comment` - if set to true, the tool will overwrite a previous checks comment with the new feedback. Default is true.
-
+- `enable_help_text=true` - if set to true, the tool will provide a help message when a user comments "/checks" on a PR. Default is true.
diff --git a/pr_agent/servers/azuredevops_server_webhook.py b/pr_agent/servers/azuredevops_server_webhook.py
index 1459b78b..a7ba8659 100644
--- a/pr_agent/servers/azuredevops_server_webhook.py
+++ b/pr_agent/servers/azuredevops_server_webhook.py
@@ -54,20 +54,22 @@ def authorize(credentials: HTTPBasicCredentials = Depends(security)):
headers={'WWW-Authenticate': 'Basic'},
)
-async def _perform_commands(commands_conf: str, agent: PRAgent, body: dict, api_url: str, log_context: dict):
+
+async def _perform_commands_azure(commands_conf: str, agent: PRAgent, api_url: str, log_context: dict):
apply_repo_settings(api_url)
commands = get_settings().get(f"azure_devops_server.{commands_conf}")
for command in commands:
- split_command = command.split(" ")
- command = split_command[0]
- args = split_command[1:]
- other_args = update_settings_from_args(args)
- new_command = ' '.join([command] + other_args)
- if body:
- get_logger().info(body)
- get_logger().info(f"Performing command: {new_command}")
- with get_logger().contextualize(**log_context):
- await agent.handle_request(api_url, new_command)
+ try:
+ split_command = command.split(" ")
+ command = split_command[0]
+ args = split_command[1:]
+ other_args = update_settings_from_args(args)
+ new_command = ' '.join([command] + other_args)
+ get_logger().info(f"Performing command: {new_command}")
+ with get_logger().contextualize(**log_context):
+ await agent.handle_request(api_url, new_command)
+ except Exception as e:
+ get_logger().error(f"Failed to perform command {command}: {e}")
@router.post("/", dependencies=[Depends(authorize)])
@@ -82,7 +84,7 @@ async def handle_webhook(background_tasks: BackgroundTasks, request: Request):
pr_url = data["resource"]["_links"]["web"]["href"].replace("_apis/git/repositories", "_git")
log_context["event"] = data["eventType"]
log_context["api_url"] = pr_url
- await _perform_commands("pr_commands", PRAgent(), {}, pr_url, log_context)
+ await _perform_commands_azure("pr_commands", PRAgent(), pr_url, log_context)
return
elif data["eventType"] == "ms.vss-code.git-pullrequest-comment-event" and "content" in data["resource"]["comment"]:
if available_commands_rgx.match(data["resource"]["comment"]["content"]):
diff --git a/pr_agent/servers/gitlab_webhook.py b/pr_agent/servers/gitlab_webhook.py
index 165cd0a3..2779f80d 100644
--- a/pr_agent/servers/gitlab_webhook.py
+++ b/pr_agent/servers/gitlab_webhook.py
@@ -11,7 +11,9 @@ from starlette_context import context
from starlette_context.middleware import RawContextMiddleware
from pr_agent.agent.pr_agent import PRAgent
+from pr_agent.algo.utils import update_settings_from_args
from pr_agent.config_loader import get_settings, global_settings
+from pr_agent.git_providers.utils import apply_repo_settings
from pr_agent.log import LoggingFormat, get_logger, setup_logger
from pr_agent.secret_providers import get_secret_provider
@@ -29,6 +31,23 @@ def handle_request(background_tasks: BackgroundTasks, url: str, body: str, log_c
background_tasks.add_task(PRAgent().handle_request, url, body)
+async def _perform_commands_gitlab(commands_conf: str, agent: PRAgent, api_url: str, log_context: dict):
+ apply_repo_settings(api_url)
+ commands = get_settings().get(f"gitlab.{commands_conf}", {})
+ for command in commands:
+ try:
+ split_command = command.split(" ")
+ command = split_command[0]
+ args = split_command[1:]
+ other_args = update_settings_from_args(args)
+ new_command = ' '.join([command] + other_args)
+ get_logger().info(f"Performing command: {new_command}")
+ with get_logger().contextualize(**log_context):
+ await agent.handle_request(api_url, new_command)
+ except Exception as e:
+ get_logger().error(f"Failed to perform command {command}: {e}")
+
+
@router.post("/webhook")
async def gitlab_webhook(background_tasks: BackgroundTasks, request: Request):
log_context = {"server_type": "gitlab_app"}
@@ -58,7 +77,8 @@ 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']:
get_logger().info(f"A merge request has been opened: {data['object_attributes'].get('title')}")
url = data['object_attributes'].get('url')
- handle_request(background_tasks, url, "/review", log_context)
+ await _perform_commands_gitlab("pr_commands", PRAgent(), url, log_context)
+ # handle_request(background_tasks, url, "/review", log_context)
elif data.get('object_kind') == 'note' and data['event_type'] == 'note':
if 'merge_request' in data:
mr = data['merge_request']
diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml
index 61df5417..8d977e7a 100644
--- a/pr_agent/settings/configuration.toml
+++ b/pr_agent/settings/configuration.toml
@@ -113,7 +113,7 @@ enable_help_text=true
enable_auto_checks_feedback=true
excluded_checks_list=["lint"] # list of checks to exclude, for example: ["check1", "check2"]
persistent_comment=true
-
+enable_help_text=true
[pr_config] # /config #
@@ -171,17 +171,12 @@ push_commands = [
]
[gitlab]
-# URL to the gitlab service
-url = "https://gitlab.com"
-
-# Polling (either project id or namespace/project_name) syntax can be used
-projects_to_monitor = ['org_name/repo_name']
-
-# Polling trigger
-magic_word = "AutoReview"
-
-# Polling interval
-polling_interval_seconds = 30
+url = "https://gitlab.com" # URL to the gitlab service
+pr_commands = [
+ "/describe --pr_description.add_original_user_description=true --pr_description.keep_original_user_title=true",
+ "/review --pr_reviewer.num_code_suggestions=0",
+ "/improve --pr_code_suggestions.summarize=true",
+]
[bitbucket_app]
#auto_review = true # set as config var in .pr_agent.toml
diff --git a/pr_agent/tools/pr_help_message.py b/pr_agent/tools/pr_help_message.py
index 5677698c..01be9ade 100644
--- a/pr_agent/tools/pr_help_message.py
+++ b/pr_agent/tools/pr_help_message.py
@@ -58,12 +58,12 @@ class PRHelpMessage:
commands.append("`/similar_issue`")
checkbox_list = []
- checkbox_list.append(" - [ ] Send ")
- checkbox_list.append(" - [ ] Send ")
- checkbox_list.append(" - [ ] Send ")
- checkbox_list.append(" - [ ] Send ")
- checkbox_list.append(" - [ ] Send ")
- checkbox_list.append(" - [ ] Send ")
+ checkbox_list.append(" - [ ] Run ")
+ checkbox_list.append(" - [ ] Run ")
+ checkbox_list.append(" - [ ] Run ")
+ checkbox_list.append(" - [ ] Run ")
+ checkbox_list.append(" - [ ] Run ")
+ checkbox_list.append(" - [ ] Run ")
checkbox_list.append("[*]")
checkbox_list.append("[*]")
checkbox_list.append("[*]")
@@ -72,12 +72,12 @@ class PRHelpMessage:
checkbox_list.append("[*]")
if isinstance(self.git_provider, GithubProvider):
- pr_comment += f"
Tool | Description | Run this command :gem: |
"
+ pr_comment += f"Tool | Description | Invoke Interactively :gem: |
"
for i in range(len(tool_names)):
pr_comment += f"\n\n\n{tool_names[i]} | \n{descriptions[i]} | \n\n\n{checkbox_list[i]}\n |
"
pr_comment += "
\n\n"
- pr_comment += f"""\n\n(1) Note that each tool be [invoked automatically](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#github-app-automatic-tools-for-pr-actions) when a new PR is opened, or called manually by [commenting on a PR](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#online-usage)."""
- pr_comment += f"""\n\n(2) Tools marked with [*] require additional parameters to be passed. For example, to invoke the `/ask` tool, you need to comment on a PR: `/ask "What is the purpose of this PR?"`. See the relevant documentation for each tool for more details."""
+ pr_comment += f"""\n\n(1) Note that each tool be [triggered automatically](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#github-app-automatic-tools-for-pr-actions) when a new PR is opened, or called manually by [commenting on a PR](https://github.com/Codium-ai/pr-agent/blob/main/Usage.md#online-usage)."""
+ pr_comment += f"""\n\n(2) Tools marked with [*] require additional parameters to be passed. For example, to invoke the `/ask` tool, you need to comment on a PR: `/ask ""`. See the relevant documentation for each tool for more details."""
else:
pr_comment += f"Tool | Command | Description |
"
for i in range(len(tool_names)):