File size: 3,209 Bytes
e49d8aa
 
 
 
02bdc55
be07e2e
df513b0
 
02bdc55
 
df513b0
c3f0268
0dbfe24
d321cf2
f7e411d
e49d8aa
c3f0268
 
 
 
02bdc55
e49d8aa
df513b0
e49d8aa
 
 
df513b0
e49d8aa
 
 
0dbfe24
 
 
 
e49d8aa
02bdc55
 
0dbfe24
 
 
 
df513b0
02bdc55
0dbfe24
 
 
 
df513b0
0dbfe24
 
 
 
e49d8aa
02bdc55
 
 
e49d8aa
02bdc55
 
 
 
 
 
0dbfe24
 
 
 
02bdc55
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# app.py

# Import necessary modules from lib
from lib.code_reviewer import CodeReviewer, ReviewManager
import streamlit as st
import os
import glob

# Streamlit UI for inputting GitHub repository details
st.title("GitHub Repository Code Reviewer")
# Variables for GitHub repository details
REPO_OWNER = "vsagar100"
REPO_NAME = st.text_input("Enter the GitHub repository name:")
GITHUB_BRANCH = st.text_input("Enter the branch or tag to download (default: main):", "main")
GITHUB_TOKEN = "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" #os.getenv("GITHUB_TOKEN")  # Specify your GitHub token

# GitHub API endpoint to download the repo as a zip file
#repo_url = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/zipball/main"
GITHUB_REPO_URL = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/zipball/{GITHUB_BRANCH}"

if st.button("Review Code") and GITHUB_REPO_URL:
    # Directory structure setup
    download_directory = "downloaded_repo"
    output_directory = "output_reviews"

    # Ensure the directories exist
    os.makedirs(download_directory, exist_ok=True)
    os.makedirs(output_directory, exist_ok=True)

    # Initialize the code reviewer and review manager
    with st.spinner("Initializing CodeReviewer and ReviewManager..."):
        code_reviewer = CodeReviewer()
        review_manager = ReviewManager(reviewer=code_reviewer)


    try:
        # Download GitHub repository
        with st.spinner("Downloading GitHub repository..."):
            review_manager.download_repo(GITHUB_REPO_URL, GITHUB_TOKEN, download_directory)
            st.success("Repository downloaded successfully.")


        # Find all YAML files in the downloaded repository
        with st.spinner("Searching for YAML files in the downloaded repository..."):
            yaml_files = glob.glob(os.path.join(download_directory, "**", "*.yml"), recursive=True)
            yaml_files += glob.glob(os.path.join(download_directory, "**", "*.yaml"), recursive=True)
            st.info(f"Found {len(yaml_files)} YAML files for review.")

        # Process files and generate reviews        
        with st.spinner("Processing files for review..."):
            reviews = review_manager.process_files(yaml_files)
            st.success("Files processed successfully.")

        # Save reviews to JSON
        output_json_path = os.path.join(output_directory, "code_review_results.json")
        review_manager.save_reviews_to_json(reviews, output_json_path)

        # Display review results
        st.success(f"Reviews saved to {output_json_path}")
        for review in reviews:
            st.subheader(f"Review for {review['filename']}")
            st.text(review['review'])

         # Display JSON output on the UI
        st.subheader("Full JSON Review Output")
        st.json(reviews)

        # Provide download link for JSON results
        with open(output_json_path, "r") as json_file:
            st.download_button("Download JSON Results", json_file, file_name="code_review_results.json")

    except Exception as e:
        st.error(f"An error occurred: {str(e)}")