Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pr_agent/algo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,10 @@ def validate_and_await_rate_limit(github_token):

def github_action_output(output_data: dict, key_name: str):
try:
if not get_settings().get('github_action_config.enable_output', False):
enable_output = get_settings().get('github_action_config.enable_output', False)
if isinstance(enable_output, str):
enable_output = enable_output.lower().strip() not in ("false", "0", "no", "")
if not enable_output:
return

key_data = output_data.get(key_name, {})
Expand Down
2 changes: 2 additions & 0 deletions pr_agent/servers/github_action_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ async def run_action():
get_settings().set("GITHUB.USER_TOKEN", GITHUB_TOKEN)
get_settings().set("GITHUB.DEPLOYMENT_TYPE", "user")
enable_output = get_setting_or_env("GITHUB_ACTION_CONFIG.ENABLE_OUTPUT", True)
if isinstance(enable_output, str):
enable_output = enable_output.lower().strip() not in ("false", "0", "no", "")
get_settings().set("GITHUB_ACTION_CONFIG.ENABLE_OUTPUT", enable_output)

# Load the event payload
Expand Down
29 changes: 29 additions & 0 deletions tests/unittest/test_github_action_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,35 @@ def test_github_action_output_notset(self, monkeypatch, tmp_path):

assert not os.path.exists(str(tmp_path / 'output'))

def test_github_action_output_disabled_string_false(self, monkeypatch, tmp_path):
"""String 'false' from env vars should be treated as falsy, not truthy."""
get_settings().set('GITHUB_ACTION_CONFIG.ENABLE_OUTPUT', "false")
monkeypatch.setenv('GITHUB_OUTPUT', str(tmp_path / 'output'))
output_data = {'key1': {'value1': 1, 'value2': 2}}
key_name = 'key1'

github_action_output(output_data, key_name)

assert not os.path.exists(str(tmp_path / 'output'))

def test_github_action_output_enabled_string_true(self, monkeypatch, tmp_path):
"""String 'true' from env vars should be treated as truthy."""
get_settings().set('GITHUB_ACTION_CONFIG.ENABLE_OUTPUT', "true")
monkeypatch.setenv('GITHUB_OUTPUT', str(tmp_path / 'output'))
output_data = {'key1': {'value1': 1, 'value2': 2}}
key_name = 'key1'

github_action_output(output_data, key_name)

with open(str(tmp_path / 'output'), 'r') as f:
env_value = f.read()

actual_key = env_value.split('=')[0]
actual_data = json.loads(env_value.split('=')[1])

assert actual_key == key_name
assert actual_data == output_data[key_name]

def test_github_action_output_error_case(self, monkeypatch, tmp_path):
monkeypatch.setenv('GITHUB_OUTPUT', str(tmp_path / 'output'))
output_data = None # invalid data
Expand Down
Loading