vsagar100 commited on
Commit
c3f0268
·
1 Parent(s): f7e411d

Updated git download code

Browse files
Files changed (2) hide show
  1. app.py +7 -2
  2. lib/code_reviewer.py +2 -4
app.py CHANGED
@@ -6,10 +6,15 @@ import os
6
  import glob
7
 
8
  # Variables for GitHub repository details
9
- GITHUB_REPO_URL = "https://github.com/vsagar100/ansible_tf_provisioner"
 
10
  GITHUB_BRANCH = "main" # Specify the branch or tag to download
11
  GITHUB_TOKEN = "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" #os.getenv("GITHUB_TOKEN") # Specify your GitHub token
12
 
 
 
 
 
13
  def main():
14
  # Directory structure setup
15
  # Directory for storing downloaded GitHub repository
@@ -26,7 +31,7 @@ def main():
26
  review_manager = ReviewManager(reviewer=code_reviewer)
27
 
28
  # Download GitHub repository
29
- review_manager.download_repo(GITHUB_REPO_URL, GITHUB_BRANCH, GITHUB_TOKEN, download_directory)
30
 
31
  # Find all YAML files in the downloaded repository
32
  yaml_files = glob.glob(os.path.join(download_directory, "**", "*.yml"), recursive=True)
 
6
  import glob
7
 
8
  # Variables for GitHub repository details
9
+ REPO_OWNER = "vsagar100"
10
+ REPO_NAME = "ansible_tf_provisioner"
11
  GITHUB_BRANCH = "main" # Specify the branch or tag to download
12
  GITHUB_TOKEN = "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" #os.getenv("GITHUB_TOKEN") # Specify your GitHub token
13
 
14
+ # GitHub API endpoint to download the repo as a zip file
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
  def main():
19
  # Directory structure setup
20
  # Directory for storing downloaded GitHub repository
 
31
  review_manager = ReviewManager(reviewer=code_reviewer)
32
 
33
  # Download GitHub repository
34
+ review_manager.download_repo(GITHUB_REPO_URL, GITHUB_TOKEN, download_directory)
35
 
36
  # Find all YAML files in the downloaded repository
37
  yaml_files = glob.glob(os.path.join(download_directory, "**", "*.yml"), recursive=True)
lib/code_reviewer.py CHANGED
@@ -82,19 +82,17 @@ class ReviewManager:
82
  """
83
  self.reviewer = reviewer
84
 
85
- def download_repo(self, repo_url: str, branch: str, token: str, download_path: str):
86
  """
87
  Downloads a GitHub repository as a ZIP file and extracts it.
88
 
89
  Args:
90
  repo_url (str): The GitHub repository URL.
91
- branch (str): The branch or tag to download.
92
  token (str): The GitHub personal access token for authentication.
93
  download_path (str): The path to extract the downloaded repository.
94
  """
95
- zip_url = f"{repo_url}/archive/refs/heads/{branch}.zip"
96
  headers = {"Authorization": f"token {token}"}
97
- response = requests.get(zip_url, headers=headers)
98
  if response.status_code == 200:
99
  with zipfile.ZipFile(io.BytesIO(response.content)) as zip_ref:
100
  zip_ref.extractall(download_path)
 
82
  """
83
  self.reviewer = reviewer
84
 
85
+ def download_repo(self, repo_url: str, token: str, download_path: str):
86
  """
87
  Downloads a GitHub repository as a ZIP file and extracts it.
88
 
89
  Args:
90
  repo_url (str): The GitHub repository URL.
 
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"token {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)