You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
authored
feat: add restricted mode for reduced GitHub permissions (#2279) (#2491)
* 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>
Where `ignore_ticket_labels` is a list of label names that should be ignored during ticket analysis.
283
+
284
+
### Restricted Mode
285
+
286
+
When running PR-Agent with limited GitHub/GitLab permissions, set `restricted_mode` to `true` to gracefully skip operations that require elevated access (e.g., pushing changelog changes):
287
+
288
+
```toml
289
+
[config]
290
+
restricted_mode = true
291
+
```
292
+
293
+
With restricted mode, the minimum workflow permissions are:
294
+
295
+
```yaml
296
+
permissions:
297
+
issues: write
298
+
pull-requests: write
299
+
```
300
+
301
+
Within an explicit `permissions:` block, any scope you do not list (such as `contents`) is set to `none`, so you do not need to grant `contents` — restricted mode skips every operation that would require `contents: write`. All tools (`/review`, `/describe`, `/improve`, etc.) continue to work normally with just `pull-requests: write`.
302
+
303
+
> **Note:** this only holds when a `permissions:` block is present (as above). If you omit the `permissions:` block entirely, the effective defaults are governed by your repository/organization GitHub Actions settings and may grant broader access.
Copy file name to clipboardExpand all lines: pr_agent/settings/configuration.toml
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -57,6 +57,7 @@ ignore_pr_authors = [] # authors to ignore from PR agent when an PR is created
57
57
ignore_repositories = [] # a list of regular expressions of repository full names (e.g. "org/repo") to ignore from PR agent processing
58
58
ignore_language_framework = [] # a list of code-generation languages or frameworks (e.g. 'protobuf', 'go_gen') whose auto-generated source files will be excluded from analysis
59
59
#
60
+
restricted_mode = false# when true, skip operations that require elevated permissions (e.g. pushing code to the repository)
60
61
is_auto_command = false# will be auto-set to true if the command is triggered by an automation
61
62
enable_ai_metadata = false# will enable adding ai metadata
0 commit comments