File size: 23,964 Bytes
ca1d775
 
 
 
8a3568a
e6483ce
ca1d775
 
 
 
 
dc11f97
 
 
 
 
 
 
 
 
 
 
 
d33998b
dc11f97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d33998b
dc11f97
 
 
 
 
 
d33998b
dc11f97
 
 
 
 
 
 
 
 
 
 
 
d33998b
dc11f97
 
 
 
 
 
 
 
 
d33998b
dc11f97
 
 
 
 
 
 
 
 
 
 
d33998b
dc11f97
 
 
 
 
 
 
 
 
d33998b
dc11f97
 
d33998b
dc11f97
41a6f7c
 
 
 
 
 
 
 
8a3568a
 
 
 
 
 
 
 
e6483ce
 
 
 
 
 
 
 
 
 
 
 
9f613f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8a3568a
 
dc11f97
9f613f2
 
 
ca1d775
9f613f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dc11f97
 
 
bbda96c
dc11f97
 
 
 
 
 
 
9f613f2
 
 
 
 
 
dc11f97
9f613f2
 
 
 
2f6a202
d33998b
2f6a202
 
 
 
 
d33998b
9f613f2
 
 
 
 
 
 
dc11f97
9f613f2
 
 
 
 
 
 
 
dc11f97
9f613f2
 
 
 
 
dc11f97
 
9f613f2
 
 
 
 
 
 
dc11f97
9f613f2
 
 
 
 
dc11f97
9f613f2
 
 
 
 
 
dc11f97
9f613f2
 
 
 
 
dc11f97
 
 
 
9f613f2
 
 
 
 
dc11f97
9f613f2
 
 
 
 
dc11f97
 
 
 
9f613f2
 
 
 
 
 
 
 
dc11f97
9f613f2
 
 
 
 
 
dc11f97
9f613f2
 
 
 
 
 
 
dc11f97
9f613f2
 
 
 
 
 
 
dc11f97
9f613f2
 
 
 
 
dc11f97
 
 
 
9f613f2
 
 
 
 
dc11f97
9f613f2
 
 
 
 
dc11f97
 
 
 
9f613f2
 
 
 
c5a8b0c
 
 
 
 
dc11f97
 
 
 
483d941
 
 
 
 
dc11f97
 
 
 
 
 
 
 
 
 
483d941
dc11f97
 
8a3568a
41a6f7c
 
dc11f97
d33998b
8a3568a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e6483ce
8a3568a
 
 
e6483ce
8a3568a
dc11f97
e6483ce
 
 
 
 
 
 
dc11f97
8a3568a
 
16b192d
dc11f97
6f91c0b
 
 
 
 
 
 
 
 
 
 
 
bbda96c
6f91c0b
 
 
bbda96c
6f91c0b
bbda96c
e6483ce
 
 
 
 
 
 
dc11f97
9f613f2
92668cb
41e8014
ca1d775
1add323
9f613f2
1add323
 
dc11f97
ca1d775
abf04cf
dc11f97
bbda96c
abf04cf
 
 
 
dc11f97
abf04cf
 
dc11f97
abf04cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dc11f97
8a3568a
 
dc11f97
abf04cf
dc11f97
abf04cf
 
dc11f97
 
 
 
 
abf04cf
 
bbda96c
abf04cf
 
 
 
 
 
 
 
 
 
dc11f97
 
 
 
 
 
6fe2453
6fb9093
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dc11f97
 
 
 
6fb9093
 
dc11f97
6fb9093
d0437d1
bbda96c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
import gradio as gr
from github import Github, GithubException
import os
import requests
import re
from collections import Counter

# Za艂aduj token z pliku .env lub ustaw bezpo艣rednio
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
g = Github(GITHUB_TOKEN)

# Szablony projekt贸w - definicje jako s艂owniki:
PROJECT_TEMPLATES = {
    "flask": {
        "files": {
            "app.py": """from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello():
    return "Hello, Flask!"

if __name__ == '__main__':
    app.run(debug=True)""",
            "requirements.txt": "Flask",
            ".gitignore": "__pycache__/\n*.pyc\nvenv/\ninstance/"
        }
    },
    "react": {
        "files": {
            "package.json": """{
  "name": "react-app",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  },
  "dependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@vitejs/plugin-react": "^4.2.1",
    "vite": "^5.0.8"
  }}""",
            "vite.config.js": """import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
})""",
            "index.html": """<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/svg+xml" href="/vite.svg" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Vite + React</title>
  </head>
  <body>
    <div id="root"></div>
    <script type="module" src="/src/main.jsx"></script>
  </body>
</html>""",
            "src/main.jsx": """import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.jsx'
import './index.css'

ReactDOM.createRoot(document.getElementById('root')).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
)""",
            "src/App.jsx": """import React from 'react'
import './App.css'

function App() {
  return (
    <>
      <h1>Hello from React!</h1>
    </>
  )
}

export default App""",
            "src/index.css": """body {
  margin: 0;
  font-family: sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code {
  font-family: monospace;
}""",
            ".gitignore": "node_modules/\ndist/"
        }
    }}

def get_file_content(owner, repo_name, path, branch="main"):
    url = f"https://raw.githubusercontent.com/{owner}/{repo_name}/{branch}/{path}"
    response = requests.get(url)
    if response.status_code == 200:
        return response.text
    else:
        return f"B艂膮d pobierania pliku: {response.status_code}"

def extract_repo_info(url):
    """Wyodr臋bnia nazw臋 u偶ytkownika i repozytorium z linku GitHub."""
    match = re.search(r"github\.com/([^/]+)/([^/]+)", url)
    if match:
        return match.group(1), match.group(2)
    else:
        return None, None

def analyze_file_content(content, file_path):
    """Analizuje zawarto艣膰 pliku i zwraca statystyki."""
    lines = content.splitlines()
    word_count = sum(len(line.split()) for line in lines)
    line_count = len(lines)
    file_extension = file_path.split('.')[-1].lower() if '.' in file_path else "unknown"
    return {
        "line_count": line_count,
        "word_count": word_count,
        "file_extension": file_extension,
    }

def github_tool(
    action: str,
    repo_name: str = None,
    branch: str = "main",  # domy艣lna ga艂膮藕
    path: str = None,
    content: str = None,
    message: str = None,
    owner: str = None,
    vcs_url: str = None,
    title: str = None,
    body: str = None,
    base: str = None,
    head: str = None,
    issue_number: int = None,
    labels: str = None,  # etykiety oddzielone przecinkami
    tag: str = None,
    name: str = None,  # nazwa release
    file_url: str = None, # URL pliku do pobrania,
    repo_url: str = None,  # Link do repozytorium
    template_name: str = None, # Nazwa szablonu projektu
):
    """Narz臋dzie do zarz膮dzania repozytoriami GitHub."""
    user = g.get_user()
    try:
        if action == "import_repository":
            if not all([owner, repo_name, vcs_url]):
                raise ValueError(
                    "Brakuj膮ce parametry: owner, repo_name, vcs_url")
            # Sprawd藕, czy repozytorium ju偶 istnieje
            try:
                repo = user.get_repo(repo_name)
                return "Repozytorium o tej nazwie ju偶 istnieje."
            except GithubException:
                pass
            headers = {
                'Authorization': f'token {GITHUB_TOKEN}',
                'Accept': 'application/vnd.github.v3+json',
            }
            import_url = f'https://api.github.com/repos/{owner}/{repo_name}/import'
            payload = {'vcs_url': vcs_url, 'vcs': 'git'}
            response = requests.put(import_url, json=payload, headers=headers)
            if response.status_code == 201:
                return "Import repozytorium zosta艂 rozpocz臋ty."
            else:
                return f"B艂膮d importu: {response.status_code}, {response.json()}"
        elif action == "create_repository":
            if not repo_name:
                raise ValueError("Brakuj膮cy parametr: repo_name")
            repo = user.create_repo(name=repo_name)
            return f"Repozytorium **{repo_name}** utworzone! [Otw贸rz repozytorium]({repo.html_url})"
        elif action == "create_project_from_template":
            if not all([repo_name, template_name]):
                raise ValueError("Brakuj膮ce parametry: repo_name, template_name")
            if template_name not in PROJECT_TEMPLATES:
                raise ValueError(f"Nieznany szablon projektu: {template_name}. Dost臋pne szablony: {', '.join(PROJECT_TEMPLATES.keys())}")
            repo = user.create_repo(name=repo_name)
            template = PROJECT_TEMPLATES[template_name]
            for file_path, file_content in template["files"].items():
                repo.create_file(file_path, f"Utworzenie {file_path} z szablonu {template_name}", file_content, branch="main")
            return f"Repozytorium **{repo_name}** utworzone z szablonu **{template_name}**! [Otw贸rz repozytorium]({repo.html_url})"
        elif action == "create_file":
            if not all([repo_name, path, content, message]):
                raise ValueError(
                    "Brakuj膮ce parametry: repo_name, path, content, message")
            repo = user.get_repo(repo_name)
            repo.create_file(path, message, content, branch=branch)
            return f"Plik **`{path}`** utworzony w repozytorium **`{repo_name}`** na ga艂臋zi **`{branch}`**."
        elif action == "get_file":
            if not all([repo_name, path]):
                raise ValueError("Brakuj膮ce parametry: repo_name, path")
            repo = user.get_repo(repo_name)
            file_content = repo.get_contents(path, ref=branch)
            return f"Zawarto艣膰 pliku **`{path}`** z repozytorium **`{repo_name}`**:\n\n`\n{file_content.decoded_content.decode()}\n`" # Dodano formatowanie Markdown
        elif action == "get_file_content_by_url":
            if not file_url:
                raise ValueError("Brakuj膮cy parametr: file_url")
            response = requests.get(file_url)
            response.raise_for_status() # Sprawd藕 czy nie ma b艂臋du HTTP
            return f"Zawarto艣膰 pliku z URL **`{file_url}`**:\n\n`\n{response.text}\n`" # Dodano formatowanie Markdown
        elif action == "delete_file":
            if not all([repo_name, path]):
                raise ValueError("Brakuj膮ce parametry: repo_name, path")
            repo = user.get_repo(repo_name)
            file_contents = repo.get_contents(path, ref=branch)
            repo.delete_file(path, "Usuni臋cie pliku",
                             file_contents.sha, branch=branch)
            return f"Plik **`{path}`** usuni臋ty z repozytorium **`{repo_name}`** na ga艂臋zi **`{branch}`**."
        elif action == "update_file":
            if not all([repo_name, path, content, message]):
                raise ValueError(
                    "Brakuj膮ce parametry: repo_name, path, content, message")
            repo = user.get_repo(repo_name)
            file_contents = repo.get_contents(path, ref=branch)
            repo.update_file(path, message, content,
                             file_contents.sha, branch=branch)
            return f"Plik **`{path}`** zaktualizowany w repozytorium **`{repo_name}`** na ga艂臋zi **`{branch}`**."
        elif action == "list_branches":
            if not repo_name:
                raise ValueError("Brakuj膮cy parametr: repo_name")
            repo = user.get_repo(repo_name)
            branches = repo.get_branches()
            branch_list = "\n".join([f"- `{branch.name}`" for branch in branches]) # Formatowanie Markdown
            return f"Ga艂臋zie w repozytorium **`{repo_name}`**:\n{branch_list}"
        elif action == "create_branch":
            if not all([repo_name, base, head]):  # base jako 藕r贸d艂o, head jako nowa nazwa
                raise ValueError("Brakuj膮ce parametry: repo_name, base, head")
            repo = user.get_repo(repo_name)
            source_branch = repo.get_branch(base)
            repo.create_git_ref(ref=f"refs/heads/{head}",
                                 sha=source_branch.commit.sha)
            return f"Ga艂膮藕 **`{head}`** utworzona z **`{base}`** w repozytorium **`{repo_name}`**."
        elif action == "delete_branch":
            if not all([repo_name, branch]):
                raise ValueError("Brakuj膮ce parametry: repo_name, branch")
            repo = user.get_repo(repo_name)
            repo.get_git_ref(f"heads/{branch}").delete()
            return f"Ga艂膮藕 **`{branch}`** usuni臋ta z repozytorium **`{repo_name}`**."
        elif action == "create_pull_request":
            if not all([repo_name, title, body, base, head]):
                raise ValueError(
                    "Brakuj膮ce parametry: repo_name, title, body, base, head")
            repo = user.get_repo(repo_name)
            pr = repo.create_pull(title=title, body=body, base=base, head=head)
            return f"Pull request utworzony! [Otw贸rz Pull Request]({pr.html_url})"
        elif action == "list_open_pull_requests":
            if not repo_name:
                raise ValueError("Brakuj膮cy parametr: repo_name")
            repo = user.get_repo(repo_name)
            open_prs = repo.get_pulls(state='open')
            if not open_prs:
                return f"Brak otwartych pull request贸w w repozytorium **`{repo_name}`**."
            prs_list = "\n".join([f"- [{pr.title}]({pr.html_url})" for pr in open_prs]) # Formatowanie Markdown
            return f"Otwarte pull requesty w repozytorium **`{repo_name}`**:\n{prs_list}"
        elif action == "create_issue":
            if not all([repo_name, title, body]):
                raise ValueError("Brakuj膮ce parametry: repo_name, title, body")
            repo = user.get_repo(repo_name)
            issue = repo.create_issue(title=title, body=body)
            return f"Issue utworzone! [Otw贸rz Issue]({issue.html_url})"
        elif action == "list_issues":
            if not repo_name:
                raise ValueError("Brakuj膮cy parametr: repo_name")
            repo = user.get_repo(repo_name)
            issues = repo.get_issues(state='open')
            if not issues:
                return f"Brak otwartych issues w repozytorium **`{repo_name}`**."
            issues_list = "\n".join([f"- [{issue.title}]({issue.html_url})" for issue in issues]) # Formatowanie Markdown
            return f"Otwarte issues w repozytorium **`{repo_name}`**:\n{issues_list}"
        elif action == "add_label_to_issue":
            if not all([repo_name, issue_number, labels]):
                raise ValueError(
                    "Brakuj膮ce parametry: repo_name, issue_number, labels")
            repo = user.get_repo(repo_name)
            issue = repo.get_issue(number=int(issue_number))
            for label in labels.split(","):
                issue.add_to_labels(label.strip())
            return f"Etykiety **`{labels}`** dodane do issue **#{issue_number}** w repozytorium **`{repo_name}`**."
        elif action == "close_issue":
            if not all([repo_name, issue_number]):
                raise ValueError("Brakuj膮ce parametry: repo_name, issue_number")
            repo = user.get_repo(repo_name)
            issue = repo.get_issue(number=int(issue_number))
            issue.edit(state='closed')
            return f"Issue **#{issue_number}** zamkni臋te w repozytorium **`{repo_name}`**."
        elif action == "add_comment_to_issue":
            if not all([repo_name, issue_number, message]):  # message jako tre艣膰 komentarza
                raise ValueError(
                    "Brakuj膮ce parametry: repo_name, issue_number, message")
            repo = user.get_repo(repo_name)
            issue = repo.get_issue(number=int(issue_number))
            issue.create_comment(body=message)
            return f"Komentarz dodany do issue **#{issue_number}** w repozytorium **`{repo_name}`**."
        elif action == "create_release":
            if not all([repo_name, tag, name, message]):
                raise ValueError(
                    "Brakuj膮ce parametry: repo_name, tag, name, message")
            repo = user.get_repo(repo_name)
            release = repo.create_git_release(
                tag=tag, name=name, message=message)
            return f"Release **`{name}`** utworzone w repozytorium **`{repo_name}`**! [Otw贸rz Release]({release.html_url})"
        elif action == "list_releases":
            if not repo_name:
                raise ValueError("Brakuj膮cy parametr: repo_name")
            repo = user.get_repo(repo_name)
            releases = repo.get_releases()
            if not releases:
                return f"Brak release'贸w w repozytorium **`{repo_name}`**."
            releases_list = "\n".join([f"- [{release.tag_name}]({release.html_url})" for release in releases]) # Formatowanie Markdown
            return f"Releases w repozytorium **`{repo_name}`**:\n{releases_list}"
        elif action == "fork_repository":
            if not repo_name:
                raise ValueError("Brakuj膮cy parametr: repo_name")
            repo = g.get_repo(repo_name)  # Pobierz repozytorium do forkowania
            fork = user.create_fork(repo)
            return f"Repozytorium **`{repo_name}`** zosta艂o zforkowane! [Otw贸rz fork]({fork.html_url})"
        elif action == "list_forks":
            if not repo_name:
                raise ValueError("Brakuj膮cy parametr: repo_name")
            repo = g.get_repo(repo_name)  # Pobierz repo, kt贸rego forki chcesz wy艣wietli膰
            forks = repo.get_forks()
            if not forks:
                return f"Brak fork贸w repozytorium **`{repo_name}`**."
            forks_list = "\n".join([f"- [{fork.full_name}]({fork.html_url})" for fork in forks]) # Formatowanie Markdown
            return f"Linki do fork贸w repozytorium **`{repo_name}`**:\n{forks_list}"
        elif action == "list_files":
            if not all([owner, repo_name]):
                raise ValueError("Brakuj膮ce parametry: owner, repo_name")
            repo = g.get_repo(f"{owner}/{repo_name}")
            # Dodaj obs艂ug臋 pustej 艣cie偶ki:
            if not path:
                contents = repo.get_contents("")  # Pobierz zawarto艣膰 g艂贸wnego katalogu
            else:
                contents = repo.get_contents(path)
            if not contents:
                return f"Brak plik贸w w 艣cie偶ce **`{path}`** repozytorium **`{repo_name}`**." # Komunikat, gdy brak plik贸w
            files_list = "\n".join([f"- [{content.name}]({content.download_url})" for content in contents]) # Formatowanie Markdown
            return f"Pliki w 艣cie偶ce **`{path}`** repozytorium **`{repo_name}`**:\n{files_list}"
        elif action == "get_repository_info":
            if not all([owner, repo_name]):
                raise ValueError("Brakuj膮ce parametry: owner, repo_name")
            repo = g.get_repo(f"{owner}/{repo_name}")
            info = {
                "Nazwa": repo.name,
                "Opis": repo.description,
                "URL": repo.html_url,
                "W艂a艣ciciel": repo.owner.login,
                "Ga艂膮藕 domy艣lna": repo.default_branch,
                "J臋zyk": repo.language,
                "Liczba gwiazdek": repo.stargazers_count,
                "Liczba fork贸w": repo.forks_count,
                "Utworzone": str(repo.created_at), # Konwersja datetime na string
                "Ostatnia aktualizacja": str(repo.updated_at) # Konwersja datetime na string
            }
            info_md = "\n".join([f"- **{key}**: {value}" for key, value in info.items()]) # Formatowanie Markdown
            return f"Informacje o repozytorium **`{repo_name}`**:\n{info_md}"
        elif action == "get_file_content":
            if not all([owner, repo_name, path]):
                raise ValueError("Brakuj膮ce parametry: owner, repo_name, path")
            content_text = get_file_content(owner, repo_name, path, branch)
            return f"Zawarto艣膰 pliku **`{path}`** z repozytorium **`{repo_name}`**:\n\n`\n{content_text}\n`" # Dodano formatowanie Markdown
        elif action == "analyze_repository_by_url":
            if not repo_url:
                raise ValueError("Brakuj膮cy parametr: repo_url")
            owner, repo_name = extract_repo_info(repo_url)
            if not owner or not repo_name:
                raise ValueError("Nieprawid艂owy link do repozytorium")
            try:
                repo = g.get_repo(f"{owner}/{repo_name}")
                # Pobierz list臋 plik贸w i katalog贸w
                contents = repo.get_contents("")
                # Iteruj po li艣cie i pobieraj zawarto艣膰 plik贸w
                file_analyses = []
                for content in contents:
                    if content.type == "file":
                        file_content = content.decoded_content.decode()
                        analysis = analyze_file_content(file_content, content.path) # ANALIZA PLIKU
                        file_analyses.append({
                            "name": content.name,
                            "path": content.path,
                            "analysis": analysis, # DODAJEMY WYNIKI ANALIZY
                        })
                # Formatowanie wyj艣cia analizy (mo偶na dostosowa膰)
                analysis_md = "Analiza plik贸w repozytorium:\n" + "\n".join([
                    f"- **{f['path']}**:\n"
                    f"  - Liczba linii: {f['analysis']['line_count']}\n"
                    f"  - Liczba s艂贸w: {f['analysis']['word_count']}\n"
                    f"  - Rozszerzenie pliku: {f['analysis']['file_extension']}"
                    for f in file_analyses
                ])
                return analysis_md
            except GithubException as e:
                return f"B艂膮d GitHub: {str(e)}"
            raise ValueError(f"Nieznana akcja: {action}") # Correctly placed for unknown action handling

        elif action == "analyze_repository_content":
            if not all([owner, repo_name]):
                raise ValueError("Brakuj膮ce parametry: owner, repo_name")
            try:
                repo = g.get_repo(f"{owner}/{repo_name}")
                # Pobierz list臋 plik贸w i katalog贸w
                contents = repo.get_contents("")
                file_analyses = []
                # Iteruj po li艣cie i pobieraj zawarto艣膰 plik贸w
                for content in contents:
                    if content.type == "file":
                        file_content = get_file_content(owner, repo_name, content.path, branch)
                        analysis = analyze_file_content(file_content, content.path)
                        file_analyses.append({
                            "name": content.name,
                            "path": content.path,
                            "analysis": analysis,
                        })
                # Formatowanie wyj艣cia analizy
                analysis_md = "Analiza zawarto艣ci plik贸w repozytorium:\n" + "\n".join([
                    f"- **{f['path']}**:\n"
                    f"  - Liczba linii: {f['analysis']['line_count']}\n"
                    f"  - Liczba s艂贸w: {f['analysis']['word_count']}\n"
                    f"  - Rozszerzenie pliku: {f['analysis']['file_extension']}"
                    for f in file_analyses
                ])
                return analysis_md
        else:
            finally ValueError(f"Nieznana akcja: {action}")
            
    except GithubException as e:
        return f"**B艂膮d GitHub:** {str(e)}"
    except ValueError as e:
        return f"**B艂膮d:** {str(e)}"
    except requests.exceptions.RequestException as e:
        return f"**B艂膮d po艂膮czenia:** {str(e)}"

with gr.Blocks() as demo:
    gr.Markdown("# Narz臋dzie GitHub Plugingit (Uproszczony Interfejs)")
    with gr.Column():
        action = gr.Dropdown(
            choices=[
                "import_repository",
                "create_repository",
                "create_project_from_template",
                "create_file",
                "get_file",
                "get_file_content_by_url",
                "delete_file",
                "update_file",
                "list_branches",
                "create_branch",
                "delete_branch",
                "create_pull_request",
                "list_open_pull_requests",
                "create_issue",
                "list_issues",
                "add_label_to_issue",
                "close_issue",
                "add_comment_to_issue",
                "create_release",
                "list_releases",
                "fork_repository",
                "list_forks",
                "list_files",
                "get_repository_info",
                "get_file_content",
                "analyze_repository_by_url",
                "analyze_repository_content",
            ],
            label="Wybierz akcj臋",
        )
        repo_name = gr.Textbox(label="Nazwa repozytorium")
        template_name = gr.Dropdown(
            choices=list(PROJECT_TEMPLATES.keys()),
            label="Szablon projektu",
            allow_none=True,
        )
        branch = gr.Textbox(label="Ga艂膮藕", value="main")
        path = gr.Textbox(label="艢cie偶ka do pliku")
        content = gr.Code(label="Zawarto艣膰 pliku", lines=5, language='python')
        message = gr.Textbox(label="Wiadomo艣膰/Komentarz")
        owner = gr.Textbox(label="W艂a艣ciciel")
        vcs_url = gr.Textbox(label="URL VCS")
        title = gr.Textbox(label="Tytu艂")
        body = gr.Textbox(label="Tre艣膰")
        base = gr.Textbox(label="Ga艂膮藕 bazowa")
        head = gr.Textbox(label="Ga艂膮藕 docelowa/Nowa ga艂膮藕")
        issue_number = gr.Number(label="Numer issue", precision=0)
        labels = gr.Textbox(label="Etykiety (oddzielone przecinkami)")
        tag = gr.Textbox(label="Tag")
        release_name = gr.Textbox(label="Nazwa release")
        file_url = gr.Textbox(label="URL pliku")
        repo_url = gr.Textbox(label="Link do repozytorium")

    run_button = gr.Button("Wykonaj")
    output = gr.Markdown(label="Wynik")

    run_button.click(
        github_tool,
        inputs=[
            action,
            repo_name,
            branch,
            path,
            content,
            message,
            owner,
            vcs_url,
            title,
            body,
            base,
            head,
            issue_number,
            labels,
            tag,
            release_name,
            file_url,
            repo_url,
            template_name,
        ],
        outputs=output,
        api_name="github_tool" # API NAME JEST KLUCZOWE!
    )

demo.launch()