Skip to content

Commit b7c6a5c

Browse files
committed
chore: address further agent comments
1 parent 1644bd5 commit b7c6a5c

4 files changed

Lines changed: 27 additions & 15 deletions

File tree

pr_agent/git_providers/gitea_provider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def publish_persistent_comment(self, pr_comment: str,
241241
def publish_comment(self, comment: str,is_temporary: bool = False) -> None:
242242
"""Publish a comment to the pull request"""
243243
if is_temporary and not get_settings().config.publish_output_progress:
244-
get_logger().debug(f"Skipping publish_comment for temporary comment")
244+
get_logger().debug("Skipping publish_comment for temporary comment")
245245
return None
246246

247247
if self.enabled_issue:
@@ -753,12 +753,12 @@ def get_repo_file_content(self, file_path: str) -> str:
753753
"""
754754
try:
755755
if not self.owner or not self.repo:
756-
self.logger.warning(f"Cannot get repo file content: owner or repo not set")
756+
self.logger.warning("Cannot get repo file content: owner or repo not set")
757757
return ""
758758

759759
ref = self.base_sha or self.base_ref or self.sha
760760
if not ref:
761-
self.logger.warning(f"Cannot get repo file content: ref not set")
761+
self.logger.warning("Cannot get repo file content: ref not set")
762762
return ""
763763

764764
content = self.repo_api.get_file_content(

pr_agent/git_providers/utils.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,11 @@ def apply_repo_settings(pr_url):
287287
os.close(fd)
288288

289289
try:
290-
dynconf_kwargs = {'core_loaders': [], # DISABLE default loaders, otherwise will load toml files more than once.
290+
dynconf_kwargs = {'core_loaders': [],
291+
# Disable default loaders, otherwise TOML files load more than once.
291292
'loaders': ['pr_agent.custom_merge_loader'],
292-
# Use a custom loader to merge sections, but overwrite their overlapping values. Don't involve ENV variables.
293-
'merge_enabled': True # Merge multiple files; ensures [XYZ] sections only overwrite overlapping keys, not whole sections.
293+
# Merge sections and overwrite overlapping values without involving environment variables.
294+
'merge_enabled': True
294295
}
295296

296297
new_settings = Dynaconf(settings_files=repo_settings_files,
@@ -364,13 +365,21 @@ def handle_configurations_errors(config_errors, git_provider):
364365
err_message = err['error']
365366
config_type = err['category']
366367
header = f"❌ **PR-Agent failed to apply '{config_type}' repo settings**"
367-
body = f"{header}\n\nThe configuration file needs to be a valid [TOML](https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/), please fix it.\n\n"
368+
body = (
369+
f"{header}\n\nThe configuration file needs to be a valid "
370+
"[TOML](https://qodo-merge-docs.qodo.ai/usage-guide/configuration_options/), please fix it.\n\n"
371+
)
368372
body += f"___\n\n**Error message:**\n`{err_message}`\n\n"
369-
if git_provider.is_supported("gfm_markdown"):
370-
body += f"\n\n<details><summary>Configuration content:</summary>\n\n```toml\n{configuration_file_content}\n```\n\n</details>"
373+
if config_type == "global":
374+
body += "\n\nThe invalid configuration came from the organization's global settings file."
375+
elif git_provider.is_supported("gfm_markdown"):
376+
body += (
377+
"\n\n<details><summary>Configuration content:</summary>\n\n"
378+
f"```toml\n{configuration_file_content}\n```\n\n</details>"
379+
)
371380
else:
372381
body += f"\n\n**Configuration content:**\n\n```toml\n{configuration_file_content}\n```\n\n"
373-
get_logger().warning(f"Sending a 'configuration error' comment to the PR", artifact={'body': body})
382+
get_logger().warning("Sending a 'configuration error' comment to the PR", artifact={'body': body})
374383
# git_provider.publish_comment(body)
375384
if hasattr(git_provider, 'publish_persistent_comment'):
376385
git_provider.publish_persistent_comment(body,
@@ -380,7 +389,7 @@ def handle_configurations_errors(config_errors, git_provider):
380389
else:
381390
git_provider.publish_comment(body)
382391
except Exception as e:
383-
get_logger().exception(f"Failed to handle configurations errors", e)
392+
get_logger().exception("Failed to handle configurations errors", e)
384393

385394

386395
def set_claude_model():

tests/unittest/test_git_provider_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def test_apply_repo_settings_merges_global_before_local_settings(monkeypatch):
4848
original_extra_instructions = settings.pr_reviewer.extra_instructions
4949
original_enable_intro_text = settings.pr_reviewer.enable_intro_text
5050
monkeypatch.setattr(utils, "get_git_provider_with_context", lambda pr_url: FakeSettingsProvider())
51+
monkeypatch.delenv("AUTO_CAST_FOR_DYNACONF", raising=False)
5152

5253
try:
5354
apply_repo_settings("https://github.example.com/org/service/pull/1")
@@ -129,7 +130,7 @@ def test_handle_configurations_errors_publishes_each_error():
129130
"category": "local",
130131
},
131132
{
132-
"settings": b"[pr_reviewer]\nnum_max_findings =",
133+
"settings": b"[github]\nuser_token = \"secret-token\"\n[pr_reviewer]\nnum_max_findings =",
133134
"error": "Second error",
134135
"category": "global",
135136
},
@@ -139,7 +140,9 @@ def test_handle_configurations_errors_publishes_each_error():
139140
assert "First error" in provider.comments[0]
140141
assert "[config]\nmodel =" in provider.comments[0]
141142
assert "Second error" in provider.comments[1]
142-
assert "[pr_reviewer]\nnum_max_findings =" in provider.comments[1]
143+
assert "organization's global settings file" in provider.comments[1]
144+
assert "secret-token" not in provider.comments[1]
145+
assert "num_max_findings" not in provider.comments[1]
143146

144147

145148
def test_handle_configurations_errors_ignores_empty_sentinel_entry():

tests/unittest/test_repo_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def test_build_repo_context_refreshes_process_cache_after_ttl(repo_context_setti
112112
first_provider = FakeProvider({"AGENTS.md": "Repo purpose"}, pr_url="https://example.com/org/repo/pull/1")
113113
second_provider = FakeProvider({"AGENTS.md": "Changed repo purpose"}, pr_url="https://example.com/org/repo/pull/1")
114114

115-
with patch("pr_agent.algo.repo_context.time.monotonic", side_effect=[100, 100, 2000, 2000, 2000]):
115+
with patch("pr_agent.algo.repo_context.time.monotonic", side_effect=[100, 100, 2000, 2000, 2000, 2000]):
116116
first_context = build_repo_context(first_provider)
117117
second_context = build_repo_context(second_provider)
118118

@@ -128,7 +128,7 @@ def test_build_repo_context_refreshes_empty_process_cache_after_ttl(repo_context
128128
first_provider = FakeProvider({}, pr_url="https://example.com/org/repo/pull/1")
129129
second_provider = FakeProvider({"AGENTS.md": "Repo purpose"}, pr_url="https://example.com/org/repo/pull/1")
130130

131-
with patch("pr_agent.algo.repo_context.time.monotonic", side_effect=[100, 100, 2000, 2000, 2000]):
131+
with patch("pr_agent.algo.repo_context.time.monotonic", side_effect=[100, 100, 2000, 2000, 2000, 2000]):
132132
first_context = build_repo_context(first_provider)
133133
second_context = build_repo_context(second_provider)
134134

0 commit comments

Comments
 (0)