From 42557feb9711d106f664df89e4d6993407c225c3 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Fri, 16 May 2025 17:20:54 +0300 Subject: [PATCH] Enhance repository filtering with regex pattern matching for ignore_repositories --- .../usage-guide/additional_configurations.md | 17 +++++++++++++++-- pr_agent/servers/bitbucket_app.py | 11 ++--------- pr_agent/servers/github_app.py | 2 +- pr_agent/servers/gitlab_webhook.py | 2 +- pr_agent/settings/configuration.toml | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/docs/docs/usage-guide/additional_configurations.md b/docs/docs/usage-guide/additional_configurations.md index c345e0c6..eb46bbaa 100644 --- a/docs/docs/usage-guide/additional_configurations.md +++ b/docs/docs/usage-guide/additional_configurations.md @@ -164,6 +164,7 @@ Qodo Merge allows you to automatically ignore certain PRs based on various crite - PRs with specific titles (using regex matching) - PRs between specific branches (using regex matching) +- PRs from specific repositories (using regex matching) - PRs not from specific folders - PRs containing specific labels - PRs opened by specific users @@ -172,7 +173,7 @@ Qodo Merge allows you to automatically ignore certain PRs based on various crite To ignore PRs with a specific title such as "[Bump]: ...", you can add the following to your `configuration.toml` file: -``` +```toml [config] ignore_pr_title = ["\\[Bump\\]"] ``` @@ -183,7 +184,7 @@ Where the `ignore_pr_title` is a list of regex patterns to match the PR title yo To ignore PRs from specific source or target branches, you can add the following to your `configuration.toml` file: -``` +```toml [config] ignore_pr_source_branches = ['develop', 'main', 'master', 'stage'] ignore_pr_target_branches = ["qa"] @@ -192,6 +193,18 @@ ignore_pr_target_branches = ["qa"] Where the `ignore_pr_source_branches` and `ignore_pr_target_branches` are lists of regex patterns to match the source and target branches you want to ignore. They are not mutually exclusive, you can use them together or separately. +### Ignoring PRs from specific repositories + +To ignore PRs from specific repositories, you can add the following to your `configuration.toml` file: + +```toml +[config] +ignore_repositories = ["my-org/my-repo1", "my-org/my-repo2"] +``` + +Where the `ignore_repositories` is a list of regex patterns to match the repositories you want to ignore. This is useful when you have multiple repositories and want to exclude certain ones from analysis. + + ### Ignoring PRs not from specific folders To allow only specific folders (often needed in large monorepos), set: diff --git a/pr_agent/servers/bitbucket_app.py b/pr_agent/servers/bitbucket_app.py index 56921328..c55a335e 100644 --- a/pr_agent/servers/bitbucket_app.py +++ b/pr_agent/servers/bitbucket_app.py @@ -129,12 +129,10 @@ def should_process_pr_logic(data) -> bool: sender = _get_username(data) repo_full_name = pr_data.get("destination", {}).get("repository", {}).get("full_name", "") - print(f"DEBUG: repo_full_name={repo_full_name}, ignore_repos={get_settings().get('CONFIG.IGNORE_REPOSITORIES', [])}") # logic to ignore PRs from specific repositories ignore_repos = get_settings().get("CONFIG.IGNORE_REPOSITORIES", []) - if ignore_repos and repo_full_name: - if repo_full_name in ignore_repos: - print(f"DEBUG: Ignoring due to repo match: {repo_full_name}") + if repo_full_name and ignore_repos: + if any(re.search(regex, repo_full_name) for regex in ignore_repos): get_logger().info(f"Ignoring PR from repository '{repo_full_name}' due to 'config.ignore_repositories' setting") return False @@ -142,7 +140,6 @@ def should_process_pr_logic(data) -> bool: ignore_pr_users = get_settings().get("CONFIG.IGNORE_PR_AUTHORS", []) if ignore_pr_users and sender: if sender in ignore_pr_users: - print(f"DEBUG: Ignoring due to user match: {sender}") get_logger().info(f"Ignoring PR from user '{sender}' due to 'config.ignore_pr_authors' setting") return False @@ -152,7 +149,6 @@ def should_process_pr_logic(data) -> bool: if not isinstance(ignore_pr_title_re, list): ignore_pr_title_re = [ignore_pr_title_re] if ignore_pr_title_re and any(re.search(regex, title) for regex in ignore_pr_title_re): - print(f"DEBUG: Ignoring due to title match: {title}") get_logger().info(f"Ignoring PR with title '{title}' due to config.ignore_pr_title setting") return False @@ -160,17 +156,14 @@ def should_process_pr_logic(data) -> bool: ignore_pr_target_branches = get_settings().get("CONFIG.IGNORE_PR_TARGET_BRANCHES", []) if (ignore_pr_source_branches or ignore_pr_target_branches): if any(re.search(regex, source_branch) for regex in ignore_pr_source_branches): - print(f"DEBUG: Ignoring due to source branch match: {source_branch}") get_logger().info( f"Ignoring PR with source branch '{source_branch}' due to config.ignore_pr_source_branches settings") return False if any(re.search(regex, target_branch) for regex in ignore_pr_target_branches): - print(f"DEBUG: Ignoring due to target branch match: {target_branch}") get_logger().info( f"Ignoring PR with target branch '{target_branch}' due to config.ignore_pr_target_branches settings") return False except Exception as e: - print(f"DEBUG: Exception in should_process_pr_logic: {e}") get_logger().error(f"Failed 'should_process_pr_logic': {e}") print("DEBUG: Returning True from should_process_pr_logic") return True diff --git a/pr_agent/servers/github_app.py b/pr_agent/servers/github_app.py index 6354b2b9..36db3c69 100644 --- a/pr_agent/servers/github_app.py +++ b/pr_agent/servers/github_app.py @@ -263,7 +263,7 @@ def should_process_pr_logic(body) -> bool: # logic to ignore PRs from specific repositories ignore_repos = get_settings().get("CONFIG.IGNORE_REPOSITORIES", []) if ignore_repos and repo_full_name: - if repo_full_name in ignore_repos: + if any(re.search(regex, repo_full_name) for regex in ignore_repos): get_logger().info(f"Ignoring PR from repository '{repo_full_name}' due to 'config.ignore_repositories' setting") return False diff --git a/pr_agent/servers/gitlab_webhook.py b/pr_agent/servers/gitlab_webhook.py index 7d178702..9036f15d 100644 --- a/pr_agent/servers/gitlab_webhook.py +++ b/pr_agent/servers/gitlab_webhook.py @@ -108,7 +108,7 @@ def should_process_pr_logic(data) -> bool: # logic to ignore PRs from specific repositories ignore_repos = get_settings().get("CONFIG.IGNORE_REPOSITORIES", []) if ignore_repos and repo_full_name: - if repo_full_name in ignore_repos: + if any(re.search(regex, repo_full_name) for regex in ignore_repos): get_logger().info(f"Ignoring MR from repository '{repo_full_name}' due to 'config.ignore_repositories' setting") return False diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index cd7ebd16..ce097c95 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -55,7 +55,7 @@ ignore_pr_target_branches = [] # a list of regular expressions of target branche ignore_pr_source_branches = [] # a list of regular expressions of source branches to ignore from PR agent when an PR is created ignore_pr_labels = [] # labels to ignore from PR agent when an PR is created ignore_pr_authors = [] # authors to ignore from PR agent when an PR is created -ignore_repositories = [] # list of repository full names (e.g. "org/repo") to ignore from PR agent processing +ignore_repositories = [] # a list of regular expressions of repository full names (e.g. "org/repo") to ignore from PR agent processing # is_auto_command = false # will be auto-set to true if the command is triggered by an automation enable_ai_metadata = false # will enable adding ai metadata