-
Notifications
You must be signed in to change notification settings - Fork 537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: set review data to github actions output #853
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
75c4bef
feat: set review data to github actions output
idubnori 45176ab
test: add config not set case
idubnori 3412095
chore: change default to true, if use in github actions
idubnori 97dcb34
clean: rename to github_action_output
idubnori ae633b3
refine: github_action_output
idubnori 5e5ead9
test: rename & add error case
idubnori aef1c6e
docs: add feature spec and config
idubnori 9e4ffd8
Merge branch 'main' into feature/gha-outputs-1
idubnori File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import os | ||
import json | ||
from pr_agent.algo.utils import get_settings, github_output | ||
|
||
class TestGitHubOutput: | ||
def test_github_output_enabled(self, monkeypatch, tmp_path): | ||
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_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_output_disabled(self, monkeypatch, tmp_path): | ||
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_output(output_data, key_name) | ||
|
||
assert not os.path.exists(str(tmp_path / 'output')) | ||
|
||
def test_github_output_notset(self, monkeypatch, tmp_path): | ||
monkeypatch.setenv('GITHUB_OUTPUT', str(tmp_path / 'output')) | ||
output_data = {'key1': {'value1': 1, 'value2': 2}} | ||
key_name = 'key1' | ||
|
||
github_output(output_data, key_name) | ||
|
||
assert not os.path.exists(str(tmp_path / 'output')) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(1)
change name to 'github_action_output'
it can be confusing to call it as a generic 'github_output' name
(2) wrap everything with try-except.
see also PR-Agent feedback:
"
Environment Variable Dependency: The feature relies on the GITHUB_OUTPUT environment variable being set.
"
Will it always be set ?
(3)
change
" if get_settings().github_action_config.enable_output is False:
return"
to getter only:
if get_settings().get("github_action_config.enable_output", False)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mrT23 Thank you for your reivewing.
I think
GITHUB_OUTPUT
env is always available on github actions runner. Refined the output implementation based on most using codebases. (ref.1 / ref.2)Note that this feature is implicitly disabled in the configuration if use in other than github actions. so, I think no side-effect.