From 80a793a2579dbed2d24d8ce4ebaa3b7af001d40a Mon Sep 17 00:00:00 2001 From: koid Date: Mon, 18 Mar 2024 15:30:16 +0900 Subject: [PATCH 1/7] ignore bot pr option on github app mode --- pr_agent/servers/github_app.py | 6 ++++++ pr_agent/settings/configuration.toml | 1 + 2 files changed, 7 insertions(+) diff --git a/pr_agent/servers/github_app.py b/pr_agent/servers/github_app.py index fbe9db0f..5cbf3175 100644 --- a/pr_agent/servers/github_app.py +++ b/pr_agent/servers/github_app.py @@ -121,6 +121,12 @@ async def handle_new_pr_opened(body: Dict[str, Any], action: str, log_context: Dict[str, Any], agent: PRAgent): + # logic to ignore PRs opened by bot + if get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False): + if re.match('.+\[bot]$', sender) is not None: + get_logger().info(f"Ignoring PR by sender '{sender}' due to github_app.ignore_bot_pr setting") + return {} + title = body.get("pull_request", {}).get("title", "") # logic to ignore PRs with specific titles (e.g. "[Auto] ...") diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 21ad264b..a1a30ef3 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -155,6 +155,7 @@ push_commands = [ "/review --pr_reviewer.num_code_suggestions=0", ] ignore_pr_title = [] +ignore_bot_pr = false [gitlab] url = "https://gitlab.com" # URL to the gitlab service From b71523f13e4ededa7582734e8dba3ac1039eff4f Mon Sep 17 00:00:00 2001 From: koid Date: Mon, 18 Mar 2024 15:42:13 +0900 Subject: [PATCH 2/7] use endswith --- pr_agent/servers/github_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_agent/servers/github_app.py b/pr_agent/servers/github_app.py index 5cbf3175..ed6e1e73 100644 --- a/pr_agent/servers/github_app.py +++ b/pr_agent/servers/github_app.py @@ -123,7 +123,7 @@ async def handle_new_pr_opened(body: Dict[str, Any], agent: PRAgent): # logic to ignore PRs opened by bot if get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False): - if re.match('.+\[bot]$', sender) is not None: + if sender.endswith('[bot]'): get_logger().info(f"Ignoring PR by sender '{sender}' due to github_app.ignore_bot_pr setting") return {} From a969d1038105f6a148bb8520eb69a1a056ef92e6 Mon Sep 17 00:00:00 2001 From: Tal Date: Wed, 20 Mar 2024 09:07:52 +0200 Subject: [PATCH 3/7] Update build-and-test.yaml --- .github/workflows/build-and-test.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index 114bbb7e..3bf08cb5 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -2,8 +2,11 @@ name: Build-and-test on: push: + branches: + - main pull_request: - types: [ opened, reopened ] + branches: + - main jobs: build-and-test: From 31bb72d65d5d48e770e9fbf7017533de37df965c Mon Sep 17 00:00:00 2001 From: "Hussam.lawen" Date: Wed, 20 Mar 2024 11:09:23 +0200 Subject: [PATCH 4/7] add enable help text to documentation --- docs/docs/tools/describe.md | 3 ++- docs/docs/tools/review.md | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/docs/tools/describe.md b/docs/docs/tools/describe.md index 33c96e96..3351b802 100644 --- a/docs/docs/tools/describe.md +++ b/docs/docs/tools/describe.md @@ -49,7 +49,8 @@ To edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agen - `enable_semantic_files_types`: if set to true, "Changes walkthrough" section will be generated. Default is true. - `collapsible_file_list`: if set to true, the file list in the "Changes walkthrough" section will be collapsible. If set to "adaptive", the file list will be collapsible only if there are more than 8 files. Default is "adaptive". - + - `enable_help_text`: if set to true, the tool will display a help text in the comment. Default is true. + ### Inline file summary 💎 This feature enables you to copy the `changes walkthrough` table to the "Files changed" tab, so you can quickly understand the changes in each file while reviewing the code changes (diff view). diff --git a/docs/docs/tools/review.md b/docs/docs/tools/review.md index 8a571983..a8bd5a66 100644 --- a/docs/docs/tools/review.md +++ b/docs/docs/tools/review.md @@ -33,6 +33,7 @@ To edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agen - `inline_code_comments`: if set to true, the tool will publish the code suggestions as comments on the code diff. Default is false. - `persistent_comment`: if set to true, the review comment will be persistent, meaning that every new review request will edit the previous one. Default is true. - `extra_instructions`: Optional extra instructions to the tool. For example: "focus on the changes in the file X. Ignore change in ...". + - `enable_help_text`: if set to true, the tool will display a help text in the comment. Default is true. !!! example "Enable\\disable sub-sections" You can enable or disable specific sub-sections of the review tool: From 61b2a1a053ad447a8e45c539ad36ab9ed9d99e15 Mon Sep 17 00:00:00 2001 From: "Hussam.lawen" Date: Wed, 20 Mar 2024 11:11:06 +0200 Subject: [PATCH 5/7] update default --- docs/docs/tools/describe.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/tools/describe.md b/docs/docs/tools/describe.md index 3351b802..cf7ccdfb 100644 --- a/docs/docs/tools/describe.md +++ b/docs/docs/tools/describe.md @@ -49,7 +49,7 @@ To edit [configurations](https://github.com/Codium-ai/pr-agent/blob/main/pr_agen - `enable_semantic_files_types`: if set to true, "Changes walkthrough" section will be generated. Default is true. - `collapsible_file_list`: if set to true, the file list in the "Changes walkthrough" section will be collapsible. If set to "adaptive", the file list will be collapsible only if there are more than 8 files. Default is "adaptive". - - `enable_help_text`: if set to true, the tool will display a help text in the comment. Default is true. + - `enable_help_text`: if set to true, the tool will display a help text in the comment. Default is false. ### Inline file summary 💎 From cae0b9605413c8c9a393e98beaa02593fc3f7828 Mon Sep 17 00:00:00 2001 From: koid Date: Thu, 21 Mar 2024 12:06:46 +0900 Subject: [PATCH 6/7] use sender_type on bot check --- pr_agent/servers/github_app.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pr_agent/servers/github_app.py b/pr_agent/servers/github_app.py index ed6e1e73..80a673d7 100644 --- a/pr_agent/servers/github_app.py +++ b/pr_agent/servers/github_app.py @@ -118,14 +118,14 @@ async def handle_new_pr_opened(body: Dict[str, Any], event: str, sender: str, sender_id: str, + sender_type: str, action: str, log_context: Dict[str, Any], agent: PRAgent): # logic to ignore PRs opened by bot - if get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False): - if sender.endswith('[bot]'): - get_logger().info(f"Ignoring PR by sender '{sender}' due to github_app.ignore_bot_pr setting") - return {} + if get_settings().get("GITHUB_APP.IGNORE_BOT_PR", False) and sender_type == "Bot": + get_logger().info(f"Ignoring PR from '{sender=}' due to github_app.ignore_bot_pr setting") + return {} title = body.get("pull_request", {}).get("title", "") @@ -230,9 +230,11 @@ def handle_closed_pr(body, event, action, log_context): def get_log_context(body, event, action, build_number): sender = "" sender_id = "" + sender_type = "" try: sender = body.get("sender", {}).get("login") sender_id = body.get("sender", {}).get("id") + sender_type = body.get("sender", {}).get("type") repo = body.get("repository", {}).get("full_name", "") git_org = body.get("organization", {}).get("login", "") app_name = get_settings().get("CONFIG.APP_NAME", "Unknown") @@ -242,7 +244,7 @@ def get_log_context(body, event, action, build_number): except Exception as e: get_logger().error("Failed to get log context", e) log_context = {} - return log_context, sender, sender_id + return log_context, sender, sender_id, sender_type async def handle_request(body: Dict[str, Any], event: str): @@ -257,7 +259,7 @@ async def handle_request(body: Dict[str, Any], event: str): if not action: return {} agent = PRAgent() - log_context, sender, sender_id = get_log_context(body, event, action, build_number) + log_context, sender, sender_id, sender_type = get_log_context(body, event, action, build_number) # handle comments on PRs if action == 'created': @@ -266,7 +268,7 @@ async def handle_request(body: Dict[str, Any], event: str): # handle new PRs elif event == 'pull_request' and action != 'synchronize' and action != 'closed': get_logger().debug(f'Request body', artifact=body, event=event) - await handle_new_pr_opened(body, event, sender, sender_id, action, log_context, agent) + await handle_new_pr_opened(body, event, sender, sender_id, sender_type, action, log_context, agent) # handle pull_request event with synchronize action - "push trigger" for new commits elif event == 'pull_request' and action == 'synchronize': get_logger().debug(f'Request body', artifact=body, event=event) From 92fbf21bd3abe07bfb79e29e289ba172d006d115 Mon Sep 17 00:00:00 2001 From: veryyet Date: Thu, 21 Mar 2024 14:41:29 +0800 Subject: [PATCH 7/7] chore: fix some typos Signed-off-by: veryyet --- docs/docs/installation/azure.md | 10 +++++----- docs/docs/usage-guide/automations_and_usage.md | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/docs/installation/azure.md b/docs/docs/installation/azure.md index e8c11664..d6ffaa6b 100644 --- a/docs/docs/installation/azure.md +++ b/docs/docs/installation/azure.md @@ -7,12 +7,12 @@ git_provider="azure" ``` Azure DevOps provider supports [PAT token](https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Windows) or [DefaultAzureCredential](https://learn.microsoft.com/en-us/azure/developer/python/sdk/authentication-overview#authentication-in-server-environments) authentication. -PAT is faster to create, but has build in experation date, and will use the user identity for API calls. -Using DefaultAzureCredential you can use managed identity or Service principle, which are more secure and will create seperate ADO user identity (via AAD) to the agent. +PAT is faster to create, but has build in expiration date, and will use the user identity for API calls. +Using DefaultAzureCredential you can use managed identity or Service principle, which are more secure and will create separate ADO user identity (via AAD) to the agent. -If PAT was choosen, you can assign the value in .secrets.toml. -If DefaultAzureCredential was choosen, you can assigned the additional env vars like AZURE_CLIENT_SECRET directly, -or use managed identity/az cli (for local develpment) without any additional configuration. +If PAT was chosen, you can assign the value in .secrets.toml. +If DefaultAzureCredential was chosen, you can assigned the additional env vars like AZURE_CLIENT_SECRET directly, +or use managed identity/az cli (for local development) without any additional configuration. in any case, 'org' value must be assigned in .secrets.toml: ``` [azure_devops] diff --git a/docs/docs/usage-guide/automations_and_usage.md b/docs/docs/usage-guide/automations_and_usage.md index b39f7e02..ba21b998 100644 --- a/docs/docs/usage-guide/automations_and_usage.md +++ b/docs/docs/usage-guide/automations_and_usage.md @@ -173,12 +173,12 @@ git_provider="azure" ``` Azure DevOps provider supports [PAT token](https://learn.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops&tabs=Windows) or [DefaultAzureCredential](https://learn.microsoft.com/en-us/azure/developer/python/sdk/authentication-overview#authentication-in-server-environments) authentication. -PAT is faster to create, but has build in experation date, and will use the user identity for API calls. -Using DefaultAzureCredential you can use managed identity or Service principle, which are more secure and will create seperate ADO user identity (via AAD) to the agent. +PAT is faster to create, but has build in expiration date, and will use the user identity for API calls. +Using DefaultAzureCredential you can use managed identity or Service principle, which are more secure and will create separate ADO user identity (via AAD) to the agent. -If PAT was choosen, you can assign the value in .secrets.toml. -If DefaultAzureCredential was choosen, you can assigned the additional env vars like AZURE_CLIENT_SECRET directly, -or use managed identity/az cli (for local develpment) without any additional configuration. +If PAT was chosen, you can assign the value in .secrets.toml. +If DefaultAzureCredential was chosen, you can assigned the additional env vars like AZURE_CLIENT_SECRET directly, +or use managed identity/az cli (for local development) without any additional configuration. in any case, 'org' value must be assigned in .secrets.toml: ``` [azure_devops]