adowu commited on
Commit
dc11f97
verified
1 Parent(s): 6f91c0b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +211 -64
app.py CHANGED
@@ -8,6 +8,110 @@ import re
8
  GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
9
  g = Github(GITHUB_TOKEN)
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  def get_file_content(owner, repo_name, path, branch="main"):
12
  url = f"https://raw.githubusercontent.com/{owner}/{repo_name}/{branch}/{path}"
13
  response = requests.get(url)
@@ -44,6 +148,7 @@ def github_tool(
44
  name: str = None, # nazwa release
45
  file_url: str = None, # URL pliku do pobrania,
46
  repo_url: str = None, # Link do repozytorium
 
47
  ):
48
  """Narz臋dzie do zarz膮dzania repozytoriami GitHub."""
49
  user = g.get_user()
@@ -76,7 +181,20 @@ def github_tool(
76
  if not repo_name:
77
  raise ValueError("Brakuj膮cy parametr: repo_name")
78
  repo = user.create_repo(name=repo_name)
79
- return f"Repozytorium {repo_name} utworzone: {repo.html_url}"
 
 
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  elif action == "create_file":
82
  if not all([repo_name, path, content, message]):
@@ -84,21 +202,21 @@ def github_tool(
84
  "Brakuj膮ce parametry: repo_name, path, content, message")
85
  repo = user.get_repo(repo_name)
86
  repo.create_file(path, message, content, branch=branch)
87
- return f"Plik {path} utworzony w {repo_name} na ga艂臋zi {branch}"
88
 
89
  elif action == "get_file":
90
  if not all([repo_name, path]):
91
  raise ValueError("Brakuj膮ce parametry: repo_name, path")
92
  repo = user.get_repo(repo_name)
93
  file_content = repo.get_contents(path, ref=branch)
94
- return file_content.decoded_content.decode() # Zdekoduj zawarto艣膰 pliku i zwr贸膰 jako string
95
 
96
  elif action == "get_file_content_by_url":
97
  if not file_url:
98
  raise ValueError("Brakuj膮cy parametr: file_url")
99
  response = requests.get(file_url)
100
  response.raise_for_status() # Sprawd藕 czy nie ma b艂臋du HTTP
101
- return response.text
102
 
103
  elif action == "delete_file":
104
  if not all([repo_name, path]):
@@ -107,7 +225,7 @@ def github_tool(
107
  file_contents = repo.get_contents(path, ref=branch)
108
  repo.delete_file(path, "Usuni臋cie pliku",
109
  file_contents.sha, branch=branch)
110
- return f"Plik {path} usuni臋ty z {repo_name} na ga艂臋zi {branch}"
111
 
112
  elif action == "update_file":
113
  if not all([repo_name, path, content, message]):
@@ -117,14 +235,15 @@ def github_tool(
117
  file_contents = repo.get_contents(path, ref=branch)
118
  repo.update_file(path, message, content,
119
  file_contents.sha, branch=branch)
120
- return f"Plik {path} zaktualizowany w {repo_name} na ga艂臋zi {branch}"
121
 
122
  elif action == "list_branches":
123
  if not repo_name:
124
  raise ValueError("Brakuj膮cy parametr: repo_name")
125
  repo = user.get_repo(repo_name)
126
  branches = repo.get_branches()
127
- return [branch.name for branch in branches]
 
128
 
129
  elif action == "create_branch":
130
  if not all([repo_name, base, head]): # base jako 藕r贸d艂o, head jako nowa nazwa
@@ -133,14 +252,14 @@ def github_tool(
133
  source_branch = repo.get_branch(base)
134
  repo.create_git_ref(ref=f"refs/heads/{head}",
135
  sha=source_branch.commit.sha)
136
- return f"Ga艂膮藕 {head} utworzona z {base} w {repo_name}"
137
 
138
  elif action == "delete_branch":
139
  if not all([repo_name, branch]):
140
  raise ValueError("Brakuj膮ce parametry: repo_name, branch")
141
  repo = user.get_repo(repo_name)
142
  repo.get_git_ref(f"heads/{branch}").delete()
143
- return f"Ga艂膮藕 {branch} usuni臋ta z {repo_name}"
144
 
145
  elif action == "create_pull_request":
146
  if not all([repo_name, title, body, base, head]):
@@ -148,28 +267,34 @@ def github_tool(
148
  "Brakuj膮ce parametry: repo_name, title, body, base, head")
149
  repo = user.get_repo(repo_name)
150
  pr = repo.create_pull(title=title, body=body, base=base, head=head)
151
- return f"Pull request utworzony: {pr.html_url}"
152
 
153
  elif action == "list_open_pull_requests":
154
  if not repo_name:
155
  raise ValueError("Brakuj膮cy parametr: repo_name")
156
  repo = user.get_repo(repo_name)
157
  open_prs = repo.get_pulls(state='open')
158
- return [{'title': pr.title, 'url': pr.html_url} for pr in open_prs]
 
 
 
159
 
160
  elif action == "create_issue":
161
  if not all([repo_name, title, body]):
162
  raise ValueError("Brakuj膮ce parametry: repo_name, title, body")
163
  repo = user.get_repo(repo_name)
164
  issue = repo.create_issue(title=title, body=body)
165
- return f"Issue utworzone: {issue.html_url}"
166
 
167
  elif action == "list_issues":
168
  if not repo_name:
169
  raise ValueError("Brakuj膮cy parametr: repo_name")
170
  repo = user.get_repo(repo_name)
171
  issues = repo.get_issues(state='open')
172
- return [{'title': issue.title, 'url': issue.html_url} for issue in issues]
 
 
 
173
 
174
  elif action == "add_label_to_issue":
175
  if not all([repo_name, issue_number, labels]):
@@ -179,7 +304,7 @@ def github_tool(
179
  issue = repo.get_issue(number=int(issue_number))
180
  for label in labels.split(","):
181
  issue.add_to_labels(label.strip())
182
- return f"Etykiety dodane do issue #{issue_number} w {repo_name}"
183
 
184
  elif action == "close_issue":
185
  if not all([repo_name, issue_number]):
@@ -187,7 +312,7 @@ def github_tool(
187
  repo = user.get_repo(repo_name)
188
  issue = repo.get_issue(number=int(issue_number))
189
  issue.edit(state='closed')
190
- return f"Issue #{issue_number} zamkni臋te w {repo_name}"
191
 
192
  elif action == "add_comment_to_issue":
193
  if not all([repo_name, issue_number, message]): # message jako tre艣膰 komentarza
@@ -196,7 +321,7 @@ def github_tool(
196
  repo = user.get_repo(repo_name)
197
  issue = repo.get_issue(number=int(issue_number))
198
  issue.create_comment(body=message)
199
- return f"Komentarz dodany do issue #{issue_number} w {repo_name}"
200
 
201
  elif action == "create_release":
202
  if not all([repo_name, tag, name, message]):
@@ -205,67 +330,78 @@ def github_tool(
205
  repo = user.get_repo(repo_name)
206
  release = repo.create_git_release(
207
  tag=tag, name=name, message=message)
208
- return f"Release {name} utworzone w {repo_name}: {release.html_url}"
209
 
210
  elif action == "list_releases":
211
  if not repo_name:
212
  raise ValueError("Brakuj膮cy parametr: repo_name")
213
  repo = user.get_repo(repo_name)
214
  releases = repo.get_releases()
215
- return [{'tag_name': release.tag_name, 'url': release.html_url} for release in releases]
 
 
 
216
 
217
  elif action == "fork_repository":
218
  if not repo_name:
219
  raise ValueError("Brakuj膮cy parametr: repo_name")
220
  repo = g.get_repo(repo_name) # Pobierz repozytorium do forkowania
221
  fork = user.create_fork(repo)
222
- return f"Fork repozytorium utworzony: {fork.html_url}"
223
 
224
  elif action == "list_forks":
225
  if not repo_name:
226
  raise ValueError("Brakuj膮cy parametr: repo_name")
227
  repo = g.get_repo(repo_name) # Pobierz repo, kt贸rego forki chcesz wy艣wietli膰
228
  forks = repo.get_forks()
229
- return [{'full_name': fork.full_name, 'url': fork.html_url} for fork in forks]
 
 
 
230
 
231
  elif action == "list_files":
232
  if not all([owner, repo_name]):
233
  raise ValueError("Brakuj膮ce parametry: owner, repo_name")
234
  repo = g.get_repo(f"{owner}/{repo_name}")
235
-
236
  # Dodaj obs艂ug臋 pustej 艣cie偶ki:
237
  if not path:
238
  contents = repo.get_contents("") # Pobierz zawarto艣膰 g艂贸wnego katalogu
239
  else:
240
  contents = repo.get_contents(path)
241
 
242
- files = [{'name': content.name, 'path': content.path,
243
- 'download_url': content.download_url} for content in contents]
244
- return files
245
-
 
 
246
  elif action == "get_repository_info":
247
  if not all([owner, repo_name]):
248
  raise ValueError("Brakuj膮ce parametry: owner, repo_name")
249
  repo = g.get_repo(f"{owner}/{repo_name}")
250
  info = {
251
- "nazwa": repo.name,
252
- "opis": repo.description,
253
- "url": repo.html_url,
254
- "w艂a艣ciciel": repo.owner.login,
255
- "ga艂膮藕 domy艣lna": repo.default_branch,
256
- "j臋zyk": repo.language,
257
- "liczba gwiazdek": repo.stargazers_count,
258
- "liczba fork贸w": repo.forks_count,
259
- "utworzone": repo.created_at,
260
- "ostatnia aktualizacja": repo.updated_at
261
  }
262
- return info # Zwraca s艂ownik z informacjami
263
-
 
 
264
  elif action == "get_file_content":
265
  if not all([owner, repo_name, path]):
266
  raise ValueError("Brakuj膮ce parametry: owner, repo_name, path")
267
- return get_file_content(owner, repo_name, path, branch)
268
-
 
269
  elif action == "analyze_repository_by_url":
270
  if not repo_url:
271
  raise ValueError("Brakuj膮cy parametr: repo_url")
@@ -291,11 +427,13 @@ def github_tool(
291
  "content": file_content,
292
  # Mo偶esz doda膰 tutaj analiz臋 zawarto艣ci pliku
293
  })
294
- return file_analyses
 
 
295
 
296
  except GithubException as e:
297
  return f"B艂膮d GitHub: {str(e)}"
298
-
299
  elif action == "analyze_repository_content":
300
  if not all([owner, repo_name]):
301
  raise ValueError("Brakuj膮ce parametry: owner, repo_name")
@@ -316,30 +454,34 @@ def github_tool(
316
  "path": content.path,
317
  "content": file_content,
318
  })
319
- return file_analyses
320
-
321
- except GithubException as e:
322
- return f"B艂膮d GitHub: {str(e)}"
323
 
324
 
325
  else:
326
  raise ValueError(f"Nieznana akcja: {action}")
327
 
328
  except GithubException as e:
329
- return f"B艂膮d GitHub: {str(e)}"
330
  except ValueError as e:
331
- return f"B艂膮d: {str(e)}"
 
 
332
 
333
 
334
  with gr.Blocks() as demo:
335
- with gr.Row():
 
 
336
  action = gr.Dropdown(
337
  choices=[
338
  "import_repository",
339
  "create_repository",
 
340
  "create_file",
341
  "get_file",
342
- "get_file_content_by_url",
343
  "delete_file",
344
  "update_file",
345
  "list_branches",
@@ -357,17 +499,22 @@ with gr.Blocks() as demo:
357
  "fork_repository",
358
  "list_forks",
359
  "list_files",
360
- "get_repository_info",
361
  "get_file_content",
362
  "analyze_repository_by_url",
363
- "analyze_repository_content", # Nowa akcja
364
  ],
365
- label="Akcja",
366
  )
367
  repo_name = gr.Textbox(label="Nazwa repozytorium")
 
 
 
 
 
368
  branch = gr.Textbox(label="Ga艂膮藕", value="main")
369
  path = gr.Textbox(label="艢cie偶ka do pliku")
370
- content = gr.Textbox(label="Zawarto艣膰 pliku")
371
  message = gr.Textbox(label="Wiadomo艣膰/Komentarz")
372
  owner = gr.Textbox(label="W艂a艣ciciel")
373
  vcs_url = gr.Textbox(label="URL VCS")
@@ -378,13 +525,12 @@ with gr.Blocks() as demo:
378
  issue_number = gr.Number(label="Numer issue", precision=0)
379
  labels = gr.Textbox(label="Etykiety (oddzielone przecinkami)")
380
  tag = gr.Textbox(label="Tag")
381
- release_name = gr.Textbox(label="Nazwa release") # Zmieniona nazwa
382
- file_url = gr.Textbox(label="URL pliku") # Dodane pole
383
- repo_url = gr.Textbox(label="Link do repozytorium") # Dodane pole
384
-
385
- with gr.Row():
386
- run_button = gr.Button("Wykonaj")
387
- output = gr.Textbox(label="Wynik")
388
 
389
  run_button.click(
390
  github_tool,
@@ -404,12 +550,13 @@ with gr.Blocks() as demo:
404
  issue_number,
405
  labels,
406
  tag,
407
- release_name, # U偶ycie zmienionej nazwy
408
- file_url, # Dodany argument
409
- repo_url, # Dodany argument
 
410
  ],
411
  outputs=output,
412
- api_name="github_tool"
413
  )
414
 
415
  demo.launch()
 
8
  GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
9
  g = Github(GITHUB_TOKEN)
10
 
11
+ # Szablony projekt贸w - definicje jako s艂owniki:
12
+ PROJECT_TEMPLATES = {
13
+ "flask": {
14
+ "files": {
15
+ "app.py": """from flask import Flask
16
+
17
+ app = Flask(__name__)
18
+
19
+ @app.route('/')
20
+ def hello():
21
+ return "Hello, Flask!"
22
+
23
+ if __name__ == '__main__':
24
+ app.run(debug=True)
25
+ """,
26
+ "requirements.txt": "Flask",
27
+ ".gitignore": "__pycache__/\n*.pyc\nvenv/\ninstance/"
28
+ }
29
+ },
30
+ "react": {
31
+ "files": {
32
+ "package.json": """{
33
+ "name": "react-app",
34
+ "private": true,
35
+ "version": "0.0.0",
36
+ "type": "module",
37
+ "scripts": {
38
+ "dev": "vite",
39
+ "build": "vite build",
40
+ "preview": "vite preview"
41
+ },
42
+ "dependencies": {
43
+ "react": "^18.2.0",
44
+ "react-dom": "^18.2.0"
45
+ },
46
+ "devDependencies": {
47
+ "@vitejs/plugin-react": "^4.2.1",
48
+ "vite": "^5.0.8"
49
+ }
50
+ }
51
+ """,
52
+ "vite.config.js": """import { defineConfig } from 'vite'
53
+ import react from '@vitejs/plugin-react'
54
+
55
+ // https://vitejs.dev/config/
56
+ export default defineConfig({
57
+ plugins: [react()],
58
+ })
59
+ """,
60
+ "index.html": """<!doctype html>
61
+ <html lang="en">
62
+ <head>
63
+ <meta charset="UTF-8" />
64
+ <link rel="icon" type="image/svg+xml" href="/vite.svg" />
65
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
+ <title>Vite + React</title>
67
+ </head>
68
+ <body>
69
+ <div id="root"></div>
70
+ <script type="module" src="/src/main.jsx"></script>
71
+ </body>
72
+ </html>
73
+ """,
74
+ "src/main.jsx": """import React from 'react'
75
+ import ReactDOM from 'react-dom/client'
76
+ import App from './App.jsx'
77
+ import './index.css'
78
+
79
+ ReactDOM.createRoot(document.getElementById('root')).render(
80
+ <React.StrictMode>
81
+ <App />
82
+ </React.StrictMode>,
83
+ )
84
+ """,
85
+ "src/App.jsx": """import React from 'react'
86
+ import './App.css'
87
+
88
+ function App() {
89
+ return (
90
+ <>
91
+ <h1>Hello from React!</h1>
92
+ </>
93
+ )
94
+ }
95
+
96
+ export default App
97
+ """,
98
+ "src/index.css": """body {
99
+ margin: 0;
100
+ font-family: sans-serif;
101
+ -webkit-font-smoothing: antialiased;
102
+ -moz-osx-font-smoothing: grayscale;
103
+ }
104
+
105
+ code {
106
+ font-family: monospace;
107
+ }
108
+ """,
109
+ ".gitignore": "node_modules/\ndist/"
110
+ }
111
+ }
112
+ }
113
+
114
+
115
  def get_file_content(owner, repo_name, path, branch="main"):
116
  url = f"https://raw.githubusercontent.com/{owner}/{repo_name}/{branch}/{path}"
117
  response = requests.get(url)
 
148
  name: str = None, # nazwa release
149
  file_url: str = None, # URL pliku do pobrania,
150
  repo_url: str = None, # Link do repozytorium
151
+ template_name: str = None, # Nazwa szablonu projektu
152
  ):
153
  """Narz臋dzie do zarz膮dzania repozytoriami GitHub."""
154
  user = g.get_user()
 
181
  if not repo_name:
182
  raise ValueError("Brakuj膮cy parametr: repo_name")
183
  repo = user.create_repo(name=repo_name)
184
+ return f"Repozytorium **{repo_name}** utworzone! [Otw贸rz repozytorium]({repo.html_url})"
185
+
186
+ elif action == "create_project_from_template":
187
+ if not all([repo_name, template_name]):
188
+ raise ValueError("Brakuj膮ce parametry: repo_name, template_name")
189
+ if template_name not in PROJECT_TEMPLATES:
190
+ raise ValueError(f"Nieznany szablon projektu: {template_name}. Dost臋pne szablony: {', '.join(PROJECT_TEMPLATES.keys())}")
191
+
192
+ repo = user.create_repo(name=repo_name)
193
+ template = PROJECT_TEMPLATES[template_name]
194
+ for file_path, file_content in template["files"].items():
195
+ repo.create_file(file_path, f"Utworzenie {file_path} z szablonu {template_name}", file_content, branch="main")
196
+ return f"Repozytorium **{repo_name}** utworzone z szablonu **{template_name}**! [Otw贸rz repozytorium]({repo.html_url})"
197
+
198
 
199
  elif action == "create_file":
200
  if not all([repo_name, path, content, message]):
 
202
  "Brakuj膮ce parametry: repo_name, path, content, message")
203
  repo = user.get_repo(repo_name)
204
  repo.create_file(path, message, content, branch=branch)
205
+ return f"Plik **`{path}`** utworzony w repozytorium **`{repo_name}`** na ga艂臋zi **`{branch}`**."
206
 
207
  elif action == "get_file":
208
  if not all([repo_name, path]):
209
  raise ValueError("Brakuj膮ce parametry: repo_name, path")
210
  repo = user.get_repo(repo_name)
211
  file_content = repo.get_contents(path, ref=branch)
212
+ return f"Zawarto艣膰 pliku **`{path}`** z repozytorium **`{repo_name}`**:\n\n```\n{file_content.decoded_content.decode()}\n```" # Dodano formatowanie Markdown
213
 
214
  elif action == "get_file_content_by_url":
215
  if not file_url:
216
  raise ValueError("Brakuj膮cy parametr: file_url")
217
  response = requests.get(file_url)
218
  response.raise_for_status() # Sprawd藕 czy nie ma b艂臋du HTTP
219
+ return f"Zawarto艣膰 pliku z URL **`{file_url}`**:\n\n```\n{response.text}\n```" # Dodano formatowanie Markdown
220
 
221
  elif action == "delete_file":
222
  if not all([repo_name, path]):
 
225
  file_contents = repo.get_contents(path, ref=branch)
226
  repo.delete_file(path, "Usuni臋cie pliku",
227
  file_contents.sha, branch=branch)
228
+ return f"Plik **`{path}`** usuni臋ty z repozytorium **`{repo_name}`** na ga艂臋zi **`{branch}`**."
229
 
230
  elif action == "update_file":
231
  if not all([repo_name, path, content, message]):
 
235
  file_contents = repo.get_contents(path, ref=branch)
236
  repo.update_file(path, message, content,
237
  file_contents.sha, branch=branch)
238
+ return f"Plik **`{path}`** zaktualizowany w repozytorium **`{repo_name}`** na ga艂臋zi **`{branch}`**."
239
 
240
  elif action == "list_branches":
241
  if not repo_name:
242
  raise ValueError("Brakuj膮cy parametr: repo_name")
243
  repo = user.get_repo(repo_name)
244
  branches = repo.get_branches()
245
+ branch_list = "\n".join([f"- `{branch.name}`" for branch in branches]) # Formatowanie Markdown
246
+ return f"Ga艂臋zie w repozytorium **`{repo_name}`**:\n{branch_list}"
247
 
248
  elif action == "create_branch":
249
  if not all([repo_name, base, head]): # base jako 藕r贸d艂o, head jako nowa nazwa
 
252
  source_branch = repo.get_branch(base)
253
  repo.create_git_ref(ref=f"refs/heads/{head}",
254
  sha=source_branch.commit.sha)
255
+ return f"Ga艂膮藕 **`{head}`** utworzona z **`{base}`** w repozytorium **`{repo_name}`**."
256
 
257
  elif action == "delete_branch":
258
  if not all([repo_name, branch]):
259
  raise ValueError("Brakuj膮ce parametry: repo_name, branch")
260
  repo = user.get_repo(repo_name)
261
  repo.get_git_ref(f"heads/{branch}").delete()
262
+ return f"Ga艂膮藕 **`{branch}`** usuni臋ta z repozytorium **`{repo_name}`**."
263
 
264
  elif action == "create_pull_request":
265
  if not all([repo_name, title, body, base, head]):
 
267
  "Brakuj膮ce parametry: repo_name, title, body, base, head")
268
  repo = user.get_repo(repo_name)
269
  pr = repo.create_pull(title=title, body=body, base=base, head=head)
270
+ return f"Pull request utworzony! [Otw贸rz Pull Request]({pr.html_url})"
271
 
272
  elif action == "list_open_pull_requests":
273
  if not repo_name:
274
  raise ValueError("Brakuj膮cy parametr: repo_name")
275
  repo = user.get_repo(repo_name)
276
  open_prs = repo.get_pulls(state='open')
277
+ if not open_prs:
278
+ return f"Brak otwartych pull request贸w w repozytorium **`{repo_name}`**."
279
+ prs_list = "\n".join([f"- [{pr.title}]({pr.html_url})" for pr in open_prs]) # Formatowanie Markdown
280
+ return f"Otwarte pull requesty w repozytorium **`{repo_name}`**:\n{prs_list}"
281
 
282
  elif action == "create_issue":
283
  if not all([repo_name, title, body]):
284
  raise ValueError("Brakuj膮ce parametry: repo_name, title, body")
285
  repo = user.get_repo(repo_name)
286
  issue = repo.create_issue(title=title, body=body)
287
+ return f"Issue utworzone! [Otw贸rz Issue]({issue.html_url})"
288
 
289
  elif action == "list_issues":
290
  if not repo_name:
291
  raise ValueError("Brakuj膮cy parametr: repo_name")
292
  repo = user.get_repo(repo_name)
293
  issues = repo.get_issues(state='open')
294
+ if not issues:
295
+ return f"Brak otwartych issues w repozytorium **`{repo_name}`**."
296
+ issues_list = "\n".join([f"- [{issue.title}]({issue.html_url})" for issue in issues]) # Formatowanie Markdown
297
+ return f"Otwarte issues w repozytorium **`{repo_name}`**:\n{issues_list}"
298
 
299
  elif action == "add_label_to_issue":
300
  if not all([repo_name, issue_number, labels]):
 
304
  issue = repo.get_issue(number=int(issue_number))
305
  for label in labels.split(","):
306
  issue.add_to_labels(label.strip())
307
+ return f"Etykiety **`{labels}`** dodane do issue **#{issue_number}** w repozytorium **`{repo_name}`**."
308
 
309
  elif action == "close_issue":
310
  if not all([repo_name, issue_number]):
 
312
  repo = user.get_repo(repo_name)
313
  issue = repo.get_issue(number=int(issue_number))
314
  issue.edit(state='closed')
315
+ return f"Issue **#{issue_number}** zamkni臋te w repozytorium **`{repo_name}`**."
316
 
317
  elif action == "add_comment_to_issue":
318
  if not all([repo_name, issue_number, message]): # message jako tre艣膰 komentarza
 
321
  repo = user.get_repo(repo_name)
322
  issue = repo.get_issue(number=int(issue_number))
323
  issue.create_comment(body=message)
324
+ return f"Komentarz dodany do issue **#{issue_number}** w repozytorium **`{repo_name}`**."
325
 
326
  elif action == "create_release":
327
  if not all([repo_name, tag, name, message]):
 
330
  repo = user.get_repo(repo_name)
331
  release = repo.create_git_release(
332
  tag=tag, name=name, message=message)
333
+ return f"Release **`{name}`** utworzone w repozytorium **`{repo_name}`**! [Otw贸rz Release]({release.html_url})"
334
 
335
  elif action == "list_releases":
336
  if not repo_name:
337
  raise ValueError("Brakuj膮cy parametr: repo_name")
338
  repo = user.get_repo(repo_name)
339
  releases = repo.get_releases()
340
+ if not releases:
341
+ return f"Brak release'贸w w repozytorium **`{repo_name}`**."
342
+ releases_list = "\n".join([f"- [{release.tag_name}]({release.html_url})" for release in releases]) # Formatowanie Markdown
343
+ return f"Releases w repozytorium **`{repo_name}`**:\n{releases_list}"
344
 
345
  elif action == "fork_repository":
346
  if not repo_name:
347
  raise ValueError("Brakuj膮cy parametr: repo_name")
348
  repo = g.get_repo(repo_name) # Pobierz repozytorium do forkowania
349
  fork = user.create_fork(repo)
350
+ return f"Repozytorium **`{repo_name}`** zosta艂o zforkowane! [Otw贸rz fork]({fork.html_url})"
351
 
352
  elif action == "list_forks":
353
  if not repo_name:
354
  raise ValueError("Brakuj膮cy parametr: repo_name")
355
  repo = g.get_repo(repo_name) # Pobierz repo, kt贸rego forki chcesz wy艣wietli膰
356
  forks = repo.get_forks()
357
+ if not forks:
358
+ return f"Brak fork贸w repozytorium **`{repo_name}`**."
359
+ forks_list = "\n".join([f"- [{fork.full_name}]({fork.html_url})" for fork in forks]) # Formatowanie Markdown
360
+ return f"Linki do fork贸w repozytorium **`{repo_name}`**:\n{forks_list}"
361
 
362
  elif action == "list_files":
363
  if not all([owner, repo_name]):
364
  raise ValueError("Brakuj膮ce parametry: owner, repo_name")
365
  repo = g.get_repo(f"{owner}/{repo_name}")
366
+
367
  # Dodaj obs艂ug臋 pustej 艣cie偶ki:
368
  if not path:
369
  contents = repo.get_contents("") # Pobierz zawarto艣膰 g艂贸wnego katalogu
370
  else:
371
  contents = repo.get_contents(path)
372
 
373
+ if not contents:
374
+ return f"Brak plik贸w w 艣cie偶ce **`{path}`** repozytorium **`{repo_name}`**." # Komunikat, gdy brak plik贸w
375
+ files_list = "\n".join([f"- [{content.name}]({content.download_url})" for content in contents]) # Formatowanie Markdown
376
+ return f"Pliki w 艣cie偶ce **`{path}`** repozytorium **`{repo_name}`**:\n{files_list}"
377
+
378
+
379
  elif action == "get_repository_info":
380
  if not all([owner, repo_name]):
381
  raise ValueError("Brakuj膮ce parametry: owner, repo_name")
382
  repo = g.get_repo(f"{owner}/{repo_name}")
383
  info = {
384
+ "Nazwa": repo.name,
385
+ "Opis": repo.description,
386
+ "URL": repo.html_url,
387
+ "W艂a艣ciciel": repo.owner.login,
388
+ "Ga艂膮藕 domy艣lna": repo.default_branch,
389
+ "J臋zyk": repo.language,
390
+ "Liczba gwiazdek": repo.stargazers_count,
391
+ "Liczba fork贸w": repo.forks_count,
392
+ "Utworzone": str(repo.created_at), # Konwersja datetime na string
393
+ "Ostatnia aktualizacja": str(repo.updated_at) # Konwersja datetime na string
394
  }
395
+ info_md = "\n".join([f"- **{key}**: {value}" for key, value in info.items()]) # Formatowanie Markdown
396
+ return f"Informacje o repozytorium **`{repo_name}`**:\n{info_md}"
397
+
398
+
399
  elif action == "get_file_content":
400
  if not all([owner, repo_name, path]):
401
  raise ValueError("Brakuj膮ce parametry: owner, repo_name, path")
402
+ content_text = get_file_content(owner, repo_name, path, branch)
403
+ return f"Zawarto艣膰 pliku **`{path}`** z repozytorium **`{repo_name}`**:\n\n```\n{content_text}\n```" # Dodano formatowanie Markdown
404
+
405
  elif action == "analyze_repository_by_url":
406
  if not repo_url:
407
  raise ValueError("Brakuj膮cy parametr: repo_url")
 
427
  "content": file_content,
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([f"- **{f['path']}**: (pierwsze 100 znak贸w): `{f['content'][:100]}...`" for f in file_analyses])
432
+ return analysis_md
433
 
434
  except GithubException as e:
435
  return f"B艂膮d GitHub: {str(e)}"
436
+
437
  elif action == "analyze_repository_content":
438
  if not all([owner, repo_name]):
439
  raise ValueError("Brakuj膮ce parametry: owner, repo_name")
 
454
  "path": content.path,
455
  "content": file_content,
456
  })
457
+ # Formatowanie wyj艣cia analizy (mo偶na dostosowa膰)
458
+ analysis_md = "Analiza zawarto艣ci plik贸w repozytorium:\n" + "\n".join([f"- **{f['path']}**: (pierwsze 100 znak贸w): `{f['content'][:100]}...`" for f in file_analyses])
459
+ return analysis_md
 
460
 
461
 
462
  else:
463
  raise ValueError(f"Nieznana akcja: {action}")
464
 
465
  except GithubException as e:
466
+ return f"**B艂膮d GitHub:** {str(e)}" # Wyra藕niejszy komunikat b艂臋du
467
  except ValueError as e:
468
+ return f"**B艂膮d:** {str(e)}" # Wyra藕niejszy komunikat b艂臋du
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
 
473
  with gr.Blocks() as demo:
474
+ gr.Markdown("# Narz臋dzie GitHub Plugingit (Uproszczony Interfejs)")
475
+
476
+ with gr.Column(): # U偶ywamy Column zamiast Tab贸w
477
  action = gr.Dropdown(
478
  choices=[
479
  "import_repository",
480
  "create_repository",
481
+ "create_project_from_template",
482
  "create_file",
483
  "get_file",
484
+ "get_file_content_by_url",
485
  "delete_file",
486
  "update_file",
487
  "list_branches",
 
499
  "fork_repository",
500
  "list_forks",
501
  "list_files",
502
+ "get_repository_info",
503
  "get_file_content",
504
  "analyze_repository_by_url",
505
+ "analyze_repository_content",
506
  ],
507
+ label="Wybierz akcj臋",
508
  )
509
  repo_name = gr.Textbox(label="Nazwa repozytorium")
510
+ template_name = gr.Dropdown(
511
+ choices=list(PROJECT_TEMPLATES.keys()),
512
+ label="Szablon projektu",
513
+ allow_none=True,
514
+ )
515
  branch = gr.Textbox(label="Ga艂膮藕", value="main")
516
  path = gr.Textbox(label="艢cie偶ka do pliku")
517
+ content = gr.Code(label="Zawarto艣膰 pliku", lines=5, language='python') # Nadal Code, ale bez zb臋dnych opcji
518
  message = gr.Textbox(label="Wiadomo艣膰/Komentarz")
519
  owner = gr.Textbox(label="W艂a艣ciciel")
520
  vcs_url = gr.Textbox(label="URL VCS")
 
525
  issue_number = gr.Number(label="Numer issue", precision=0)
526
  labels = gr.Textbox(label="Etykiety (oddzielone przecinkami)")
527
  tag = gr.Textbox(label="Tag")
528
+ release_name = gr.Textbox(label="Nazwa release")
529
+ file_url = gr.Textbox(label="URL pliku")
530
+ repo_url = gr.Textbox(label="Link do repozytorium")
531
+
532
+ run_button = gr.Button("Wykonaj")
533
+ output = gr.Markdown(label="Wynik")
 
534
 
535
  run_button.click(
536
  github_tool,
 
550
  issue_number,
551
  labels,
552
  tag,
553
+ release_name,
554
+ file_url,
555
+ repo_url,
556
+ template_name,
557
  ],
558
  outputs=output,
559
+ api_name="github_tool" # API NAME JEST KLUCZOWE!
560
  )
561
 
562
  demo.launch()