|
1 | | -import mimetypes |
2 | 1 | import subprocess |
3 | 2 | import requests |
4 | | -import os |
5 | | -import shutil |
6 | | - |
7 | | -github_key = os.environ.get('GITHUB_API_KEY') |
8 | | - |
9 | | -def get_github_repo_stars(repo_url): |
10 | | - if github_key is None: |
11 | | - print('🔴🔴 no github api key provided!!') |
12 | | - # Extracting the owner and repo name from the URL |
13 | | - parts = repo_url.split("/") |
14 | | - owner, repo = parts[-2], parts[-1] |
15 | | - |
16 | | - # GitHub API endpoint for fetching repo details |
17 | | - api_url = f"https://api.github.com/repos/{owner}/{repo}" |
18 | | - |
19 | | - headers = { |
20 | | - "Authorization": f"token {github_key}", # Adding the authentication token to the request header |
21 | | - "Accept": "application/vnd.github.v3+json" |
22 | | - } |
23 | | - |
24 | | - # Making the authenticated request |
25 | | - response = requests.get(api_url, headers=headers) |
26 | | - if response.status_code == 200: |
27 | | - # Extracting the number of stars |
28 | | - repo_data = response.json() |
29 | | - stars = repo_data.get("stargazers_count", 0) |
30 | | - owner_avatar_url = repo_data['owner']['avatar_url'] |
31 | | - # image_url = get_first_image_url_from_readme(owner, repo) |
32 | | - description = repo_data.get('description') |
33 | | - if not description: |
34 | | - # Fetch README content |
35 | | - readme_url = f"https://api.github.com/repos/{owner}/{repo}/readme" |
36 | | - readme_info = requests.get(readme_url, headers=headers).json() |
37 | | - readme_content = readme_info.get('content', '') |
38 | | - readme_text = requests.get(readme_info['download_url']).text if 'download_url' in readme_info else "" |
39 | | - paragraphs = readme_text.split('\n\n') |
40 | | - # Keep only the first two paragraphs |
41 | | - first_two_paragraphs = paragraphs[:2] |
42 | | - description = '\n'.join(first_two_paragraphs) |
43 | | - |
44 | | - return { |
45 | | - "stars": stars, |
46 | | - "owner_avatar_url": owner_avatar_url, |
47 | | - 'description': description, |
48 | | - # "image_url": image_url |
49 | | - } |
50 | | - else: |
51 | | - print(f"Failed to retrieve repository data. Status Code: {response.status_code}") |
52 | | - return {} |
53 | 3 | import base64 |
54 | 4 | import re |
55 | 5 |
|
@@ -78,34 +28,6 @@ def get_first_image_url_from_readme(owner, repo): |
78 | 28 | else: |
79 | 29 | return "Error: Unable to fetch README information" |
80 | 30 |
|
81 | | -def clear_except_allowed_folder(path, allowedFolder): |
82 | | - """ |
83 | | - Clears everything in the specified path except for the allowedFolder. |
84 | | - |
85 | | - :param path: Path to the directory to clear. |
86 | | - :param allowedFolder: The name of the folder to keep. |
87 | | - """ |
88 | | - # Make sure the path is a directory |
89 | | - if not os.path.isdir(path): |
90 | | - print(f"The provided path {path} is not a directory.") |
91 | | - return |
92 | | - |
93 | | - # Iterate through items in the directory |
94 | | - for item in os.listdir(path): |
95 | | - item_path = os.path.join(path, item) |
96 | | - # Check if the current item is the allowedFolder |
97 | | - if item == allowedFolder: |
98 | | - continue # Skip the allowedFolder |
99 | | - |
100 | | - # If item is a directory, remove it and its contents |
101 | | - if os.path.isdir(item_path): |
102 | | - shutil.rmtree(item_path) |
103 | | - print(f"Removed directory: {item_path}") |
104 | | - # If item is a file, remove it |
105 | | - else: |
106 | | - os.remove(item_path) |
107 | | - print(f"Removed file: {item_path}") |
108 | | - |
109 | 31 | ######v2 |
110 | 32 | def get_repo_user_and_name(module_path): |
111 | 33 | command = ['git', 'config', '--get', 'remote.origin.url'] |
|
0 commit comments