Skip to content
18 changes: 13 additions & 5 deletions pr_agent/agent/pr_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ def __init__(self, ai_handler: partial[BaseAiHandler,] = LiteLLMAIHandler):
self.ai_handler = ai_handler # will be initialized in run_action

async def _handle_request(self, pr_url, request, notify=None) -> bool:
# First, apply repo specific settings if exists
apply_repo_settings(pr_url)

# Then, apply user specific settings if exists
if isinstance(request, str):
request = request.replace("'", "\\'")
lexer = shlex.shlex(request, posix=True)
Expand All @@ -73,9 +69,21 @@ async def _handle_request(self, pr_url, request, notify=None) -> bool:
)
return False

# Update settings from args
# Extract CLI --key=value overrides so they can be applied before
# apply_repo_settings (needed for --config.git_provider=gitlab etc.)
# and re-applied afterward to maintain CLI > repo precedence.
cli_key_values = [a for a in args if a.startswith('--') and '=' in a]

# Apply CLI overrides before repo settings, so provider creation
# (e.g. --config.git_provider=gitlab) can see them.
args = update_settings_from_args(args)

# First, apply repo specific settings if exists
apply_repo_settings(pr_url)

# Re-apply CLI overrides so they take precedence over repo .pr_agent.toml
update_settings_from_args(cli_key_values)

# Append the response language in the extra instructions
response_language = get_settings().config.get('response_language', 'en-us')
if response_language.lower() != 'en-us':
Expand Down
32 changes: 31 additions & 1 deletion pr_agent/algo/cli_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,37 @@ def validate_user_args(args: list) -> (bool, str):

# decode forbidden args
# b64encode('word'.encode()).decode()
_encoded_args = 'c2hhcmVkX3NlY3JldA==:dXNlcg==:c3lzdGVt:ZW5hYmxlX2NvbW1lbnRfYXBwcm92YWw=:ZW5hYmxlX21hbnVhbF9hcHByb3ZhbA==:ZW5hYmxlX2F1dG9fYXBwcm92YWw=:YXBwcm92ZV9wcl9vbl9zZWxmX3Jldmlldw==:YmFzZV91cmw=:dXJs:YXBwX25hbWU=:c2VjcmV0X3Byb3ZpZGVy:Z2l0X3Byb3ZpZGVy:c2tpcF9rZXlz:b3BlbmFpLmtleQ==:QU5BTFlUSUNTX0ZPTERFUg==:dXJp:YXBwX2lk:d2ViaG9va19zZWNyZXQ=:YmVhcmVyX3Rva2Vu:UEVSU09OQUxfQUNDRVNTX1RPS0VO:b3ZlcnJpZGVfZGVwbG95bWVudF90eXBl:cHJpdmF0ZV9rZXk=:bG9jYWxfY2FjaGVfcGF0aA==:ZW5hYmxlX2xvY2FsX2NhY2hl:amlyYV9iYXNlX3VybA==:YXBpX2Jhc2U=:YXBpX3R5cGU=:YXBpX3ZlcnNpb24=:c2tpcF9rZXlz'
_encoded_parts = [
'c2hhcmVkX3NlY3JldA==', # shared_secret
'dXNlcg==', # user
'c3lzdGVt', # system
'ZW5hYmxlX2NvbW1lbnRfYXBwcm92YWw=', # enable_comment_approval
'ZW5hYmxlX21hbnVhbF9hcHByb3ZhbA==', # enable_manual_approval
'ZW5hYmxlX2F1dG9fYXBwcm92YWw=', # enable_auto_approval
'YXBwcm92ZV9wcl9vbl9zZWxmX3Jldmlldw==', # approve_pr_on_self_review
'YmFzZV91cmw=', # base_url
'dXJs', # url
'YXBwX25hbWU=', # app_name
'c2VjcmV0X3Byb3ZpZGVy', # secret_provider
'c2tpcF9rZXlz', # skip_keys
'b3BlbmFpLmtleQ==', # openai.key
'QU5BTFlUSUNTX0ZPTERFUg==', # ANALYTICS_FOLDER
'dXJp', # uri
'YXBwX2lk', # app_id
'd2ViaG9va19zZWNyZXQ=', # webhook_secret
'YmVhcmVyX3Rva2Vu', # bearer_token
'UEVSU09OQUxfQUNDRVNTX1RPS0VO', # PERSONAL_ACCESS_TOKEN
'b3ZlcnJpZGVfZGVwbG95bWVudF90eXBl', # override_deployment_type
'cHJpdmF0ZV9rZXk=', # private_key
'bG9jYWxfY2FjaGVfcGF0aA==', # local_cache_path
'ZW5hYmxlX2xvY2FsX2NhY2hl', # enable_local_cache
'amlyYV9iYXNlX3VybA==', # jira_base_url
'YXBpX2Jhc2U=', # api_base
'YXBpX3R5cGU=', # api_type
'YXBpX3ZlcnNpb24=', # api_version
'c2tpcF9rZXlz', # skip_keys
]
_encoded_args = ':'.join(_encoded_parts)

forbidden_cli_args = []
for e in _encoded_args.split(':'):
Expand Down
2 changes: 1 addition & 1 deletion pr_agent/git_providers/gitlab_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ def publish_code_suggestions(self, code_suggestions: list) -> bool:
if target_file is None:
get_logger().warning(f"Skipping suggestion: file '{relevant_file}' not found in diff")
continue
range = relevant_lines_end - relevant_lines_start # no need to add 1
range = relevant_lines_end - relevant_lines_start + 1
body = body.replace('```suggestion', f'```suggestion:-0+{range}')
lines = target_file.head_file.splitlines()
relevant_line_in_file = lines[relevant_lines_start - 1]
Expand Down
3 changes: 2 additions & 1 deletion pr_agent/tools/pr_code_suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ async def run(self):

# Publish table summarized suggestions
if ((not get_settings().pr_code_suggestions.commitable_code_suggestions) and
self.git_provider.is_supported("gfm_markdown")):
self.git_provider.is_supported("gfm_markdown") and
self.git_provider.is_supported("publish_inline_comments")):
Comment thread
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
Comment thread
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.

# generate summarized suggestions
pr_body = self.generate_summarized_suggestions(data)
Expand Down
Loading