File size: 1,675 Bytes
e49d8aa
 
 
 
be07e2e
df513b0
 
 
 
 
 
e49d8aa
 
 
df513b0
 
e49d8aa
 
 
 
df513b0
e49d8aa
 
 
 
 
 
df513b0
 
 
 
 
 
 
e49d8aa
df513b0
e49d8aa
 
df513b0
e49d8aa
 
 
 
 
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
# app.py

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

# Variables for GitHub repository details
GITHUB_REPO_URL = "https://github.com/vsagar100/ansible_tf_provisioner"
GITHUB_BRANCH = "main"  # Specify the branch or tag to download
GITHUB_TOKEN = os.getenv("GITHUB_TOKEN")  # Specify your GitHub token

def main():
    # Directory structure setup
    # Directory for storing downloaded GitHub repository
    download_directory = "downloaded_repo"
    # Directory for storing output JSON reviews
    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
    code_reviewer = CodeReviewer()
    review_manager = ReviewManager(reviewer=code_reviewer)

    # Download GitHub repository
    review_manager.download_repo(GITHUB_REPO_URL, GITHUB_BRANCH, GITHUB_TOKEN, download_directory)

    # Find all 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)

    # Process files and generate reviews
    reviews = review_manager.process_files(yaml_files)

    # 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)
    print(f"Reviews saved to {output_json_path}")

if __name__ == "__main__":
    main()