dwb2023 commited on
Commit
418c4df
·
verified ·
1 Parent(s): 9d2cbd3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -16,10 +16,11 @@ SUPPORTED_FILE_TYPES = ["txt", "python", "markdown", "yaml", "json", "csv", "tsv
16
  def validate_url(url):
17
  return url.startswith('https://')
18
 
19
- def clone_repo(url, repo_dir):
20
  env = os.environ.copy()
21
  env['GIT_LFS_SKIP_SMUDGE'] = '1'
22
- result = subprocess.run(["git", "clone", url, repo_dir], env=env, capture_output=True, text=True)
 
23
  if result.returncode != 0:
24
  return False, result.stderr
25
  return True, None
@@ -53,7 +54,7 @@ def validate_file_types(directory):
53
  file_types[file_path] = f"Error: {str(e)}"
54
  return file_types
55
 
56
- def extract_repo_content(url):
57
  if not validate_url(url):
58
  return [{"header": {"name": "Error", "type": "error", "size": 0}, "content": "Invalid URL"}]
59
 
@@ -61,7 +62,7 @@ def extract_repo_content(url):
61
  if os.path.exists(repo_dir):
62
  subprocess.run(["rm", "-rf", repo_dir])
63
 
64
- success, error = clone_repo(url, repo_dir)
65
  if not success:
66
  return [{"header": {"name": "Error", "type": "error", "size": 0}, "content": f"Failed to clone repository: {error}"}]
67
 
@@ -100,7 +101,7 @@ def format_output(extracted_content, repo_url):
100
  return formatted_output
101
 
102
  def extract_and_display(url):
103
- extracted_content = extract_repo_content(url)
104
  formatted_output = format_output(extracted_content, url)
105
  return formatted_output
106
 
 
16
  def validate_url(url):
17
  return url.startswith('https://')
18
 
19
+ def clone_repo(url, repo_dir, token):
20
  env = os.environ.copy()
21
  env['GIT_LFS_SKIP_SMUDGE'] = '1'
22
+ git_command = ["git", "clone", f"https://{token}:x-oauth-basic@{url[8:]}", repo_dir]
23
+ result = subprocess.run(git_command, env=env, capture_output=True, text=True)
24
  if result.returncode != 0:
25
  return False, result.stderr
26
  return True, None
 
54
  file_types[file_path] = f"Error: {str(e)}"
55
  return file_types
56
 
57
+ def extract_repo_content(url, token):
58
  if not validate_url(url):
59
  return [{"header": {"name": "Error", "type": "error", "size": 0}, "content": "Invalid URL"}]
60
 
 
62
  if os.path.exists(repo_dir):
63
  subprocess.run(["rm", "-rf", repo_dir])
64
 
65
+ success, error = clone_repo(url, repo_dir, token)
66
  if not success:
67
  return [{"header": {"name": "Error", "type": "error", "size": 0}, "content": f"Failed to clone repository: {error}"}]
68
 
 
101
  return formatted_output
102
 
103
  def extract_and_display(url):
104
+ extracted_content = extract_repo_content(url, hf_token)
105
  formatted_output = format_output(extracted_content, url)
106
  return formatted_output
107