-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
400 lines (313 loc) Β· 13.4 KB
/
main.py
File metadata and controls
400 lines (313 loc) Β· 13.4 KB
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
"""
HubMind - GitHub Intelligent Agent
Main Entry Point
"""
import typer
from rich.console import Console
from rich.table import Table
from rich.panel import Panel
from rich.markdown import Markdown
from typing import Optional, List
import json
from src.agents.hubmind_agent import HubMindAgent
from src.agents.qa_agent import HubMindQAAgent
from src.utils.dashboard import DeveloperDashboard
from src.tools.github_trending import GitHubTrendingTool
from src.tools.github_pr import GitHubPRTool
from src.tools.github_issue import GitHubIssueTool
from config import Config
app = typer.Typer(help="HubMind - Your Intelligent GitHub Assistant")
console = Console()
@app.command()
def trending(
language: Optional[str] = typer.Option(None, "--language", "-l", help="Filter by programming language"),
since: str = typer.Option("daily", "--since", "-s", help="Time range: daily, weekly, monthly"),
limit: int = typer.Option(10, "--limit", help="Number of repos to show"),
):
"""Get trending GitHub repositories"""
console.print("[bold blue]π Fetching trending repositories...[/bold blue]")
try:
tool = GitHubTrendingTool()
repos = tool.get_trending_repos(language=language, since=since, limit=limit)
if not repos:
console.print("[yellow]No trending repositories found.[/yellow]")
return
# Create table
table = Table(title=f"π₯ Trending Repositories ({since})")
table.add_column("#", style="cyan", width=4)
table.add_column("Repository", style="magenta", width=30)
table.add_column("Stars", style="green", width=10)
table.add_column("Language", style="yellow", width=12)
table.add_column("Description", style="white", width=50)
for i, repo in enumerate(repos, 1):
desc = repo['description'][:47] + "..." if len(repo['description']) > 50 else repo['description']
table.add_row(
str(i),
repo['name'],
f"β {repo['stars']}",
repo['language'] or "N/A",
desc
)
console.print(table)
# Show summary
summary = tool.get_trending_summary(repos)
console.print("\n[bold]Summary:[/bold]")
console.print(Markdown(summary))
except Exception as e:
console.print(f"[red]Error: {str(e)}[/red]")
@app.command()
def prs(
repo: str = typer.Argument(..., help="Repository full name (owner/repo)"),
valuable: bool = typer.Option(False, "--valuable", "-v", help="Show only valuable PRs"),
limit: int = typer.Option(10, "--limit", help="Number of PRs to show"),
):
"""Get today's pull requests for a repository"""
console.print(f"[bold blue]π Fetching PRs for {repo}...[/bold blue]")
try:
tool = GitHubPRTool()
if valuable:
prs = tool.get_valuable_prs(repo, limit=limit)
title = f"π Most Valuable PRs - {repo}"
else:
prs = tool.get_today_prs(repo, limit=limit)
title = f"π Today's PRs - {repo}"
if not prs or "error" in prs[0]:
console.print(f"[yellow]No PRs found for {repo} today.[/yellow]")
return
# Create table
table = Table(title=title)
table.add_column("#", style="cyan", width=6)
table.add_column("Title", style="magenta", width=40)
table.add_column("Author", style="green", width=15)
table.add_column("State", style="yellow", width=8)
table.add_column("Comments", style="blue", width=10)
if valuable:
table.add_column("Score", style="red", width=8)
for i, pr in enumerate(prs, 1):
title_text = pr['title'][:37] + "..." if len(pr['title']) > 40 else pr['title']
row = [
f"#{pr['number']}",
title_text,
pr['author'],
pr['state'],
str(pr['comments'])
]
if valuable:
row.append(str(pr.get('value_score', 0)))
table.add_row(*row)
console.print(table)
# Show URLs
console.print("\n[bold]PR URLs:[/bold]")
for pr in prs[:5]:
console.print(f" β’ [#{pr['number']}]({pr['url']}) - {pr['title'][:50]}")
except Exception as e:
console.print(f"[red]Error: {str(e)}[/red]")
@app.command()
def analyze_pr(
repo: str = typer.Argument(..., help="Repository full name (owner/repo)"),
pr_number: int = typer.Argument(..., help="PR number"),
):
"""Analyze a specific pull request in detail"""
console.print(f"[bold blue]π Analyzing PR #{pr_number} in {repo}...[/bold blue]")
try:
tool = GitHubPRTool()
analysis = tool.analyze_pr(repo, pr_number)
if "error" in analysis:
console.print(f"[red]Error: {analysis['error']}[/red]")
return
# Display analysis
info = f"""
**PR #{analysis['number']}**: {analysis['title']}
**State**: {analysis['state']}
**Author**: {analysis['author']}
**Value Score**: {analysis['value_score']}
**Statistics**:
- Files Changed: {analysis['files_changed']}
- Additions: +{analysis['additions']}
- Deletions: -{analysis['deletions']}
- Comments: {analysis['comments']}
- Review Comments: {analysis['review_comments']}
**Reviews**:
- Total: {analysis['review_summary']['total']}
- Approved: {analysis['review_summary']['approved']}
- Changes Requested: {analysis['review_summary']['changes_requested']}
**Maintainer Participated**: {'Yes' if analysis['maintainer_participated'] else 'No'}
**URL**: {analysis['url']}
"""
console.print(Panel(Markdown(info), title="PR Analysis", border_style="green"))
# Show file changes
if analysis.get('file_details'):
console.print("\n[bold]Files Changed:[/bold]")
file_table = Table()
file_table.add_column("File", style="cyan")
file_table.add_column("Status", style="yellow")
file_table.add_column("Changes", style="green")
for file in analysis['file_details'][:10]:
file_table.add_row(
file['filename'],
file['status'],
f"+{file['additions']} -{file['deletions']}"
)
console.print(file_table)
except Exception as e:
console.print(f"[red]Error: {str(e)}[/red]")
@app.command()
def create_issue(
repo: str = typer.Argument(..., help="Repository full name (owner/repo)"),
text: str = typer.Argument(..., help="Issue description in natural language"),
assignees: Optional[str] = typer.Option(None, "--assignees", help="Comma-separated list of assignees"),
labels: Optional[str] = typer.Option(None, "--labels", help="Comma-separated list of labels"),
):
"""Create a GitHub issue from natural language"""
console.print(f"[bold blue]π Creating issue in {repo}...[/bold blue]")
try:
tool = GitHubIssueTool()
assignee_list = [a.strip() for a in assignees.split(",")] if assignees else None
label_list = [l.strip() for l in labels.split(",")] if labels else None
result = tool.create_issue_from_text(
repo,
text,
assignees=assignee_list,
labels=label_list
)
if "error" in result:
console.print(f"[red]Error: {result['error']}[/red]")
return
info = f"""
**Issue Created Successfully!**
**#{result['number']}**: {result['title']}
**URL**: {result['url']}
**Labels**: {', '.join(result['labels'])}
**Similar Issues Found**: {len(result.get('similar_issues', []))}
"""
console.print(Panel(Markdown(info), title="Issue Created", border_style="green"))
if result.get('similar_issues'):
console.print("\n[yellow]β οΈ Similar issues:[/yellow]")
for similar in result['similar_issues'][:3]:
console.print(f" β’ [#{similar['number']}]({similar['url']}) - {similar['title']}")
except Exception as e:
console.print(f"[red]Error: {str(e)}[/red]")
@app.command()
def chat(
message: str = typer.Argument(..., help="Your question or command"),
):
"""Chat with HubMind agent using natural language"""
console.print("[bold blue]π€ HubMind Agent is thinking...[/bold blue]")
try:
agent = HubMindAgent()
response = agent.chat(message)
console.print("\n[bold green]HubMind:[/bold green]")
console.print(Panel(Markdown(response), border_style="blue"))
except Exception as e:
console.print(f"[red]Error: {str(e)}[/red]")
@app.command()
def ask(
repo: str = typer.Argument(..., help="Repository full name (owner/repo)"),
question: str = typer.Argument(..., help="Your question about the repository"),
):
"""Ask questions about a repository"""
console.print(f"[bold blue]π¬ Answering question about {repo}...[/bold blue]")
try:
qa_agent = HubMindQAAgent()
result = qa_agent.answer_repo_question(repo, question)
console.print("\n[bold green]Answer:[/bold green]")
console.print(Panel(Markdown(result['answer']), border_style="green"))
if result.get('sources'):
console.print("\n[bold]Sources:[/bold]")
for source in result['sources']:
console.print(f" β’ {source}")
except Exception as e:
console.print(f"[red]Error: {str(e)}[/red]")
@app.command()
def health(
repo: str = typer.Argument(..., help="Repository full name (owner/repo)"),
days: int = typer.Option(30, "--days", "-d", help="Number of days to analyze"),
):
"""Get repository health metrics"""
console.print(f"[bold blue]π Analyzing health of {repo}...[/bold blue]")
try:
dashboard = DeveloperDashboard()
health = dashboard.get_repo_health(repo, days=days)
if "error" in health:
console.print(f"[red]Error: {health['error']}[/red]")
return
info = f"""
**Repository Health Report** ({health['period_days']} days)
**Metrics**:
- Average Issue Response Time: {health['avg_issue_response_hours']} hours
- PR Merge Rate: {health['pr_merge_rate']}%
- Active Contributors: {health['active_contributors']}
- Commits per Day: {health['commits_per_day']}
- Total Commits: {health['total_commits']}
**Current Status**:
- Open Issues: {health['open_issues']}
- Stars: {health['stars']}
- Forks: {health['forks']}
**Top Contributors**: {', '.join(health['contributor_list'][:5])}
"""
console.print(Panel(Markdown(info), title="Health Report", border_style="cyan"))
except Exception as e:
console.print(f"[red]Error: {str(e)}[/red]")
@app.command()
def watch(
repos: str = typer.Argument(..., help="Comma-separated list of repositories"),
hours: int = typer.Option(24, "--hours", "-h", help="Hours to look back"),
):
"""Watch activity for multiple repositories"""
repo_list = [r.strip() for r in repos.split(",")]
console.print(f"[bold blue]π Watching {len(repo_list)} repositories...[/bold blue]")
try:
dashboard = DeveloperDashboard()
activities = dashboard.get_watched_repos_activity(repo_list, hours=hours)
table = Table(title=f"Repository Activity (last {hours} hours)")
table.add_column("Repository", style="magenta", width=30)
table.add_column("New PRs", style="green", width=10)
table.add_column("Updated PRs", style="blue", width=12)
table.add_column("New Issues", style="yellow", width=12)
table.add_column("Updated Issues", style="cyan", width=14)
table.add_column("Commits", style="red", width=10)
for activity in activities:
if "error" not in activity:
table.add_row(
activity['repo'],
str(activity['new_prs']),
str(activity['updated_prs']),
str(activity['new_issues']),
str(activity['updated_issues']),
str(activity['commits'])
)
console.print(table)
except Exception as e:
console.print(f"[red]Error: {str(e)}[/red]")
@app.command()
def interactive():
"""Start interactive chat mode"""
console.print("[bold green]π€ HubMind Interactive Mode[/bold green]")
console.print("[dim]Type 'exit' or 'quit' to end the session[/dim]\n")
try:
agent = HubMindAgent()
chat_history = []
while True:
try:
user_input = console.input("[bold cyan]You:[/bold cyan] ")
if user_input.lower() in ['exit', 'quit', 'q']:
console.print("[yellow]Goodbye! π[/yellow]")
break
if not user_input.strip():
continue
response = agent.chat(user_input, chat_history)
console.print(f"\n[bold green]HubMind:[/bold green]")
console.print(Panel(Markdown(response), border_style="blue"))
console.print() # Empty line
# Update chat history
chat_history.append(("human", user_input))
chat_history.append(("ai", response))
except KeyboardInterrupt:
console.print("\n[yellow]Goodbye! π[/yellow]")
break
except Exception as e:
console.print(f"[red]Error: {str(e)}[/red]")
except Exception as e:
console.print(f"[red]Error initializing agent: {str(e)}[/red]")
if __name__ == "__main__":
app()