Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ from github import Github, GithubException
|
|
3 |
import os
|
4 |
import requests
|
5 |
import re
|
|
|
6 |
|
7 |
# Za艂aduj token z pliku .env lub ustaw bezpo艣rednio
|
8 |
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
|
@@ -128,6 +129,19 @@ def extract_repo_info(url):
|
|
128 |
else:
|
129 |
return None, None
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
def github_tool(
|
133 |
action: str,
|
@@ -421,14 +435,20 @@ def github_tool(
|
|
421 |
for content in contents:
|
422 |
if content.type == "file":
|
423 |
file_content = content.decoded_content.decode()
|
|
|
424 |
file_analyses.append({
|
425 |
"name": content.name,
|
426 |
"path": content.path,
|
427 |
-
"
|
428 |
-
# Mo偶esz doda膰 tutaj analiz臋 zawarto艣ci pliku
|
429 |
})
|
430 |
# Formatowanie wyj艣cia analizy (mo偶na dostosowa膰)
|
431 |
-
analysis_md = "Analiza plik贸w repozytorium:\n" + "\n".join([
|
|
|
|
|
|
|
|
|
|
|
|
|
432 |
return analysis_md
|
433 |
|
434 |
except GithubException as e:
|
@@ -449,13 +469,20 @@ def github_tool(
|
|
449 |
for content in contents:
|
450 |
if content.type == "file":
|
451 |
file_content = get_file_content(owner, repo_name, content.path, branch)
|
|
|
452 |
file_analyses.append({
|
453 |
"name": content.name,
|
454 |
"path": content.path,
|
455 |
-
"
|
456 |
})
|
457 |
# Formatowanie wyj艣cia analizy (mo偶na dostosowa膰)
|
458 |
-
analysis_md = "Analiza zawarto艣ci plik贸w repozytorium:\n" + "\n".join([
|
|
|
|
|
|
|
|
|
|
|
|
|
459 |
return analysis_md
|
460 |
|
461 |
|
@@ -469,6 +496,7 @@ def github_tool(
|
|
469 |
except requests.exceptions.RequestException as e: # Dodana obs艂uga b艂臋d贸w request贸w
|
470 |
return f"**B艂膮d po艂膮czenia:** {str(e)}"
|
471 |
|
|
|
472 |
with gr.Blocks() as demo:
|
473 |
gr.Markdown("# Narz臋dzie GitHub Plugingit (Uproszczony Interfejs)")
|
474 |
|
|
|
3 |
import os
|
4 |
import requests
|
5 |
import re
|
6 |
+
from collections import Counter
|
7 |
|
8 |
# Za艂aduj token z pliku .env lub ustaw bezpo艣rednio
|
9 |
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
|
|
|
129 |
else:
|
130 |
return None, None
|
131 |
|
132 |
+
def analyze_file_content(content, file_path):
|
133 |
+
"""Analizuje zawarto艣膰 pliku i zwraca statystyki."""
|
134 |
+
lines = content.splitlines()
|
135 |
+
word_count = sum(len(line.split()) for line in lines)
|
136 |
+
line_count = len(lines)
|
137 |
+
file_extension = file_path.split('.')[-1].lower() if '.' in file_path else "unknown"
|
138 |
+
|
139 |
+
return {
|
140 |
+
"line_count": line_count,
|
141 |
+
"word_count": word_count,
|
142 |
+
"file_extension": file_extension,
|
143 |
+
}
|
144 |
+
|
145 |
|
146 |
def github_tool(
|
147 |
action: str,
|
|
|
435 |
for content in contents:
|
436 |
if content.type == "file":
|
437 |
file_content = content.decoded_content.decode()
|
438 |
+
analysis = analyze_file_content(file_content, content.path) # ANALIZA PLIKU
|
439 |
file_analyses.append({
|
440 |
"name": content.name,
|
441 |
"path": content.path,
|
442 |
+
"analysis": analysis, # DODAJEMY WYNIKI ANALIZY
|
|
|
443 |
})
|
444 |
# Formatowanie wyj艣cia analizy (mo偶na dostosowa膰)
|
445 |
+
analysis_md = "Analiza plik贸w repozytorium:\n" + "\n".join([
|
446 |
+
f"- **{f['path']}**:\n"
|
447 |
+
f" - Liczba linii: {f['analysis']['line_count']}\n"
|
448 |
+
f" - Liczba s艂贸w: {f['analysis']['word_count']}\n"
|
449 |
+
f" - Rozszerzenie pliku: {f['analysis']['file_extension']}"
|
450 |
+
for f in file_analyses
|
451 |
+
])
|
452 |
return analysis_md
|
453 |
|
454 |
except GithubException as e:
|
|
|
469 |
for content in contents:
|
470 |
if content.type == "file":
|
471 |
file_content = get_file_content(owner, repo_name, content.path, branch)
|
472 |
+
analysis = analyze_file_content(file_content, content.path) # ANALIZA PLIKU
|
473 |
file_analyses.append({
|
474 |
"name": content.name,
|
475 |
"path": content.path,
|
476 |
+
"analysis": analysis, # DODAJEMY WYNIKI ANALIZY
|
477 |
})
|
478 |
# Formatowanie wyj艣cia analizy (mo偶na dostosowa膰)
|
479 |
+
analysis_md = "Analiza zawarto艣ci plik贸w repozytorium:\n" + "\n".join([
|
480 |
+
f"- **{f['path']}**:\n"
|
481 |
+
f" - Liczba linii: {f['analysis']['line_count']}\n"
|
482 |
+
f" - Liczba s艂贸w: {f['analysis']['word_count']}\n"
|
483 |
+
f" - Rozszerzenie pliku: {f['analysis']['file_extension']}"
|
484 |
+
for f in file_analyses
|
485 |
+
])
|
486 |
return analysis_md
|
487 |
|
488 |
|
|
|
496 |
except requests.exceptions.RequestException as e: # Dodana obs艂uga b艂臋d贸w request贸w
|
497 |
return f"**B艂膮d po艂膮czenia:** {str(e)}"
|
498 |
|
499 |
+
|
500 |
with gr.Blocks() as demo:
|
501 |
gr.Markdown("# Narz臋dzie GitHub Plugingit (Uproszczony Interfejs)")
|
502 |
|