Added provision to accept the git repo url from UI
Browse files- app.py +27 -16
- lib/code_reviewer.py +3 -3
app.py
CHANGED
@@ -2,9 +2,12 @@
|
|
2 |
|
3 |
# Import necessary modules from lib
|
4 |
from lib.code_reviewer import CodeReviewer, ReviewManager
|
|
|
5 |
import os
|
6 |
import glob
|
7 |
|
|
|
|
|
8 |
# Variables for GitHub repository details
|
9 |
REPO_OWNER = "vsagar100"
|
10 |
REPO_NAME = "ansible_tf_provisioner"
|
@@ -15,11 +18,9 @@ GITHUB_TOKEN = "github_pat_11AF2YOZI0T6NzY3glKc04_40PRSN3Tl0dDhmrEdFZIbNMReQKktV
|
|
15 |
#repo_url = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/zipball/main"
|
16 |
GITHUB_REPO_URL = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/zipball/{GITHUB_BRANCH}"
|
17 |
|
18 |
-
|
19 |
# Directory structure setup
|
20 |
-
# Directory for storing downloaded GitHub repository
|
21 |
download_directory = "downloaded_repo"
|
22 |
-
# Directory for storing output JSON reviews
|
23 |
output_directory = "output_reviews"
|
24 |
|
25 |
# Ensure the directories exist
|
@@ -30,20 +31,30 @@ def main():
|
|
30 |
code_reviewer = CodeReviewer()
|
31 |
review_manager = ReviewManager(reviewer=code_reviewer)
|
32 |
|
33 |
-
|
34 |
-
|
|
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
|
40 |
-
|
41 |
-
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
print(f"Reviews saved to {output_json_path}")
|
47 |
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# Import necessary modules from lib
|
4 |
from lib.code_reviewer import CodeReviewer, ReviewManager
|
5 |
+
import streamlit as st
|
6 |
import os
|
7 |
import glob
|
8 |
|
9 |
+
# Streamlit UI for inputting GitHub repository details
|
10 |
+
st.title("GitHub Repository Code Reviewer")
|
11 |
# Variables for GitHub repository details
|
12 |
REPO_OWNER = "vsagar100"
|
13 |
REPO_NAME = "ansible_tf_provisioner"
|
|
|
18 |
#repo_url = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/zipball/main"
|
19 |
GITHUB_REPO_URL = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/zipball/{GITHUB_BRANCH}"
|
20 |
|
21 |
+
if st.button("Review Code") and GITHUB_REPO_URL:
|
22 |
# Directory structure setup
|
|
|
23 |
download_directory = "downloaded_repo"
|
|
|
24 |
output_directory = "output_reviews"
|
25 |
|
26 |
# Ensure the directories exist
|
|
|
31 |
code_reviewer = CodeReviewer()
|
32 |
review_manager = ReviewManager(reviewer=code_reviewer)
|
33 |
|
34 |
+
try:
|
35 |
+
# Download GitHub repository
|
36 |
+
review_manager.download_repo(GITHUB_REPO_URL, GITHUB_TOKEN, download_directory)
|
37 |
|
38 |
+
# Find all YAML files in the downloaded repository
|
39 |
+
yaml_files = glob.glob(os.path.join(download_directory, "**", "*.yml"), recursive=True)
|
40 |
+
yaml_files += glob.glob(os.path.join(download_directory, "**", "*.yaml"), recursive=True)
|
41 |
|
42 |
+
# Process files and generate reviews
|
43 |
+
reviews = review_manager.process_files(yaml_files)
|
44 |
|
45 |
+
# Save reviews to JSON
|
46 |
+
output_json_path = os.path.join(output_directory, "code_review_results.json")
|
47 |
+
review_manager.save_reviews_to_json(reviews, output_json_path)
|
|
|
48 |
|
49 |
+
# Display review results
|
50 |
+
st.success(f"Reviews saved to {output_json_path}")
|
51 |
+
for review in reviews:
|
52 |
+
st.subheader(f"Review for {review['filename']}")
|
53 |
+
st.text(review['review'])
|
54 |
+
|
55 |
+
# Provide download link for JSON results
|
56 |
+
with open(output_json_path, "r") as json_file:
|
57 |
+
st.download_button("Download JSON Results", json_file, file_name="code_review_results.json")
|
58 |
+
|
59 |
+
except Exception as e:
|
60 |
+
st.error(f"An error occurred: {str(e)}")
|
lib/code_reviewer.py
CHANGED
@@ -33,7 +33,7 @@ class CodeReviewer:
|
|
33 |
Returns:
|
34 |
Dict: The code standards in dictionary form.
|
35 |
"""
|
36 |
-
standards_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "standards", "
|
37 |
with open(standards_path, 'r') as f:
|
38 |
return json.load(f)
|
39 |
|
@@ -91,13 +91,13 @@ class ReviewManager:
|
|
91 |
token (str): The GitHub personal access token for authentication.
|
92 |
download_path (str): The path to extract the downloaded repository.
|
93 |
"""
|
94 |
-
headers = {"Authorization": f"
|
95 |
response = requests.get(repo_url, headers=headers)
|
96 |
if response.status_code == 200:
|
97 |
with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:
|
98 |
zip_ref.extractall(download_path)
|
99 |
else:
|
100 |
-
raise Exception(f"Failed to download repository. Status code: {response.status_code}")
|
101 |
|
102 |
def process_files(self, file_paths: List[str]) -> List[Dict[str, str]]:
|
103 |
"""
|
|
|
33 |
Returns:
|
34 |
Dict: The code standards in dictionary form.
|
35 |
"""
|
36 |
+
standards_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "standards", "code_standards.json")
|
37 |
with open(standards_path, 'r') as f:
|
38 |
return json.load(f)
|
39 |
|
|
|
91 |
token (str): The GitHub personal access token for authentication.
|
92 |
download_path (str): The path to extract the downloaded repository.
|
93 |
"""
|
94 |
+
headers = {"Authorization": f"Bearer {token}"}
|
95 |
response = requests.get(repo_url, headers=headers)
|
96 |
if response.status_code == 200:
|
97 |
with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:
|
98 |
zip_ref.extractall(download_path)
|
99 |
else:
|
100 |
+
raise Exception(f"Failed to download repository. Status code: {response.status_code}, Message: {response.text}")
|
101 |
|
102 |
def process_files(self, file_paths: List[str]) -> List[Dict[str, str]]:
|
103 |
"""
|