Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Document review request events in Timeline struct #3391

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions github/issues_timeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ type Timeline struct {
// reviewed
// The pull request was reviewed.
//
// review_requested
// The actor requested a review from a user or team.
// Reviewer and Requester/RequestedTeam will be populated.
//
// review_request_removed
// The actor removed a review request from a user or team.
// Reviewer and Requester/RequestedTeam will be populated.
//
// subscribed
// The actor subscribed to receive notifications for an issue.
//
Expand Down
98 changes: 98 additions & 0 deletions github/issues_timeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ import (
"net/http"
"strings"
"testing"
"time"

"github.com/google/go-cmp/cmp"
)

func parseTime(t *testing.T, value string) time.Time {
Copy link
Collaborator

@gmlewis gmlewis Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, there is really no need for this helper function, as there is no need to test the functionality of time.Parse in this repo since it is well-tested with each release of the Go compiler.

The vast majority of our tests use &Timestamp{referenceTime} although I do see some unfortunate deviations from this.

Let's please remove this helper function and use the existing referenceTime instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I've pushed up those changes to use &Timestamp{referenceTime}!

t.Helper()
parsedTime, err := time.Parse(time.RFC3339, value)
if err != nil {
t.Fatalf("failed to parse time: %v", err)
}
return parsedTime
}

func TestIssuesService_ListIssueTimeline(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)
Expand Down Expand Up @@ -255,3 +265,91 @@ func TestTimeline_Marshal(t *testing.T) {

testJSONMarshal(t, u, want)
}

func TestTimeline_ReviewRequests(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

mux.HandleFunc("/repos/example-org/example-repo/issues/3/timeline", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[{
"id": 1234567890,
"url": "http://example.com/timeline/1",
"actor": {
"login": "actor-user",
"id": 1
},
"event": "review_requested",
"created_at": "2024-12-17T15:47:42Z",
"requested_reviewer": {
"login": "reviewer-user",
"id": 2
},
"review_requester": {
"login": "requester-user",
"id": 1
}
},
{
"id": 1234567891,
"url": "http://example.com/timeline/2",
"actor": {
"login": "actor-user",
"id": 1
},
"event": "review_request_removed",
"created_at": "2024-12-17T15:51:04Z",
"requested_reviewer": {
"login": "reviewer-user",
"id": 2
}
}]`)
})

ctx := context.Background()
events, _, err := client.Issues.ListIssueTimeline(ctx, "example-org", "example-repo", 3, nil)
if err != nil {
t.Errorf("Issues.ListIssueTimeline returned error: %v", err)
}

want := []*Timeline{
{
ID: Ptr(int64(1234567890)),
URL: Ptr("http://example.com/timeline/1"),
Actor: &User{
Login: Ptr("actor-user"),
ID: Ptr(int64(1)),
},
Event: Ptr("review_requested"),
CreatedAt: &Timestamp{parseTime(t, "2024-12-17T15:47:42Z")},
Reviewer: &User{
Login: Ptr("reviewer-user"),
ID: Ptr(int64(2)),
},
Requester: &User{
Login: Ptr("requester-user"),
ID: Ptr(int64(1)),
},
},
{
ID: Ptr(int64(1234567891)),
URL: Ptr("http://example.com/timeline/2"),
Actor: &User{
Login: Ptr("actor-user"),
ID: Ptr(int64(1)),
},
Event: Ptr("review_request_removed"),
CreatedAt: &Timestamp{parseTime(t, "2024-12-17T15:51:04Z")},
Reviewer: &User{
Login: Ptr("reviewer-user"),
ID: Ptr(int64(2)),
},
},
}

if !cmp.Equal(events, want) {
t.Errorf("Issues.ListIssueTimeline review request events = %+v, want %+v", events, want)
diff := cmp.Diff(events, want)
t.Errorf("Difference: %s", diff)
}
}
Loading