diff --git a/.gitignore b/.gitignore index 476837426..5977d585b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ .idea/ venv/ +lib/ +bin/ pr_agent/settings/.secrets.toml __pycache__ dist/ diff --git a/docker/Dockerfile b/docker/Dockerfile index eca88f4ed..5f20281c1 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -8,7 +8,7 @@ ENV PYTHONPATH=/app FROM base as github_app ADD pr_agent pr_agent -CMD ["python", "pr_agent/servers/github_app.py"] +CMD ["python", "pr_agent/servers/launch_github_app.py"] FROM base as bitbucket_app ADD pr_agent pr_agent diff --git a/pr_agent/servers/github_app.py b/pr_agent/servers/github_app.py index be1410848..6b15a328a 100644 --- a/pr_agent/servers/github_app.py +++ b/pr_agent/servers/github_app.py @@ -4,6 +4,10 @@ import re import uuid from typing import Any, Dict, Tuple +import boto3 +import json +import toml +from botocore.exceptions import ClientError import uvicorn from fastapi import APIRouter, FastAPI, HTTPException, Request, Response @@ -22,6 +26,7 @@ from pr_agent.log import LoggingFormat, get_logger, setup_logger from pr_agent.servers.utils import DefaultDictWithTimeout, verify_signature + setup_logger(fmt=LoggingFormat.JSON, level="DEBUG") base_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) build_number_path = os.path.join(base_path, "build_number.txt") diff --git a/pr_agent/servers/launch_github_app.py b/pr_agent/servers/launch_github_app.py new file mode 100644 index 000000000..4a6f0a68f --- /dev/null +++ b/pr_agent/servers/launch_github_app.py @@ -0,0 +1,39 @@ +import subprocess +import re +import boto3 +import json +import toml +from botocore.exceptions import ClientError + +secret_name = "devops/github/pr-agent-bot" +region_name = "eu-west-1" + +def get_aws_secrets(secret_name, region_name): + session = boto3.session.Session() + client = session.client( + service_name='secretsmanager', + region_name=region_name + ) + + try: + get_secret_value_response = client.get_secret_value( + SecretId=secret_name + ) + except ClientError as e: + raise e + + secret = get_secret_value_response['SecretString'] + return secret + +def create_toml_file(file_path, secret_content): + try: + with open("pr_agent/settings/.secrets.toml", 'w') as file: + file.write(secret_content) + print(f"Successfully updated in {file_path}.") + except Exception as e: + print(f"Error writing to TOML file: {e}") + +secret_dict = json.loads(get_aws_secrets(secret_name,region_name)) +secret_toml=secret_dict.get('secret_file') +create_toml_file("pr_agent/settings/.secrets.toml",secret_toml) +subprocess.run(['python', 'pr_agent/servers/github_app.py']) diff --git a/pr_agent/settings/.secrets_template_bkp.toml b/pr_agent/settings/.secrets_template_bkp.toml new file mode 100644 index 000000000..b5aa352f3 --- /dev/null +++ b/pr_agent/settings/.secrets_template_bkp.toml @@ -0,0 +1,92 @@ +# QUICKSTART: +# Copy this file to .secrets.toml in the same folder. +# The minimum workable settings - set openai.key to your API key. +# Set github.deployment_type to "user" and github.user_token to your GitHub personal access token. +# This will allow you to run the CLI scripts in the scripts/ folder and the github_polling server. +# +# See README for details about GitHub App deployment. + +[openai] +key = "" # Acquire through https://platform.openai.com +#org = "" # Optional, may be commented out. +# Uncomment the following for Azure OpenAI +#api_type = "azure" +#api_version = '2023-05-15' # Check Azure documentation for the current API version +#api_base = "" # The base URL for your Azure OpenAI resource. e.g. "https://.openai.azure.com" +#deployment_id = "" # The deployment name you chose when you deployed the engine +#fallback_deployments = [] # For each fallback model specified in configuration.toml in the [config] section, specify the appropriate deployment_id + +[pinecone] +api_key = "..." +environment = "gcp-starter" + +[anthropic] +key = "" # Optional, uncomment if you want to use Anthropic. Acquire through https://www.anthropic.com/ + +[cohere] +key = "" # Optional, uncomment if you want to use Cohere. Acquire through https://dashboard.cohere.ai/ + +[replicate] +key = "" # Optional, uncomment if you want to use Replicate. Acquire through https://replicate.com/ + +[groq] +key = "" # Acquire through https://console.groq.com/keys + +[huggingface] +key = "" # Optional, uncomment if you want to use Huggingface Inference API. Acquire through https://huggingface.co/docs/api-inference/quicktour +api_base = "" # the base url for your huggingface inference endpoint + +[ollama] +api_base = "" # the base url for your local Llama 2, Code Llama, and other models inference endpoint. Acquire through https://ollama.ai/ + +[vertexai] +vertex_project = "" # the google cloud platform project name for your vertexai deployment +vertex_location = "" # the google cloud platform location for your vertexai deployment + +[aws] +bedrock_region = "" # the AWS region to call Bedrock APIs + +[github] +# ---- Set the following only for deployment type == "user" +user_token = "" # A GitHub personal access token with 'repo' scope. +deployment_type = "user" #set to user by default + +# ---- Set the following only for deployment type == "app", see README for details. +private_key = """\ +-----BEGIN RSA PRIVATE KEY----- + +-----END RSA PRIVATE KEY----- +""" +app_id = 123456 # The GitHub App ID, replace with your own. +webhook_secret = "" # Optional, may be commented out. + +[gitlab] +# Gitlab personal access token +personal_access_token = "" + +[bitbucket] +# For Bitbucket personal/repository bearer token +bearer_token = "" + +[bitbucket_server] +# For Bitbucket Server bearer token +auth_token = "" +webhook_secret = "" + +# For Bitbucket app +app_key = "" +base_url = "" + +[litellm] +LITELLM_TOKEN = "" # see https://docs.litellm.ai/docs/debugging/hosted_debugging for details and instructions on how to get a token + +[azure_devops] +# For Azure devops personal access token +org = "" +pat = "" + +[azure_devops_server] +# For Azure devops Server basic auth - configured in the webhook creation +# Optional, uncomment if you want to use Azure devops webhooks. Value assinged when you create the webhook +# webhook_username = "" +# webhook_password = "" diff --git a/pr_agent/settings/configuration.toml b/pr_agent/settings/configuration.toml index 8ecf04ab4..614cfc12b 100644 --- a/pr_agent/settings/configuration.toml +++ b/pr_agent/settings/configuration.toml @@ -134,7 +134,7 @@ enable_help_text=true [github] # The type of deployment to create. Valid values are 'app' or 'user'. -deployment_type = "user" +deployment_type = "app" ratelimit_retries = 5 base_url = "https://api.github.com" publish_inline_comments_fallback_with_verification = true diff --git a/pyvenv.cfg b/pyvenv.cfg new file mode 100644 index 000000000..53dee7d74 --- /dev/null +++ b/pyvenv.cfg @@ -0,0 +1,5 @@ +home = /usr/local/opt/python@3.12/bin +include-system-site-packages = false +version = 3.12.3 +executable = /usr/local/Cellar/python@3.12/3.12.3/Frameworks/Python.framework/Versions/3.12/bin/python3.12 +command = /usr/local/opt/python@3.12/bin/python3.12 -m venv /Users/amar.khan/pr-agent diff --git a/requirements.txt b/requirements.txt index 283a319a1..95f319e33 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,6 +23,7 @@ tiktoken==0.7.0 ujson==5.8.0 uvicorn==0.22.0 tenacity==8.2.3 +toml==0.10.2 # Uncomment the following lines to enable the 'similar issue' tool # pinecone-client # pinecone-datasets @ git+https://github.com/mrT23/pinecone-datasets.git@main