Skip to content

Merge CLI scripts - #4

Merged
okotek merged 2 commits into
mainfrom
feature/merge_cli
Jul 6, 2023
Merged

okotek merged 2 commits into
mainfrom
feature/merge_cli

Conversation

@okotek

@okotek okotek commented Jul 6, 2023 •

Copy link
Copy Markdown
Contributor

No description provided.

@okotek
okotek merged commit 0ebd29d into main Jul 6, 2023
@okotek
okotek deleted the feature/merge_cli branch July 6, 2023 08:52
@okotek
okotek restored the feature/merge_cli branch January 7, 2024 11:50
yochail pushed a commit to yochail/pr-agent that referenced this pull request Feb 11, 2024
@mrT23

mrT23 commented Aug 25, 2024 •

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Score
Error handling
Use a more specific exception type when checking for configuration errors

Consider using a more specific exception type instead of AttributeError when
checking for the OpenAI key. This will make it easier to distinguish between
different types of configuration errors.

pr_agent/algo/ai_handler.py [13-18]

 try:
     openai.api_key = settings.openai.key
     if settings.get("OPENAI.ORG", None):
         openai.organization = settings.openai.org
-except AttributeError as e:
+except KeyError as e:
     raise ValueError("OpenAI key is required") from e
 
  • Apply this suggestion
Suggestion importance[1-10]: 7

Why: Using KeyError instead of AttributeError is more specific and appropriate for catching missing dictionary keys, improving error handling precision.

7
Documentation
Add a more descriptive comment for a configuration option

Consider adding a comment to explain the purpose and format of the OpenAI
organization ID, similar to the comment for the API key.

pr_agent/settings/.secrets_template.toml [10-11]

 key = "<API_KEY>"  # Acquire through https://platform.openai.com
-org = "<ORGANIZATION>"  # Optional, may be commented out.
+org = "<ORGANIZATION>"  # Optional, organization ID from OpenAI dashboard. May be commented out if not needed.
 
  • Apply this suggestion
Suggestion importance[1-10]: 6

Why: Adding a more detailed comment for the 'org' field improves documentation and clarity for users setting up the configuration.

6
Enhancement
Add a default value for an optional command-line argument

Consider adding a default value for the --question argument to simplify the
command-line interface and improve user experience.

pr_agent/cli.py [13]

-parser.add_argument('--question', type=str, help='Optional question to ask', required=False)
+parser.add_argument('--question', type=str, help='Optional question to ask', default=None)
 
  • Apply this suggestion
Suggestion importance[1-10]: 5

Why: Adding a default value of None simplifies the CLI usage, but the current implementation with required=False is also valid and clear.

5
Best practice
Use a context manager for setting up logging configuration

Consider using a context manager for setting up logging to ensure proper cleanup and
consistent behavior across different execution environments.

pr_agent/cli.py [15]

-logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
+import contextlib
 
+with contextlib.suppress(Exception):
+    logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))
+
  • Apply this suggestion
Suggestion importance[1-10]: 3

Why: While using a context manager can be beneficial, the suggested implementation with suppress() might silently ignore important errors. The current simple approach is adequate for most cases.

3

mrT23 pushed a commit that referenced this pull request May 25, 2025
feat: add add_diagram configuration option to PR description
mrT23 pushed a commit that referenced this pull request Jun 18, 2025
…-count-for-todo-section

todo section의 내용이 10줄 이하이면 기본적으로 펼쳐져 있도록 수정
agonzalesipcoop-cmyk pushed a commit to agonzalesipcoop-cmyk/pr-agent that referenced this pull request May 8, 2026
…view

- Extract loader into pr_agent/algo/best_practices.py and reuse it from
  /improve and /review so OSS behavior is symmetric (closes Qodo The-PR-Agent#1).
- Guard int(max_lines_allowed) with TypeError/ValueError fallback to 800
  plus a targeted warning (Qodo The-PR-Agent#2).
- Bitbucket get_pr_agent_repo_custom_file: only accept HTTP 200, log
  non-404 failures, add 10s timeout, and use the repo default branch
  via get_repo_default_branch (Qodo The-PR-Agent#3, The-PR-Agent#5, The-PR-Agent#6).
- LocalGitProvider get_pr_agent_repo_custom_file: resolve and verify the
  candidate path stays inside the repo root before reading (Qodo The-PR-Agent#7).
- Soften prompt wording in code-suggestions templates and add a parallel
  block in pr_reviewer_prompts.toml so the model treats the section as
  guidance, ignoring obvious non-guideline content.
- Drop unused _FakeContext test helper, retarget patches to the new
  module, add coverage for the invalid max_lines fallback (Qodo The-PR-Agent#4).
- Update docs/improve.md and docs/review.md to reflect that both tools
  now consume best_practices.md in OSS.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@dellch dellch mentioned this pull request Jun 2, 2026
3 tasks done
Oxygen56 added a commit to Oxygen56/pr-agent that referenced this pull request Jun 8, 2026
- Use compiled Asana patterns (_ASANA_TASK_URL_PATTERN,
  _ASANA_TASK_SHORT_PATTERN) in find_asana_tickets() instead of
  inline regex (CodeQL unused-variable, comments The-PR-Agent#5/The-PR-Agent#6).
- Add re.IGNORECASE flag to _ASANA_TASK_SHORT_PATTERN for proper
  case-insensitive matching.
- Replace substring match ('app.asana.com' in ticket) with
  prefix check (ticket.startswith()) to fix CodeQL URL
  sanitization warning (comment The-PR-Agent#4).
- Reserve at least one slot for Asana tickets during
  truncation when there are 3+ GitHub/branch tickets
  (comment The-PR-Agent#8).
- Dedent only actual leading whitespace instead of blindly
  slicing dline[remove_count:] to avoid deleting real code
  on lines with less indentation (comments The-PR-Agent#3/The-PR-Agent#9).
- Remove unused 'import pytest' from test file
  (comments The-PR-Agent#10/The-PR-Agent#20).
- Add test_shorthand_mixed_case_asana and
  test_shorthand_respects_word_boundary test cases.
Oxygen56 added a commit to Oxygen56/pr-agent that referenced this pull request Jun 8, 2026
- Use compiled Asana patterns (_ASANA_TASK_URL_PATTERN,
  _ASANA_TASK_SHORT_PATTERN) in find_asana_tickets() instead of
  inline regex (CodeQL unused-variable, comments The-PR-Agent#5/The-PR-Agent#6).
- Add re.IGNORECASE flag to _ASANA_TASK_SHORT_PATTERN for proper
  case-insensitive matching.
- Replace substring match ('app.asana.com' in ticket) with
  prefix check (ticket.startswith()) to fix CodeQL URL
  sanitization warning (comment The-PR-Agent#4).
- Reserve at least one slot for Asana tickets during
  truncation when there are 3+ GitHub/branch tickets
  (comment The-PR-Agent#8).
- Dedent only actual leading whitespace instead of blindly
  slicing dline[remove_count:] to avoid deleting real code
  on lines with less indentation (comments The-PR-Agent#3/The-PR-Agent#9).
- Remove unused 'import pytest' from test file
  (comments The-PR-Agent#10/The-PR-Agent#20).
- Add test_shorthand_mixed_case_asana and
  test_shorthand_respects_word_boundary test cases.
ashearin added a commit to ashearin/pr-agent that referenced this pull request Jun 29, 2026
…h failures via typed exception

Addresses Qodo review items The-PR-Agent#2, The-PR-Agent#3, The-PR-Agent#4 on PR The-PR-Agent#2483.

The-PR-Agent#2 Hardcoded managed_default label set
- Add is_describe_managed_label() and _describe_managed_label_names() in
  pr_agent.algo.utils as the single source of truth for the
  /describe-managed namespace.
- Rewrite get_user_labels() to defer to the same helper so the inclusion
  and exclusion rules can never drift.

The-PR-Agent#3 Default label not managed (Bug fix with tests)
- When enable_custom_labels=True and no custom_labels are configured,
  set_custom_labels injects defaults that include 'Bug fix with tests'.
  is_describe_managed_label now classifies that label as managed so
  /describe can remove it once it is no longer recommended.
- This also fixes a pre-existing bug in get_user_labels where
  'Bug fix with tests' was misclassified as a user label.

The-PR-Agent#4 Refresh failure misreported
- Add LabelRefreshError in pr_agent.git_providers.git_provider so
  callers can distinguish a refresh failure from a genuine no-op.
- GitProvider.publish_managed_labels (default impl) and
  GitLabProvider.publish_managed_labels now raise LabelRefreshError on
  pre-write refresh failure instead of returning None.
- PRDescription._safe_publish_labels and PRReviewer.set_review_labels
  catch LabelRefreshError specifically and log a warning that names the
  failure, instead of mis-logging it as 'labels unchanged' /
  'already set'.

#1, The-PR-Agent#5, The-PR-Agent#6, The-PR-Agent#7 from Qodo's review are already addressed in earlier
commits on this branch (36ec454, a7a8cad); Qodo's review listing is
pinned to PR-level diff hunks so they appear in the report against
older revisions.

Tests:
- New TestDescribeManagedLabelNamespace locks the predicate behavior:
  default-set always managed, Bug fix with tests managed under the
  custom-labels default-injection path, and is_describe_managed_label /
  get_user_labels stay disjoint.
- TestSafePublishLabels gains test_predicate_includes_bug_fix_with_tests_when_custom_labels_default
  and test_logs_distinctly_on_refresh_failure.
- test_pr_reviewer_core gains test_set_review_labels_logs_distinctly_on_refresh_failure.
- test_publish_managed_labels_aborts_when_refresh_fails replaced with
  test_publish_managed_labels_raises_when_refresh_fails.
- Full unit suite: 1066 passed, 1 skipped, 3 xfailed (was 1060).

Signed-off-by: Allen Shearin <allen.p.shearin@gmail.com>
naorpeled referenced this pull request in utsab345/pr-agent Jul 3, 2026
…in restricted mode

Address Qodo review on The-PR-Agent#2491:

- #4 (skip path drops changelog output): when a changelog push is requested but not
  possible — provider lacks push support, or restricted_mode disables push_code — the
  tool no longer returns early with only an error. It now still generates the changelog
  and publishes it as a comment (which only needs pull-requests: write), with a note that
  the changes were not pushed. commit_changelog is set to False in that case.
- #5 (skip path still initializes): removes the special early-return init path; the normal
  flow builds only what's needed to generate the changelog.
- #6 (contents default note misleading): clarify that unlisted scopes default to none only
  within an explicit permissions: block; without one, defaults follow repo/org settings.

Update the "no push support" test to assert the comment fallback, and add a restricted_mode
test (push API present but is_supported('push_code') False) asserting it comments, not pushes.
naorpeled added a commit that referenced this pull request Jul 3, 2026
* fix: scope ticket cache per-PR and fix Dynaconf list merge leaks in tests

- Cache key is now 'related_tickets_<md5(pr_url)>' instead of global
  'related_tickets', preventing stale tickets leaking between unrelated PRs
- Added cache_tickets=true config flag under [pr_reviewer] to allow disabling
- Fixed Dynaconf merge_enabled=True list append bug in both production code
  (env_bridge.py uses case-insensitive pop before set) and test helpers
  (restore_settings now calls _remove_key before every set)
- Added azure-identity dependency for Azure DevOps provider availability
- 1043 tests pass, 0 failures

* Revert "fix: scope ticket cache per-PR and fix Dynaconf list merge leaks in tests"

This reverts commit 7f0d154.

* feat: add restricted mode for reduced GitHub permissions (#2279)

Add a `config.restricted_mode` option that gates operations requiring
elevated permissions (e.g. pushing code to the repository). When enabled,
`is_supported("push_code")` returns `False` on GitHub, GitLab, and
Bitbucket providers, and `/update_changelog --push_changelog_changes=true`
gracefully skips with a clear message instead of failing.

Users can set `restricted_mode = true` and use only `issues: write`
and `pull-requests: write` permissions, without `contents: write`.

* docs: document restricted_mode for reduced GitHub permissions

* docs: clarify minimal permissions for restricted mode

* fix: move restricted-mode check to __init__ to avoid unnecessary provider reads

PRUpdateChangelog.__init__() was fetching languages, files, and
CHANGELOG.md content before run() checked push_code support.
In restricted mode, these reads were wasted and could fail if
contents access is also restricted.

Move the capability check into __init__() before the expensive
provider calls, and store the result in self._skip_push so
run() can return early.

* fix: remove full-config logging from run() and use mock AI handler in test

- Remove relevant_configs logging that dumps full settings dicts
  (potential secret leak in logs)
- Pass ai_handler mock in test_run_without_push_support to avoid
  instantiating a real LiteLLMAIHandler

* fix: use spec'd mock for push-support test and fix docs permissions note

- Use MagicMock(spec=[...]) in test_run_without_push_support so
  hasattr() correctly returns False for missing attributes instead
  of brittle delattr on bare MagicMock
- Remove misleading 'contents: read (defaults to read)' comment
  from restricted mode docs; contents is simply not needed

* fix: skip __init__ provider reads when _skip_push is set

Move all provider-dependent initialization (vars dict, token handler,
ai_handler binding, language/file/changelog reads) behind the _skip_push
guard so the skip path avoids hitting the git provider at all during
construction.

* fix(update_changelog): degrade to comment instead of dropping output in restricted mode

Address Qodo review on #2491:

- #4 (skip path drops changelog output): when a changelog push is requested but not
  possible — provider lacks push support, or restricted_mode disables push_code — the
  tool no longer returns early with only an error. It now still generates the changelog
  and publishes it as a comment (which only needs pull-requests: write), with a note that
  the changes were not pushed. commit_changelog is set to False in that case.
- #5 (skip path still initializes): removes the special early-return init path; the normal
  flow builds only what's needed to generate the changelog.
- #6 (contents default note misleading): clarify that unlisted scopes default to none only
  within an explicit permissions: block; without one, defaults follow repo/org settings.

Update the "no push support" test to assert the comment fallback, and add a restricted_mode
test (push API present but is_supported('push_code') False) asserting it comments, not pushes.

* fix: generate changelog preview instead of silent skip when push is restricted

When restricted_mode is active and push_changelog_changes=true, the
tool now generates the changelog output via AI and publishes it as a
comment with a '(push restricted by configuration)' label, instead of
returning silently. This ensures users see the changelog even when
they don't have contents: write permissions.

For the 'not supported' case (provider lacks create_or_update_pr_file
entirely), the existing early-return behavior is preserved.

---------

Co-authored-by: Utsab <utsab@pr-agent.dev>
Co-authored-by: naorpeled <me@naor.dev>
@naorpeled
naorpeled deleted the feature/merge_cli branch August 29, 2026 19:59
ira-at-work added a commit to Agrematch/pr-agent that referenced this pull request Sep 28, 2026
…e fix

- Regenerate the config reference so the documented no_temperature_models
  default includes the GLM-5 entries added in the previous commit (the docs
  build guard would otherwise catch this drift, per Qodo finding #1).
- Extend the Kimi K3 completion test to also cover the GLM-5 bare, regional,
  and Converse spellings, since the model list added a second model with no
  matching coverage (Qodo finding #2).
- Reword the test docstring to imperative phrasing (Qodo finding The-PR-Agent#4).

Qodo finding #3 (import order) is a false positive: `ruff check` against this
repo's actual pyproject.toml config passes the original tomllib-then-pathlib
order unchanged (straight imports sort before from-imports within a section
by default); left as-is.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
ira-at-work added a commit to Agrematch/pr-agent that referenced this pull request Sep 28, 2026
…e fix

- Regenerate the config reference so the documented no_temperature_models
  default includes the GLM-5 entries added in the previous commit (the docs
  build guard would otherwise catch this drift, per Qodo finding #1).
- Extend the Kimi K3 completion test to also cover the GLM-5 bare, regional,
  and Converse spellings, since the model list added a second model with no
  matching coverage (Qodo finding #2).
- Reword the test docstring to imperative phrasing (Qodo finding The-PR-Agent#4).

Qodo finding #3 (import order) is a false positive: `ruff check` against this
repo's actual pyproject.toml config passes the original tomllib-then-pathlib
order unchanged (straight imports sort before from-imports within a section
by default); left as-is.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
ira-at-work added a commit to Agrematch/pr-agent that referenced this pull request Sep 28, 2026
…e fix

- Regenerate the config reference so the documented no_temperature_models
  default includes the GLM-5 entries added in the previous commit (the docs
  build guard would otherwise catch this drift, per Qodo finding #1).
- Extend the Kimi K3 completion test to also cover the GLM-5 bare, regional,
  and Converse spellings, since the model list added a second model with no
  matching coverage (Qodo finding #2).
- Reword the test docstring to imperative phrasing (Qodo finding The-PR-Agent#4).

Qodo finding #3 (import order) is a false positive: `ruff check` against this
repo's actual pyproject.toml config passes the original tomllib-then-pathlib
order unchanged (straight imports sort before from-imports within a section
by default); left as-is.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants