diff options
| author | Franck Cuny <franck@fcuny.net> | 2025-09-27 15:10:13 -0700 |
|---|---|---|
| committer | Franck Cuny <franck@fcuny.net> | 2025-09-27 15:16:40 -0700 |
| commit | 7095a53bf173ca6680c7888c8d1df4afb1ad29ae (patch) | |
| tree | 63ce5037b38ed8704fffc362c7541ebef311b74c /cmd/pr-analyzer/formatter.go | |
| parent | fix sha for goget (diff) | |
| download | x-7095a53bf173ca6680c7888c8d1df4afb1ad29ae.tar.gz | |
add pr-analyzer
A tool to analyze pull request review patterns in a GitHub repository, focusing on team members' review behaviors and habits. This tool helps teams understand and improve their code review processes by providing insights into review frequency, speed, thoroughness, and approval patterns.
Diffstat (limited to '')
| -rw-r--r-- | cmd/pr-analyzer/formatter.go | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/cmd/pr-analyzer/formatter.go b/cmd/pr-analyzer/formatter.go new file mode 100644 index 0000000..a9e0f03 --- /dev/null +++ b/cmd/pr-analyzer/formatter.go @@ -0,0 +1,78 @@ +package main + +import ( + "fmt" + "log" + "strings" + "text/tabwriter" + "time" +) + +// Formatter handles the formatting of analysis results +type Formatter struct { + repo string + startDate time.Time + endDate time.Time +} + +// NewFormatter creates a new output formatter +func NewFormatter(repo string, startDate, endDate time.Time) *Formatter { + return &Formatter{ + repo: repo, + startDate: startDate, + endDate: endDate, + } +} + +// FormatTable generates a formatted table string from the analysis results +func (f *Formatter) FormatTable(metrics []ReviewerMetrics) string { + var sb strings.Builder + w := tabwriter.NewWriter(&sb, 0, 0, 2, ' ', tabwriter.TabIndent) + + _, err := fmt.Fprintf(w, "GitHub PR Review Analysis for %s (%s - %s)\n", + f.repo, + f.startDate.Format("Jan 2, 2006"), + f.endDate.Format("Jan 2, 2006")) + if err != nil { + log.Fatal(err) + } + _, err = fmt.Fprintln(w, strings.Repeat("-", 80)) + if err != nil { + log.Fatal(err) + } + + _, err = fmt.Fprintln( + w, + "Team Member\tPRs Reviewed\tAvg Review Speed\tAvg Comments/File\tImmediate Approvals", + ) + if err != nil { + log.Fatal(err) + } + + for _, m := range metrics { + _, err = fmt.Fprintf(w, "%s\t%d\t%.1f hours\t%.1f\t%.1f%%\n", + m.Username, + m.PRsReviewed, + m.AverageReviewSpeed, + m.AverageComments, + m.ImmediateApprovals) + if err != nil { + log.Fatal(err) + } + } + + if err := w.Flush(); err != nil { + log.Fatal(err) + } + return sb.String() +} + +// FormatError generates a formatted error message +func (f *Formatter) FormatError(err error) string { + return fmt.Sprintf("Error: %v\n", err) +} + +// FormatProgress generates a formatted progress message +func (f *Formatter) FormatProgress(msg string) string { + return fmt.Sprintf("Progress: %s\n", msg) +} |
