From 585a7f1c694eb5caaa30b5ff1ce9365e54991710 Mon Sep 17 00:00:00 2001 From: Matan Baruch <36934912+matanbaruch@users.noreply.github.com> Date: Sun, 15 Sep 2024 09:33:47 +0300 Subject: [PATCH 1/5] Update github_action_runner.py --- pr_agent/servers/github_action_runner.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pr_agent/servers/github_action_runner.py b/pr_agent/servers/github_action_runner.py index 945772118..0bda91506 100644 --- a/pr_agent/servers/github_action_runner.py +++ b/pr_agent/servers/github_action_runner.py @@ -37,7 +37,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') - # get_settings().set("CONFIG.PUBLISH_OUTPUT_PROGRESS", False) # Check if required environment variables are set if not GITHUB_EVENT_NAME: @@ -54,7 +53,6 @@ async def run_action(): if OPENAI_KEY: get_settings().set("OPENAI.KEY", OPENAI_KEY) else: - # Might not be set if the user is using models not from OpenAI print("OPENAI_KEY not set") if OPENAI_ORG: get_settings().set("OPENAI.ORG", OPENAI_ORG) @@ -83,10 +81,13 @@ async def run_action(): # Handle pull request event if GITHUB_EVENT_NAME == "pull_request": action = event_payload.get("action") - if action in ["opened", "reopened", "ready_for_review", "review_requested"]: + + # Retrieve the list of actions from the configuration + pr_actions = get_settings().get("GITHUB_ACTION_CONFIG.PR_ACTIONS", ["opened", "reopened", "ready_for_review", "review_requested"]) + + if action in pr_actions: pr_url = event_payload.get("pull_request", {}).get("url") if pr_url: - # legacy - supporting both GITHUB_ACTION and GITHUB_ACTION_CONFIG auto_review = get_setting_or_env("GITHUB_ACTION.AUTO_REVIEW", None) if auto_review is None: auto_review = get_setting_or_env("GITHUB_ACTION_CONFIG.AUTO_REVIEW", None) @@ -97,7 +98,6 @@ async def run_action(): if auto_improve is None: auto_improve = get_setting_or_env("GITHUB_ACTION_CONFIG.AUTO_IMPROVE", None) - # invoke by default all three tools if auto_describe is None or is_true(auto_describe): get_settings().pr_description.final_update_message = False # No final update message when auto_describe is enabled await PRDescription(pr_url).run() @@ -127,7 +127,7 @@ async def run_action(): if event_payload.get("issue", {}).get("pull_request"): url = event_payload.get("issue", {}).get("pull_request", {}).get("url") is_pr = True - elif event_payload.get("comment", {}).get("pull_request_url"): # for 'pull_request_review_comment + elif event_payload.get("comment", {}).get("pull_request_url"): url = event_payload.get("comment", {}).get("pull_request_url") is_pr = True disable_eyes = True From 0851767774d1e274c44c148fe69d937b295bdad5 Mon Sep 17 00:00:00 2001 From: Matan Baruch <36934912+matanbaruch@users.noreply.github.com> Date: Sun, 15 Sep 2024 09:35:58 +0300 Subject: [PATCH 2/5] Update configuration.toml --- pr_agent/settings/configuration.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index b6f9d08e8..27995cc96 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -200,6 +200,7 @@ ignore_bot_pr = true # auto_review = true # set as env var in .github/workflows/pr-agent.yaml # auto_describe = true # set as env var in .github/workflows/pr-agent.yaml # auto_improve = true # set as env var in .github/workflows/pr-agent.yaml +# pr_actions = ['opened', 'reopened', 'ready_for_review', 'review_requested'] [github_app] # these toggles allows running the github app from custom deployments From a23541912b8eb485b535a9550b444299c23f7a94 Mon Sep 17 00:00:00 2001 From: Matan Baruch <36934912+matanbaruch@users.noreply.github.com> Date: Sun, 15 Sep 2024 09:40:05 +0300 Subject: [PATCH 3/5] Update github_action_runner.py --- pr_agent/servers/github_action_runner.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pr_agent/servers/github_action_runner.py b/pr_agent/servers/github_action_runner.py index 0bda91506..417e81545 100644 --- a/pr_agent/servers/github_action_runner.py +++ b/pr_agent/servers/github_action_runner.py @@ -37,6 +37,7 @@ 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') + # get_settings().set("CONFIG.PUBLISH_OUTPUT_PROGRESS", False) # Check if required environment variables are set if not GITHUB_EVENT_NAME: From 306af02d2285a13a54e7b05aad369a38dab8090c Mon Sep 17 00:00:00 2001 From: Matan Baruch <36934912+matanbaruch@users.noreply.github.com> Date: Sun, 15 Sep 2024 09:42:02 +0300 Subject: [PATCH 4/5] Update github_action_runner.py --- pr_agent/servers/github_action_runner.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pr_agent/servers/github_action_runner.py b/pr_agent/servers/github_action_runner.py index 417e81545..bdd4f5cfc 100644 --- a/pr_agent/servers/github_action_runner.py +++ b/pr_agent/servers/github_action_runner.py @@ -54,6 +54,7 @@ async def run_action(): if OPENAI_KEY: get_settings().set("OPENAI.KEY", OPENAI_KEY) else: + # Might not be set if the user is using models not from OpenAI print("OPENAI_KEY not set") if OPENAI_ORG: get_settings().set("OPENAI.ORG", OPENAI_ORG) @@ -89,6 +90,7 @@ async def run_action(): if action in pr_actions: pr_url = event_payload.get("pull_request", {}).get("url") if pr_url: + # legacy - supporting both GITHUB_ACTION and GITHUB_ACTION_CONFIG auto_review = get_setting_or_env("GITHUB_ACTION.AUTO_REVIEW", None) if auto_review is None: auto_review = get_setting_or_env("GITHUB_ACTION_CONFIG.AUTO_REVIEW", None) @@ -99,6 +101,7 @@ async def run_action(): if auto_improve is None: auto_improve = get_setting_or_env("GITHUB_ACTION_CONFIG.AUTO_IMPROVE", None) + # invoke by default all three tools if auto_describe is None or is_true(auto_describe): get_settings().pr_description.final_update_message = False # No final update message when auto_describe is enabled await PRDescription(pr_url).run() @@ -128,7 +131,7 @@ async def run_action(): if event_payload.get("issue", {}).get("pull_request"): url = event_payload.get("issue", {}).get("pull_request", {}).get("url") is_pr = True - elif event_payload.get("comment", {}).get("pull_request_url"): + elif event_payload.get("comment", {}).get("pull_request_url"): # for 'pull_request_review_comment url = event_payload.get("comment", {}).get("pull_request_url") is_pr = True disable_eyes = True From 5d68b0c4922a0c25c1d3bc2d085a0f048e788013 Mon Sep 17 00:00:00 2001 From: Matan Baruch <36934912+matanbaruch@users.noreply.github.com> Date: Sun, 15 Sep 2024 15:19:40 +0300 Subject: [PATCH 5/5] Update automations_and_usage.md --- docs/docs/usage-guide/automations_and_usage.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/docs/usage-guide/automations_and_usage.md b/docs/docs/usage-guide/automations_and_usage.md index 1c6e80526..b3d92fcdf 100644 --- a/docs/docs/usage-guide/automations_and_usage.md +++ b/docs/docs/usage-guide/automations_and_usage.md @@ -121,10 +121,14 @@ Specifically, start by setting the following environment variables: github_action_config.auto_review: "true" # enable\disable auto review github_action_config.auto_describe: "true" # enable\disable auto describe github_action_config.auto_improve: "true" # enable\disable auto improve + github_action_config.pr_actions: ["opened", "reopened", "ready_for_review", "review_requested"] ``` `github_action_config.auto_review`, `github_action_config.auto_describe` and `github_action_config.auto_improve` are used to enable/disable automatic tools that run when a new PR is opened. If not set, the default configuration is for all three tools to run automatically when a new PR is opened. +`github_action_config.pr_actions` is used to configure which `pull_requests` events will trigger the enabled auto flags +If not set, the default configuration is `["opened", "reopened", "ready_for_review", "review_requested"]` + `github_action_config.enable_output` are used to enable/disable github actions [output parameter](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#outputs-for-docker-container-and-javascript-actions) (default is `true`). Review result is output as JSON to `steps.{step-id}.outputs.review` property. The JSON structure is equivalent to the yaml data structure defined in [pr_reviewer_prompts.toml](https://github.com/idubnori/pr-agent/blob/main/pr_agent/settings/pr_reviewer_prompts.toml).