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
|
package github
import (
"context"
"time"
)
// PullRequest represents a GitHub pull request.
type PullRequest struct {
// Number is the pull request number
Number int `json:"number"`
// Title is the pull request title
Title string `json:"title"`
// CreatedAt is the timestamp when the PR was created
CreatedAt time.Time `json:"created_at"`
// UpdatedAt is the timestamp when the PR was last updated
UpdatedAt time.Time `json:"updated_at"`
// User is the GitHub user who created the PR
User User `json:"user"`
}
// Review represents a pull request review.
type Review struct {
// ID is the unique identifier for the review
ID int64 `json:"id"`
// User is the GitHub user who submitted the review
User User `json:"user"`
// State represents the review decision: APPROVED, CHANGES_REQUESTED, or COMMENTED
State string `json:"state"`
// SubmittedAt is the timestamp when the review was submitted
SubmittedAt time.Time `json:"submitted_at"`
// Body is the review comment text
Body string `json:"body"`
}
// ReviewComment represents an inline comment on a pull request review.
type ReviewComment struct {
// ID is the unique identifier for the comment
ID int64 `json:"id"`
// ReviewID is the ID of the review this comment belongs to
ReviewID int64 `json:"pull_request_review_id"`
// User is the GitHub user who made the comment
User User `json:"user"`
// Body is the comment text
Body string `json:"body"`
// CreatedAt is the timestamp when the comment was created
CreatedAt time.Time `json:"created_at"`
// UpdatedAt is the timestamp when the comment was last updated
UpdatedAt time.Time `json:"updated_at"`
// Path is the file path where the comment was made
Path string `json:"path"`
// Line is the line number where the comment was made
Line int `json:"line"`
}
// User represents a GitHub user.
type User struct {
// Login is the GitHub username
Login string `json:"login"`
// ID is the GitHub user ID
ID int64 `json:"id"`
}
// APIError represents a GitHub API error response.
type APIError struct {
// Message describes the error that occurred
Message string `json:"message"`
// DocumentationURL points to the relevant API documentation
DocumentationURL string `json:"documentation_url"`
}
// RateLimit represents GitHub API rate limit information.
type RateLimit struct {
// Limit is the maximum number of requests allowed per hour
Limit int
// Remaining is the number of requests remaining in the current hour
Remaining int
// Reset is the time when the rate limit will be reset
Reset time.Time
}
// ClientInterface defines the interface for GitHub API interactions.
type ClientInterface interface {
// GetPullRequests fetches pull requests created within the specified date range.
// It returns a slice of PullRequest and any error that occurred.
GetPullRequests(
ctx context.Context,
owner, repo string,
since, until time.Time,
) ([]PullRequest, error)
// GetPullRequestReviews fetches all reviews for a specific pull request.
// It returns a slice of Review and any error that occurred.
GetPullRequestReviews(ctx context.Context, owner, repo string, prNumber int) ([]Review, error)
// GetPullRequestReviewComments fetches all review comments for a specific pull request.
// It returns a slice of ReviewComment and any error that occurred.
GetPullRequestReviewComments(
ctx context.Context,
owner, repo string,
prNumber int,
) ([]ReviewComment, error)
// GetRateLimit returns the current rate limit information.
// It returns a RateLimit pointer and any error that occurred.
GetRateLimit(ctx context.Context) (*RateLimit, error)
}
// TestFixtures represents the test data structure.
type TestFixtures struct {
// PullRequests is a slice of sample pull requests
PullRequests []PullRequest
// Reviews maps PR numbers to their reviews
Reviews map[string][]Review
// Comments maps PR numbers to their review comments
Comments map[string][]ReviewComment
// RateLimit contains sample rate limit information
RateLimit RateLimit
}
|