Skip to content

Commit

Permalink
refc: flake8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sauravpanda committed Apr 6, 2024
1 parent 010c849 commit 64ca28e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
6 changes: 3 additions & 3 deletions api/github_helper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def is_github_signature_valid(headers, body):
Validate the signature of the incoming request against the secret.
"""
github_secret = os.environ.get("GITHUB_APP_WEBHOOK_SECRET", "").encode()
signature = headers.get('X-Hub-Signature-256')
signature = headers.get("X-Hub-Signature-256")

if not signature or not github_secret:
return False

sha_name, signature = signature.split('=')
if sha_name != 'sha256':
sha_name, signature = signature.split("=")
if sha_name != "sha256":
return False

mac = hmac.new(github_secret, msg=body, digestmod=hashlib.sha256)
Expand Down
4 changes: 1 addition & 3 deletions api/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from fastapi import FastAPI, Request, BackgroundTasks, HTTPException
from fastapi.responses import JSONResponse
from api.github_helper.pull_requests import process_pull_request, ACTIONS_TO_PROCESS_PR
from api.github_helper.utils import (
is_github_signature_valid
)
from api.github_helper.utils import is_github_signature_valid
import logging

logging.basicConfig(
Expand Down
51 changes: 27 additions & 24 deletions tests/helpers/test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
from unittest.mock import patch
from unittest.mock import patch
import logging
from cloudcode.helpers.output import (
COLLAPSIBLE_TEMPLATE,
json_to_markdown
)
from cloudcode.helpers.output import COLLAPSIBLE_TEMPLATE, json_to_markdown


@pytest.fixture
Expand All @@ -16,46 +13,52 @@ def test_data():
"topic": "Code Quality",
"comment": "The code is well-structured and easy to read.",
"reasoning": "The code follows best practices and coding standards.",
"confidence": "High"
"confidence": "High",
},
{
"topic": "Performance",
"comment": "The code could be optimized for better performance.",
"reasoning": "There are some inefficient loops and data structures used.",
"confidence": "Medium"
"confidence": "Medium",
},
{
"topic": "Security",
"comment": "NA",
"reasoning": "NA",
"confidence": "NA"
}
"confidence": "NA",
},
]
}


def test_json_to_markdown(test_data, capfd):
logging.getLogger().setLevel(logging.ERROR)
expected_output = "## Code Review Feedback\n\n"
expected_output += "### Code Quality\n\n"
expected_output += COLLAPSIBLE_TEMPLATE.format(
comment="The code is well-structured and easy to read.",
reasoning="The code follows best practices and coding standards.",
confidence="High"
) + "\n"
expected_output += (
COLLAPSIBLE_TEMPLATE.format(
comment="The code is well-structured and easy to read.",
reasoning="The code follows best practices and coding standards.",
confidence="High",
)
+ "\n"
)
expected_output += "### Performance\n\n"
expected_output += COLLAPSIBLE_TEMPLATE.format(
comment="The code could be optimized for better performance.",
reasoning="There are some inefficient loops and data structures used.",
confidence="Medium"
) + "\n"
expected_output += (
COLLAPSIBLE_TEMPLATE.format(
comment="The code could be optimized for better performance.",
reasoning="There are some inefficient loops and data structures used.",
confidence="Medium",
)
+ "\n"
)
expected_output += "### Security\n\n"
expected_output += COLLAPSIBLE_TEMPLATE.format(
comment="NA",
reasoning="NA",
confidence="NA"
) + "\n"
expected_output += (
COLLAPSIBLE_TEMPLATE.format(comment="NA", reasoning="NA", confidence="NA")
+ "\n"
)

output = json_to_markdown(test_data)
captured = capfd.readouterr()
assert output == expected_output
assert captured.out == ""
assert captured.out == ""

0 comments on commit 64ca28e

Please sign in to comment.