|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "strings" |
| 7 | + "time" |
| 8 | + |
| 9 | + "github.com/gh-standup/internal/github" |
| 10 | + "github.com/gh-standup/internal/llm" |
| 11 | + "github.com/gh-standup/internal/types" |
| 12 | + "github.com/spf13/cobra" |
| 13 | +) |
| 14 | + |
| 15 | +const extensionName = "standup" |
| 16 | + |
| 17 | +var rootCmd = &cobra.Command{ |
| 18 | + Use: extensionName, |
| 19 | + Short: "Generate AI-powered standup reports", |
| 20 | + Long: "A GitHub CLI extension that generates standup reports using GitHub Models and GitHub API data", |
| 21 | + RunE: runStandup, |
| 22 | +} |
| 23 | + |
| 24 | +var ( |
| 25 | + flagDays int |
| 26 | + flagModel string |
| 27 | + flagRepo string |
| 28 | + flagUser string |
| 29 | +) |
| 30 | + |
| 31 | +func init() { |
| 32 | + rootCmd.Flags().IntVarP(&flagDays, "days", "d", 1, "Number of days to look back for activity") |
| 33 | + rootCmd.Flags().StringVarP(&flagModel, "model", "m", "openai/gpt-4o", "GitHub Models model to use") |
| 34 | + rootCmd.Flags().StringVarP(&flagRepo, "repo", "r", "", "Repository to generate standup for (owner/repo)") |
| 35 | + rootCmd.Flags().StringVarP(&flagUser, "user", "u", "", "User to generate standup for (defaults to authenticated user)") |
| 36 | +} |
| 37 | + |
| 38 | +func main() { |
| 39 | + if err := rootCmd.Execute(); err != nil { |
| 40 | + fmt.Fprintf(os.Stderr, "Error: %v\n", err) |
| 41 | + os.Exit(1) |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +func runStandup(cmd *cobra.Command, args []string) error { |
| 46 | + githubClient, err := github.NewClient() |
| 47 | + if err != nil { |
| 48 | + return fmt.Errorf("failed to create GitHub client: %w", err) |
| 49 | + } |
| 50 | + |
| 51 | + if flagUser == "" { |
| 52 | + fmt.Print("Getting authenticated GitHub user... ") |
| 53 | + user, err := githubClient.GetCurrentUser() |
| 54 | + if err != nil { |
| 55 | + fmt.Println("Failed") |
| 56 | + return fmt.Errorf("failed to get current user: %w", err) |
| 57 | + } |
| 58 | + flagUser = user |
| 59 | + fmt.Printf("✅ Found user: %s\n", flagUser) |
| 60 | + } |
| 61 | + |
| 62 | + endDate := time.Now() |
| 63 | + startDate := endDate.AddDate(0, 0, -flagDays) |
| 64 | + |
| 65 | + fmt.Printf("Analyzing GitHub activity for %s (%s to %s)\n", |
| 66 | + flagUser, startDate.Format("2006-01-02"), endDate.Format("2006-01-02")) |
| 67 | + |
| 68 | + fmt.Print("Collecting GitHub activity data...\n") |
| 69 | + activities, err := githubClient.CollectActivity(flagUser, flagRepo, startDate, endDate) |
| 70 | + if err != nil { |
| 71 | + return fmt.Errorf("failed to collect GitHub activity: %w", err) |
| 72 | + } |
| 73 | + |
| 74 | + if len(activities) == 0 { |
| 75 | + fmt.Println("No GitHub activity found for the specified period.") |
| 76 | + return nil |
| 77 | + } |
| 78 | + |
| 79 | + fmt.Printf("Found %d activities\n", len(activities)) |
| 80 | + |
| 81 | + commits, prs, issues, reviews := countActivities(activities) |
| 82 | + fmt.Printf(" %d commits, %d pull requests, %d issues, %d reviews\n", commits, prs, issues, reviews) |
| 83 | + |
| 84 | + llmClient, err := llm.NewClient() |
| 85 | + if err != nil { |
| 86 | + return fmt.Errorf("failed to create LLM client: %w", err) |
| 87 | + } |
| 88 | + |
| 89 | + // Generate standup report using GitHub Models |
| 90 | + fmt.Printf("Generating standup report using %s...\n", flagModel) |
| 91 | + report, err := llmClient.GenerateStandupReport(activities, flagModel) |
| 92 | + if err != nil { |
| 93 | + return fmt.Errorf("failed to generate standup report: %w", err) |
| 94 | + } |
| 95 | + |
| 96 | + fmt.Println("Report generated successfully!") |
| 97 | + fmt.Println("\n" + strings.Repeat("=", 50)) |
| 98 | + fmt.Println("STANDUP REPORT") |
| 99 | + fmt.Println(strings.Repeat("=", 50)) |
| 100 | + fmt.Println(report) |
| 101 | + |
| 102 | + return nil |
| 103 | +} |
| 104 | + |
| 105 | +func countActivities(activities []types.GitHubActivity) (commits, prs, issues, reviews int) { |
| 106 | + for _, activity := range activities { |
| 107 | + switch activity.Type { |
| 108 | + case "commit": |
| 109 | + commits++ |
| 110 | + case "pull_request": |
| 111 | + prs++ |
| 112 | + case "issue": |
| 113 | + issues++ |
| 114 | + case "review": |
| 115 | + reviews++ |
| 116 | + } |
| 117 | + } |
| 118 | + return |
| 119 | +} |
0 commit comments