Skip to content
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

Add env value merging feature #4

Merged
merged 7 commits into from
Apr 3, 2024
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/pr-agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
env:
common_instructions: >-
- Please use Japanese in descriptions.
pr_code_suggestions.extra_instructions: >-
- Think about the need for changes or additions to the test code and make suggestions.
- name: PR Agent action step
id: pragent
uses: Codium-ai/pr-agent@main
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ Community version of [PR-Agent Wiki configuration file](https://pr-agent-docs.co
# Why?
- [PR-Agent Wiki configuration file](https://pr-agent-docs.codium.ai/usage-guide/configuration_options/#wiki-configuration-file) feature is currently only available in the paid version ([PR-Agent Pro](https://www.codium.ai/pricing/))
- This Composite Action provides functionality similar to the PR-Agent Wiki Configuration feature as Open Source
- Provides functionality to make it easier to set and manage common `extra_instructions`

# How does it work
Note: current support is `extra_instructions` config only

1. Load `.pr_agent.toml` configuration from Wiki page
1. Add `common_instructions` into each extra_instructions configs
1. Merge `common_instructions` and the env `extra_instructions` with the Wiki config value
1. Set each extra_instructions to environment variables

# How to Use
Expand All @@ -34,6 +35,8 @@ jobs:
env:
common_instructions: >-
- Please use Japanese in descriptions.
pr_code_suggestions.extra_instructions: >-
- Think about the need for changes or additions to the test code and make suggestions.
- name: PR Agent action step
id: pragent
uses: Codium-ai/pr-agent@main
Expand Down
21 changes: 12 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,32 @@ runs:
print(f"Error: {e}")
return {}

def add_common_instructions(parsed_toml):
common_instructions = os.getenv('common_instructions')
def concat_env_value(parsed_toml):
common_instructions = os.getenv('common_instructions', '')
for key in ei_sections:
additional_instructions = (os.getenv(f"{key}.{ei_key}", '').strip() + '\n' + (common_instructions).strip()).strip()
if key in parsed_toml:
if ei_key in parsed_toml[key]:
parsed_toml[key][ei_key] = (parsed_toml[key][ei_key]).strip() + '\n' + (common_instructions).strip()
parsed_toml[key][ei_key] = (parsed_toml[key][ei_key]).strip() + '\n' + additional_instructions
else:
parsed_toml[key][ei_key] = common_instructions
parsed_toml[key][ei_key] = additional_instructions
else:
parsed_toml[key] = {ei_key: common_instructions}
parsed_toml[key] = {ei_key: additional_instructions}

return parsed_toml

def set_to_env(parsed_toml):
github_env = os.getenv('GITHUB_ENV')
with open(github_env, "a") as outputfile:
for key in ei_sections:
print(f"{key}.{ei_key}<<EOF",file=outputfile)
print(f"{parsed_toml[key][ei_key]}",file=outputfile)
print(f"EOF",file=outputfile)
value = parsed_toml.get(key, {}).get(ei_key)
if value not in ('', None):
print(f"{key}.{ei_key}<<EOF", file=outputfile)
print(f"{value}", file=outputfile)
print(f"EOF", file=outputfile)

if __name__ == "__main__":
toml_conf = get_conf()
added_toml_conf = add_common_instructions(toml_conf)
added_toml_conf = concat_env_value(toml_conf)
set_to_env(added_toml_conf)