aboutsummaryrefslogtreecommitdiff
path: root/cmd/pr-analyzer/types.go
blob: 4c3a83d1febb038936dfbc34feb9a4c3ecd18c19 (plain) (blame)
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
package main

import (
	"time"
)

// PRData represents a pull request with its reviews and comments.
type PRData struct {
	// Number is the pull request number
	Number int
	// CreatedAt is the timestamp when the PR was created
	CreatedAt time.Time
	// Reviews contains all reviews submitted for this PR
	Reviews []ReviewData
}

// ReviewData represents a review submitted on a pull request.
type ReviewData struct {
	// Reviewer is the GitHub username of the person who submitted the review
	Reviewer string
	// State represents the review state: APPROVED, CHANGES_REQUESTED, or COMMENTED
	State string
	// SubmittedAt is the timestamp when the review was submitted
	SubmittedAt time.Time
	// Comments contains all inline comments made during the review
	Comments []CommentData
}

// CommentData represents an inline comment made during a review.
type CommentData struct {
	// Reviewer is the GitHub username of the person who made the comment
	Reviewer string
	// CreatedAt is the timestamp when the comment was created
	CreatedAt time.Time
	// Path is the file path where the comment was made
	Path string
	// Line is the line number where the comment was made
	Line int
}

// ReviewerMetrics holds the analysis results for a single reviewer.
type ReviewerMetrics struct {
	// Username is the GitHub username of the reviewer
	Username string
	// PRsReviewed is the total number of PRs reviewed by this person
	PRsReviewed int
	// AverageReviewSpeed is the average time (in hours) from PR creation
	// to the reviewer's first comment
	AverageReviewSpeed float64 // in hours
	// AverageComments is the average number of inline comments made
	// per PR when the reviewer comments
	AverageComments float64
	// ImmediateApprovals is the percentage of PRs that were approved
	// without requesting changes first
	ImmediateApprovals float64 // percentage
}

// ReviewPattern represents the approval pattern for a PR.
type ReviewPattern struct {
	// IsImmediateApproval indicates if the PR was approved without
	// requesting changes first
	IsImmediateApproval bool
	// FirstReviewState is the state of the first review submitted
	FirstReviewState string
	// FinalReviewState is the state of the last review submitted
	FinalReviewState string
	// TimeToFirstReview is the duration from PR creation to first review
	TimeToFirstReview time.Duration
	// TimeToFinalReview is the duration from PR creation to final review
	TimeToFinalReview time.Duration
}

// PRMetrics holds all metrics for a single PR.
type PRMetrics struct {
	// Number is the pull request number
	Number int
	// CreatedAt is the timestamp when the PR was created
	CreatedAt time.Time
	// ReviewPatterns contains the review patterns for each reviewer
	ReviewPatterns []ReviewPattern
	// CommentsPerFile maps file paths to the number of comments made
	// on that file
	CommentsPerFile map[string]int
	// Reviewers is the list of GitHub usernames who reviewed this PR
	Reviewers []string
	// TimeToFirstReview is the duration from PR creation to the first
	// review being submitted
	TimeToFirstReview time.Duration
}

// Analyzer processes PR data and generates metrics.
type Analyzer struct {
	// startDate is the beginning of the analysis period
	startDate time.Time
	// endDate is the end of the analysis period
	endDate time.Time
}

// NewAnalyzer creates a new PR analyzer with the specified date range.
func NewAnalyzer(startDate, endDate time.Time) *Analyzer {
	return &Analyzer{
		startDate: startDate,
		endDate:   endDate,
	}
}