diff --git a/docs/docs/usage-guide/additional_configurations.md b/docs/docs/usage-guide/additional_configurations.md index 2adfa360..cf32d08f 100644 --- a/docs/docs/usage-guide/additional_configurations.md +++ b/docs/docs/usage-guide/additional_configurations.md @@ -112,3 +112,36 @@ LANGSMITH_API_KEY= LANGSMITH_PROJECT= LANGSMITH_BASE_URL= ``` + +## Ignoring automatic commands in PRs + +In some cases, you may want to ignore automatic commands in PRs. For example you may want to ignore MR with a specific title, or labels or from/to specific branches. + +For example, to ignore MRs with a specific title such as "[AUTO]: foobar", you can add the following to your `configuration.toml` file: + +``` +[config] +ignore_mr_title = ["\\[AUTO\\]"] +``` + +Where the `ignore_mr_title` is a list of regex patterns to match the MR title you want to ignore. + +To ignore MRs with specific labels, you can add the following to your `configuration.toml` file: + +``` +[config] +ignore_mr_labels = ["auto"] +``` + +Where the `ignore_mr_labels` is a list of labels you want to ignore. + +To ignore MRs from specific branches, you can add the following to your `configuration.toml` file: + +``` +[config] +ignore_mr_source_branches = ['develop', 'main', 'master', 'stage'] +ignore_mr_target_branches = ["qa"] +``` + +Where the `ignore_mr_source_branches` and `ignore_mr_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. diff --git a/pr_agent/servers/github_app.py b/pr_agent/servers/github_app.py index 9a8784fd..f9f179b8 100644 --- a/pr_agent/servers/github_app.py +++ b/pr_agent/servers/github_app.py @@ -138,7 +138,7 @@ async def handle_new_pr_opened(body: Dict[str, Any], if action in get_settings().github_app.handle_pr_actions: # ['opened', 'reopened', 'ready_for_review'] # logic to ignore PRs with specific titles (e.g. "[Auto] ...") apply_repo_settings(api_url) - ignore_pr_title_re = get_settings().get("GITHUB_APP.IGNORE_PR_TITLE", []) + ignore_pr_title_re = get_settings().get("CONFIG.IGNORE_PR_TITLE", []) if not isinstance(ignore_pr_title_re, list): ignore_pr_title_re = [ignore_pr_title_re] @@ -147,9 +147,9 @@ async def handle_new_pr_opened(body: Dict[str, Any], return {} # logic to ignore PRs with specific labels or source branches or target branches. - ignore_pr_labels = get_settings().get("GITHUB_APP.IGNORE_PR_LABELS", []) - ignore_pr_source_branches = get_settings().get("GITHUB_APP.IGNORE_PR_SOURCE_BRANCHES", []) - ignore_pr_target_branches = get_settings().get("GITHUB_APP.IGNORE_PR_TARGET_BRANCHES", []) + ignore_pr_labels = get_settings().get("CONFIG.IGNORE_PR_LABELS", []) + ignore_pr_source_branches = get_settings().get("CONFIG.IGNORE_PR_SOURCE_BRANCHES", []) + ignore_pr_target_branches = get_settings().get("CONFIG.IGNORE_PR_TARGET_BRANCHES", []) if ignore_pr_labels: labels = [label['name'] for label in pull_request.get("labels", [])] diff --git a/pr_agent/servers/gitlab_webhook.py b/pr_agent/servers/gitlab_webhook.py index aee3732d..d51fa387 100644 --- a/pr_agent/servers/gitlab_webhook.py +++ b/pr_agent/servers/gitlab_webhook.py @@ -139,10 +139,10 @@ async def gitlab_webhook(background_tasks: BackgroundTasks, request: Request): return JSONResponse(status_code=status.HTTP_200_OK, content=jsonable_encoder({"message": "success"})) # logic to ignore MRs for titles, labels and source, target branches. - ignore_mr_title = get_settings().get("GITLAB.IGNORE_MR_TITLE", []) - ignore_mr_labels = get_settings().get("GITLAB.IGNORE_MR_LABELS", []) - ignore_mr_source_branches = get_settings().get("GITLAB.IGNORE_MR_SOURCE_BRANCHES", []) - ignore_mr_target_branches = get_settings().get("GITLAB.IGNORE_MR_TARGET_BRANCHES", []) + ignore_mr_title = get_settings().get("CONFIG.IGNORE_PR_TITLE", []) + ignore_mr_labels = get_settings().get("CONFIG.IGNORE_PR_LABELS", []) + ignore_mr_source_branches = get_settings().get("CONFIG.IGNORE_PR_SOURCE_BRANCHES", []) + ignore_mr_target_branches = get_settings().get("CONFIG.IGNORE_PR_TARGET_BRANCHES", []) if ignore_mr_source_branches: source_branch = data['object_attributes'].get('source_branch') if any(re.search(regex, source_branch) for regex in ignore_mr_source_branches): diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index e6d5968a..1fc8e0c0 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -36,6 +36,15 @@ is_auto_command=false seed=-1 # set positive value to fix the seed (and ensure temperature=0) temperature=0.2 +# a list of regular expressions to match against the PR title to ignore the PR agent +ignore_pr_title = [] +# a list of regular expressions of target branches to ignore from PR agent when an MR is created +ignore_pr_target_branches = [] +# a list of regular expressions of source branches to ignore from PR agent when an MR is created +ignore_pr_source_branches = [] +# labels to ignore from PR agent when an MR is created +ignore_pr_labels = [] + [pr_reviewer] # /review # # enable/disable features require_score_review=false @@ -187,6 +196,7 @@ base_url = "https://api.github.com" publish_inline_comments_fallback_with_verification = true try_fix_invalid_inline_comments = true app_name = "pr-agent" +ignore_bot_pr = true [github_action_config] # auto_review = true # set as env var in .github/workflows/pr-agent.yaml @@ -215,16 +225,6 @@ push_commands = [ "/describe", "/review --pr_reviewer.num_code_suggestions=0", ] -# a list of regular expressions to match against the PR title to ignore the PR agent -ignore_pr_title = [] -# a list of regular expressions of target branches to ignore from PR agent when an MR is created -ignore_pr_target_branches = [] -# a list of regular expressions of source branches to ignore from PR agent when an MR is created -ignore_pr_source_branches = [] -# labels to ignore from PR agent when an MR is created -ignore_pr_labels = [] -# MR titles to ignore from PR agent when an MR is created -ignore_bot_pr = true [gitlab] url = "https://gitlab.com"