Skip to content

Commit

Permalink
refactor: add logging and better formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mahyarmirrashed committed Dec 20, 2024
1 parent 75dcbb0 commit d202b4c
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,36 +54,37 @@ var rootCmd = &cobra.Command{

// Build the output content based on the order of `includes`
var contentBuilder strings.Builder
codeBlock := func(content string) string { return "\n```\n" + content + "\n```\n" }

for _, item := range includes {
switch item {
case "DAY_STATS":
// Compute the weekly stats
dailyData, err := stats.GetDailyCommitData(cfg, commits)
log.Info().Msg("Calculating commit statistics based on time of day")
dailyStats, err := stats.GetDailyCommitData(cfg, commits)
if err != nil {
return fmt.Errorf("failed to get daily commit data: %w", err)
return fmt.Errorf("failed to get daily commit stats: %w", err)
}
contentBuilder.WriteString("\n```\n" + dailyData + "\n```\n")
contentBuilder.WriteString(codeBlock(dailyStats))

case "WEEK_STATS":
// Compute the weekly stats
weeklyData, err := stats.GetWeeklyCommitData(cfg, commits)
log.Info().Msg("Calculating commit statistics based on day of week")
weeklyStats, err := stats.GetWeeklyCommitData(cfg, commits)
if err != nil {
return fmt.Errorf("failed to get weekly commit data: %w", err)
return fmt.Errorf("failed to get weekly commit stats: %w", err)
}
contentBuilder.WriteString("\n```\n" + weeklyData + "\n```\n")
contentBuilder.WriteString(codeBlock(weeklyStats))

case "LANGUAGE_STATS":
// Compute the language stats
languageData, err := stats.GetLanguageData(cfg, languages)
log.Info().Msg("Calculating language statistics")
languageStats, err := stats.GetLanguageData(cfg, languages)
if err != nil {
return fmt.Errorf("failed to get weekly commit data: %w", err)
return fmt.Errorf("failed to get language stats: %w", err)
}
contentBuilder.WriteString("\n```\n" + languageData + "\n```\n")
contentBuilder.WriteString(codeBlock(languageStats))

default:
// Unknown item, skip or handle error
contentBuilder.WriteString(fmt.Sprintf("Unknown item: %s\n", item))
contentBuilder.WriteString(fmt.Sprintf("\n\nUnknown item: %s\n", item))
}
}

Expand Down

0 comments on commit d202b4c

Please sign in to comment.