Skip to content

Commit

Permalink
Merge pull request #25 from Cloud-Code-AI/24-bug-pull-request-detail-…
Browse files Browse the repository at this point in the history
…bug-original-desc-missing

fix: pull_request_desc bug
  • Loading branch information
sauravpanda authored Apr 6, 2024
2 parents 063572c + 6e73126 commit 2cdccec
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
3 changes: 3 additions & 0 deletions api/github_helper/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from api.github_helper.utils import get_config

CONFIG_DATA = get_config()
7 changes: 7 additions & 0 deletions api/github_helper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import hmac
import hashlib
import json

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -60,3 +61,9 @@ def is_github_signature_valid(headers, body):

mac = hmac.new(github_secret, msg=body, digestmod=hashlib.sha256)
return hmac.compare_digest(mac.hexdigest(), signature)


def get_config():
with open("config.json", "r") as f:
config_data = json.loads(f.read())
return config_data
6 changes: 4 additions & 2 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
process_pr_desc,
)
from api.github_helper.utils import is_github_signature_valid
from api.github_helper.constants import CONFIG_DATA
import logging

logging.basicConfig(
Expand All @@ -23,8 +24,9 @@ async def handle_webhook(request: Request, background_tasks: BackgroundTasks):
body = await request.body()
event = request.headers.get("X-GitHub-Event")
# Check if the Signature is valid
# TODO: Make this optional based on user config settings
if not is_github_signature_valid(request.headers, body):
if CONFIG_DATA["github_app"]["check_signature"] and not is_github_signature_valid(
request.headers, body
):
return HTTPException(status_code=404, detail="Invalid Signature")

if event == "pull_request":
Expand Down
5 changes: 4 additions & 1 deletion cloudcode/actions/reviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,8 @@ def generate_pull_request_desc(
)

resp = self.provider.chat_completion(prompt)
body = output.create_pr_description(parser.extract_json(resp))
self.logger.debug(f"PROMPT Generate PR Desc RESP: {resp}")
body = output.create_pr_description(
parser.extract_json(resp), pull_request_desc
)
return body
4 changes: 1 addition & 3 deletions cloudcode/helpers/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
DESC_COLLAPSIBLE_TEMPLATE = """
<details>
<summary>Original Description</summary>
{desc}
</details>
"""

Expand All @@ -41,7 +39,7 @@ def create_pr_review_from_json(data):


def create_pr_description(data, original_desc):
markdown_output = "## Autogenerated PR Description"
markdown_output = "## Autogenerated PR Description \n\n"
markdown_output += data["desc"]
markdown_output += "\n\n -- Generated with love by Cloud Code AI"
markdown_output += "\n\n" + DESC_COLLAPSIBLE_TEMPLATE.format(desc=original_desc)
Expand Down
3 changes: 3 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"language_model": {
"provider": "litellm"
},
"github_app": {
"check_signature": false
}
}

0 comments on commit 2cdccec

Please sign in to comment.