From ae375c2ff0ef25f609e48531763ee5d3d1ddc1a0 Mon Sep 17 00:00:00 2001 From: mrT23 Date: Sun, 29 Oct 2023 13:01:55 +0200 Subject: [PATCH] final fixes --- Usage.md | 20 +++++++++------ pr_agent/servers/github_action_runner.py | 32 ------------------------ 2 files changed, 13 insertions(+), 39 deletions(-) diff --git a/Usage.md b/Usage.md index fc5d7b3b..60991e0d 100644 --- a/Usage.md +++ b/Usage.md @@ -159,21 +159,27 @@ user=""" Note that the new prompt will need to generate an output compatible with the relevant [post-process function](./pr_agent/tools/pr_description.py#L137). ### Working with GitHub Action -You can configure settings in GitHub action by adding environment variables under the env section in `.github/workflows/pr_agent.yml` file. Some examples: +You can configure settings in GitHub action by adding environment variables under the env section in `.github/workflows/pr_agent.yml` file. +Specifically, you need to set the following environment variables: ```yaml env: - # ... previous environment values - OPENAI.ORG: "" - PR_REVIEWER.REQUIRE_TESTS_REVIEW: "false" # Disable tests review - PR_CODE_SUGGESTIONS.NUM_CODE_SUGGESTIONS: 6 # Increase number of code suggestions + OPENAI_KEY: ${{ secrets.OPENAI_KEY }} # or give directly your key + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # or give directly your token github_action.auto_review: "true" # Enable auto review github_action.auto_describe: "true" # Enable auto describe github_action.auto_improve: "false" # Disable auto improve ``` -specifically, `github_action.auto_review`, `github_action.auto_describe` and `github_action.auto_improve` are used to enable/disable automatic tools that run when a new PR is opened. - +`github_action.auto_review`, `github_action.auto_describe` and `github_action.auto_improve` are used to enable/disable automatic tools that run when a new PR is opened. If not set, the default option is that only the `review` tool will run automatically when a new PR is opened. +Note that you can give additional config parameters by adding environment variables to `.github/workflows/pr_agent.yml`, or by using a `.pr_agent.toml` file in the root of your repo, similar to the GitHub App usage. +For example, you can set an environment variable: `pr_description.add_original_user_description=false`, or add a `.pr_agent.toml` file with the following content: +``` +[pr_description] +add_original_user_description = false +``` + + ### Changing a model See [here](pr_agent/algo/__init__.py) for the list of available models. diff --git a/pr_agent/servers/github_action_runner.py b/pr_agent/servers/github_action_runner.py index 0d02b3b3..4d35abff 100644 --- a/pr_agent/servers/github_action_runner.py +++ b/pr_agent/servers/github_action_runner.py @@ -19,10 +19,6 @@ async def run_action(): OPENAI_KEY = os.environ.get('OPENAI_KEY') or os.environ.get('OPENAI.KEY') OPENAI_ORG = os.environ.get('OPENAI_ORG') or os.environ.get('OPENAI.ORG') GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN') - CUSTOM_LABELS = os.environ.get('CUSTOM_LABELS') - CUSTOM_LABELS_DESCRIPTIONS = os.environ.get('CUSTOM_LABELS_DESCRIPTIONS') - # CUSTOM_LABELS is a comma separated list of labels (string), convert to list and strip spaces - get_settings().set("CONFIG.PUBLISH_OUTPUT_PROGRESS", False) # Check if required environment variables are set @@ -38,7 +34,6 @@ async def run_action(): if not GITHUB_TOKEN: print("GITHUB_TOKEN not set") return - # CUSTOM_LABELS_DICT = handle_custom_labels(CUSTOM_LABELS, CUSTOM_LABELS_DESCRIPTIONS) # Set the environment variables in the settings get_settings().set("OPENAI.KEY", OPENAI_KEY) @@ -46,7 +41,6 @@ async def run_action(): get_settings().set("OPENAI.ORG", OPENAI_ORG) get_settings().set("GITHUB.USER_TOKEN", GITHUB_TOKEN) get_settings().set("GITHUB.DEPLOYMENT_TYPE", "user") - # get_settings().set("CUSTOM_LABELS", CUSTOM_LABELS_DICT) # Load the event payload try: @@ -104,31 +98,5 @@ async def run_action(): await PRAgent().handle_request(url, body) -def handle_custom_labels(CUSTOM_LABELS, CUSTOM_LABELS_DESCRIPTIONS): - if CUSTOM_LABELS: - CUSTOM_LABELS = [x.strip() for x in CUSTOM_LABELS.split(',')] - else: - # Set default labels - CUSTOM_LABELS = ['Bug fix', 'Tests', 'Bug fix with tests', 'Refactoring', 'Enhancement', 'Documentation', - 'Other'] - print(f"Using default labels: {CUSTOM_LABELS}") - if CUSTOM_LABELS_DESCRIPTIONS: - CUSTOM_LABELS_DESCRIPTIONS = [x.strip() for x in CUSTOM_LABELS_DESCRIPTIONS.split(',')] - else: - # Set default labels - CUSTOM_LABELS_DESCRIPTIONS = ['Fixes a bug in the code', 'Adds or modifies tests', - 'Fixes a bug in the code and adds or modifies tests', - 'Refactors the code without changing its functionality', - 'Adds new features or functionality', - 'Adds or modifies documentation', - 'Other changes that do not fit in any of the above categories'] - print(f"Using default labels: {CUSTOM_LABELS_DESCRIPTIONS}") - # create a dictionary of labels and descriptions - CUSTOM_LABELS_DICT = dict() - for i in range(len(CUSTOM_LABELS)): - CUSTOM_LABELS_DICT[CUSTOM_LABELS[i]] = {'description': CUSTOM_LABELS_DESCRIPTIONS[i]} - return CUSTOM_LABELS_DICT - - if __name__ == '__main__': asyncio.run(run_action()) \ No newline at end of file