Skip to content

Commit

Permalink
Enhance aicodebot_action.py with better error handling and configurat…
Browse files Browse the repository at this point in the history
…ion 🛠️

This commit introduces a few key changes to improve the functionality of our AI code bot. We've added the import of `get_config_file` from `aicodebot.config` and `Path` from `pathlib` to better handle configuration files.

We've also moved the setting of the `OPENAI_API_KEY` environment variable to a more appropriate location, ensuring it's set even if the key is not initially present. This should help prevent any unexpected errors related to missing API keys.

Lastly, we've added a check to ensure the configuration file exists after it's set up, and we're now printing the output of the configuration command for better debugging.

These changes should make the bot more robust and easier to use. Happy coding! 🚀
  • Loading branch information
TechNickAI committed Jul 13, 2023
1 parent 38a3029 commit c314302
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion aicodebot_action.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env python3
from aicodebot.cli import cli
from aicodebot.config import get_config_file
from click.testing import CliRunner
from github import Github
from pathlib import Path
import json, os, subprocess, sys

# ---------------------------------------------------------------------------- #
Expand All @@ -10,7 +12,6 @@

# Check if required inputs are set
openai_api_key = os.getenv("INPUT_OPENAI_API_KEY") # Note this is prefixed with INPUT_ through actions
os.environ["OPENAI_API_KEY"] = openai_api_key
if not openai_api_key:
print("🛑 The OpenAI API Key is not set. This key is REQUIRED for the AICodeBot.")
print("You can get one for free at https://platform.openai.com/account/api-keys")
Expand All @@ -20,6 +21,9 @@
print("https://docs.github.com/en/actions/security-guides/encrypted-secrets")
sys.exit(1)

# Set the OPENAI_API_KEY environment variable
os.environ["OPENAI_API_KEY"] = openai_api_key

# Set up the personality, defaulting to "Her"
os.environ["AICODEBOT_PERSONALITY"] = os.getenv("INPUT_AICODEBOT_PERSONALITY", "Her")

Expand All @@ -38,7 +42,9 @@

# Set up the aicodebot configuration from the OPENAI_API_KEY
result = cli_runner.invoke(cli, ["configure", "--openai-api-key", openai_api_key])
print(f"Configure: {result.output}")
assert result.exit_code == 0
assert Path(get_config_file()).exists()

# Run a code review on the current commit
result = cli_runner.invoke(cli, ["review", "-c", os.getenv("GITHUB_SHA"), "--output-format", "json"])
Expand Down

0 comments on commit c314302

Please sign in to comment.