Spaces:
Runtime error
Runtime error
Not-Grim-Refer
commited on
Commit
•
f1f576a
1
Parent(s):
e113367
Update app.py
Browse files
app.py
CHANGED
@@ -1,75 +1,70 @@
|
|
1 |
-
import os
|
2 |
import streamlit as st
|
3 |
from github import Github
|
4 |
-
from github import
|
5 |
-
|
6 |
|
7 |
-
|
8 |
-
|
9 |
|
10 |
-
|
11 |
-
access_token =
|
12 |
|
13 |
-
# Define a function to get all the repositories that contain a file with the given name
|
14 |
-
def get_repositories_with_file(filename):
|
15 |
-
# Create a GitHub client
|
16 |
-
g = Github(access_token)
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
|
|
|
|
|
23 |
repo_info = []
|
24 |
|
25 |
-
# Loop through the repositories
|
26 |
for repo in repositories:
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
# Check if the repository contains a file with the given name
|
31 |
-
for content in contents:
|
32 |
-
if content.name == filename:
|
33 |
repo_info.append({
|
34 |
"name": repo.name,
|
35 |
"description": repo.description,
|
36 |
"url": repo.html_url
|
37 |
})
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
return repo_info
|
42 |
|
43 |
-
|
44 |
def app():
|
45 |
-
# Set up the user interface
|
46 |
st.title("GitHub File Search")
|
47 |
st.write("Enter a file name to search for on GitHub:")
|
48 |
filename = st.text_input("File name")
|
49 |
-
|
50 |
if filename:
|
51 |
-
# Get the repositories with the file
|
52 |
repo_info = get_repositories_with_file(filename)
|
53 |
-
|
54 |
-
# Display the repository information
|
55 |
if len(repo_info) > 0:
|
56 |
st.success(f"Found {len(repo_info)} repositories with the file '{filename}':")
|
57 |
for repo in repo_info:
|
58 |
st.write(f"- **{repo['name']}**: {repo['description']}")
|
59 |
st.write(f" URL: [{repo['url']}]({repo['url']})")
|
60 |
else:
|
|
|
61 |
st.warning(f"No repositories found with the file '{filename}'.")
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
|
|
69 |
|
70 |
-
# Display the chart
|
71 |
-
st.plotly_chart(chart)
|
72 |
|
73 |
-
# Run the Streamlit app
|
74 |
if __name__ == "__main__":
|
75 |
-
app()
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from github import Github
|
3 |
+
from github import UnknownObjectException
|
4 |
+
import logging
|
5 |
|
6 |
+
logging.basicConfig(level=logging.INFO)
|
7 |
+
logger = logging.getLogger(__name__)
|
8 |
|
9 |
+
st.set_page_config(page_title="GitHub File Search", page_icon=":mag_right:")
|
10 |
+
access_token = "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"
|
11 |
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
def find_file(repo, path, filename):
|
14 |
+
contents = repo.get_contents(path)
|
15 |
+
for content in contents:
|
16 |
+
if content.type == "dir":
|
17 |
+
result = find_file(repo, content.path, filename)
|
18 |
+
if result:
|
19 |
+
return result
|
20 |
+
elif content.name == filename:
|
21 |
+
return content
|
22 |
+
return None
|
23 |
+
|
24 |
|
25 |
+
def get_repositories_with_file(filename):
|
26 |
+
g = Github(access_token)
|
27 |
+
repositories = g.search_repositories(query=f"filename:{filename}", sort="stars", order="desc")
|
28 |
repo_info = []
|
29 |
|
|
|
30 |
for repo in repositories:
|
31 |
+
try:
|
32 |
+
content = find_file(repo, "", filename)
|
33 |
+
if content:
|
|
|
|
|
|
|
34 |
repo_info.append({
|
35 |
"name": repo.name,
|
36 |
"description": repo.description,
|
37 |
"url": repo.html_url
|
38 |
})
|
39 |
+
except UnknownObjectException as e:
|
40 |
+
logger.warning(f"File '{filename}' not found in repository '{repo.full_name}'.")
|
41 |
+
st.warning(f"File '{filename}' not found in repository '{repo.full_name}'.")
|
42 |
return repo_info
|
43 |
|
44 |
+
|
45 |
def app():
|
|
|
46 |
st.title("GitHub File Search")
|
47 |
st.write("Enter a file name to search for on GitHub:")
|
48 |
filename = st.text_input("File name")
|
|
|
49 |
if filename:
|
|
|
50 |
repo_info = get_repositories_with_file(filename)
|
|
|
|
|
51 |
if len(repo_info) > 0:
|
52 |
st.success(f"Found {len(repo_info)} repositories with the file '{filename}':")
|
53 |
for repo in repo_info:
|
54 |
st.write(f"- **{repo['name']}**: {repo['description']}")
|
55 |
st.write(f" URL: [{repo['url']}]({repo['url']})")
|
56 |
else:
|
57 |
+
logger.warning(f"No repositories found with the file '{filename}'.")
|
58 |
st.warning(f"No repositories found with the file '{filename}'.")
|
59 |
|
60 |
+
st.sidebar.title("GitHub File Search Options")
|
61 |
+
show_logs = st.sidebar.checkbox("Show Logs")
|
62 |
+
if show_logs:
|
63 |
+
st.sidebar.subheader("Logs")
|
64 |
+
with open("app.log", "r") as log_file:
|
65 |
+
logs = log_file.read()
|
66 |
+
st.sidebar.text(logs)
|
67 |
|
|
|
|
|
68 |
|
|
|
69 |
if __name__ == "__main__":
|
70 |
+
app()
|