Spaces:
Runtime error
Runtime error
Commit
·
14ba0dd
1
Parent(s):
1d05a4d
Update app.py
Browse files
app.py
CHANGED
@@ -4,15 +4,17 @@ from github import Github
|
|
4 |
from github import GithubException
|
5 |
|
6 |
# Set up the Streamlit app
|
7 |
-
st.set_page_config(page_title="GitHub File Search", page_icon=":mag_right:")
|
8 |
|
9 |
# Retrieve the GitHub API token from the environment variable
|
10 |
-
access_token = os.environ["
|
11 |
|
12 |
# Define a function to get all the repositories that contain a file with the given name
|
13 |
def get_repositories_with_file(filename):
|
14 |
-
#
|
15 |
g = Github(access_token)
|
|
|
|
|
16 |
query = f"filename:{filename}"
|
17 |
repositories = g.search_repositories(query=query, sort="stars", order="desc")
|
18 |
|
@@ -21,24 +23,18 @@ def get_repositories_with_file(filename):
|
|
21 |
|
22 |
# Loop through the repositories
|
23 |
for repo in repositories:
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
except GithubException as e:
|
37 |
-
# Catch the exception if the file is not found in the repository
|
38 |
-
if e.status == 404:
|
39 |
-
st.warning(f"File '{filename}' not found in repository '{repo.full_name}'.")
|
40 |
-
else:
|
41 |
-
st.error(f"Error occurred while searching for file '{filename}' in repository '{repo.full_name}': {str(e)}")
|
42 |
|
43 |
# Return the repository information
|
44 |
return repo_info
|
|
|
4 |
from github import GithubException
|
5 |
|
6 |
# Set up the Streamlit app
|
7 |
+
st.set_page_config(page_title="GitHub File Search", page_icon=":mag_right:", theme="dark")
|
8 |
|
9 |
# Retrieve the GitHub API token from the environment variable
|
10 |
+
access_token = os.environ["GITHUB_TOKEN"]
|
11 |
|
12 |
# Define a function to get all the repositories that contain a file with the given name
|
13 |
def get_repositories_with_file(filename):
|
14 |
+
# Create a GitHub client
|
15 |
g = Github(access_token)
|
16 |
+
|
17 |
+
# Search for the file on GitHub
|
18 |
query = f"filename:{filename}"
|
19 |
repositories = g.search_repositories(query=query, sort="stars", order="desc")
|
20 |
|
|
|
23 |
|
24 |
# Loop through the repositories
|
25 |
for repo in repositories:
|
26 |
+
# Get the contents of the repository
|
27 |
+
contents = repo.get_contents("")
|
28 |
+
|
29 |
+
# Check if the repository contains a file with the given name
|
30 |
+
for content in contents:
|
31 |
+
if content.name == filename:
|
32 |
+
repo_info.append({
|
33 |
+
"name": repo.name,
|
34 |
+
"description": repo.description,
|
35 |
+
"url": repo.html_url
|
36 |
+
})
|
37 |
+
break
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# Return the repository information
|
40 |
return repo_info
|