From 2674d503203c6a5cd5b089ef71a0d80db5a08c04 Mon Sep 17 00:00:00 2001 From: Pranav Bansal Date: Sat, 21 Sep 2024 10:16:36 +0100 Subject: [PATCH 1/3] Add missing fields to tthe checksuite event - latest_check_runs_count, rerequestable and runs_rerequestable --- github/checks.go | 5 ++++- github/github-accessors.go | 24 ++++++++++++++++++++++ github/github-accessors_test.go | 30 ++++++++++++++++++++++++++++ github/github-stringify_test.go | 35 ++++++++++++++++++--------------- 4 files changed, 77 insertions(+), 17 deletions(-) diff --git a/github/checks.go b/github/checks.go index a8618944532..f12d86f5f98 100644 --- a/github/checks.go +++ b/github/checks.go @@ -85,7 +85,10 @@ type CheckSuite struct { PullRequests []*PullRequest `json:"pull_requests,omitempty"` // The following fields are only populated by Webhook events. - HeadCommit *Commit `json:"head_commit,omitempty"` + HeadCommit *Commit `json:"head_commit,omitempty"` + LatstCheckRunsCount *int64 `json:"latest_check_runs_count,omitempty"` + Rerequstable *bool `json:"rerequestable,omitempty"` + RunsRerequstable *bool `json:"runs_rerequestable,omitempty"` } func (c CheckRun) String() string { diff --git a/github/github-accessors.go b/github/github-accessors.go index 1abbabd0b63..31f10cf0043 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -2286,6 +2286,14 @@ func (c *CheckSuite) GetID() int64 { return *c.ID } +// GetLatstCheckRunsCount returns the LatstCheckRunsCount field if it's non-nil, zero value otherwise. +func (c *CheckSuite) GetLatstCheckRunsCount() int64 { + if c == nil || c.LatstCheckRunsCount == nil { + return 0 + } + return *c.LatstCheckRunsCount +} + // GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. func (c *CheckSuite) GetNodeID() string { if c == nil || c.NodeID == nil { @@ -2302,6 +2310,22 @@ func (c *CheckSuite) GetRepository() *Repository { return c.Repository } +// GetRerequstable returns the Rerequstable field if it's non-nil, zero value otherwise. +func (c *CheckSuite) GetRerequstable() bool { + if c == nil || c.Rerequstable == nil { + return false + } + return *c.Rerequstable +} + +// GetRunsRerequstable returns the RunsRerequstable field if it's non-nil, zero value otherwise. +func (c *CheckSuite) GetRunsRerequstable() bool { + if c == nil || c.RunsRerequstable == nil { + return false + } + return *c.RunsRerequstable +} + // GetStatus returns the Status field if it's non-nil, zero value otherwise. func (c *CheckSuite) GetStatus() string { if c == nil || c.Status == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 6d1419c79f2..94b2138bd1d 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -2708,6 +2708,16 @@ func TestCheckSuite_GetID(tt *testing.T) { c.GetID() } +func TestCheckSuite_GetLatstCheckRunsCount(tt *testing.T) { + var zeroValue int64 + c := &CheckSuite{LatstCheckRunsCount: &zeroValue} + c.GetLatstCheckRunsCount() + c = &CheckSuite{} + c.GetLatstCheckRunsCount() + c = nil + c.GetLatstCheckRunsCount() +} + func TestCheckSuite_GetNodeID(tt *testing.T) { var zeroValue string c := &CheckSuite{NodeID: &zeroValue} @@ -2725,6 +2735,26 @@ func TestCheckSuite_GetRepository(tt *testing.T) { c.GetRepository() } +func TestCheckSuite_GetRerequstable(tt *testing.T) { + var zeroValue bool + c := &CheckSuite{Rerequstable: &zeroValue} + c.GetRerequstable() + c = &CheckSuite{} + c.GetRerequstable() + c = nil + c.GetRerequstable() +} + +func TestCheckSuite_GetRunsRerequstable(tt *testing.T) { + var zeroValue bool + c := &CheckSuite{RunsRerequstable: &zeroValue} + c.GetRunsRerequstable() + c = &CheckSuite{} + c.GetRunsRerequstable() + c = nil + c.GetRunsRerequstable() +} + func TestCheckSuite_GetStatus(tt *testing.T) { var zeroValue string c := &CheckSuite{Status: &zeroValue} diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index 8633d837d12..184d8704e69 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -182,22 +182,25 @@ func TestCheckRun_String(t *testing.T) { func TestCheckSuite_String(t *testing.T) { v := CheckSuite{ - ID: Int64(0), - NodeID: String(""), - HeadBranch: String(""), - HeadSHA: String(""), - URL: String(""), - BeforeSHA: String(""), - AfterSHA: String(""), - Status: String(""), - Conclusion: String(""), - CreatedAt: &Timestamp{}, - UpdatedAt: &Timestamp{}, - App: &App{}, - Repository: &Repository{}, - HeadCommit: &Commit{}, - } - want := `github.CheckSuite{ID:0, NodeID:"", HeadBranch:"", HeadSHA:"", URL:"", BeforeSHA:"", AfterSHA:"", Status:"", Conclusion:"", CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, App:github.App{}, Repository:github.Repository{}, HeadCommit:github.Commit{}}` + ID: Int64(0), + NodeID: String(""), + HeadBranch: String(""), + HeadSHA: String(""), + URL: String(""), + BeforeSHA: String(""), + AfterSHA: String(""), + Status: String(""), + Conclusion: String(""), + CreatedAt: &Timestamp{}, + UpdatedAt: &Timestamp{}, + App: &App{}, + Repository: &Repository{}, + HeadCommit: &Commit{}, + LatstCheckRunsCount: Int64(0), + Rerequstable: Bool(false), + RunsRerequstable: Bool(false), + } + want := `github.CheckSuite{ID:0, NodeID:"", HeadBranch:"", HeadSHA:"", URL:"", BeforeSHA:"", AfterSHA:"", Status:"", Conclusion:"", CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, App:github.App{}, Repository:github.Repository{}, HeadCommit:github.Commit{}, LatstCheckRunsCount:0, Rerequstable:false, RunsRerequstable:false}` if got := v.String(); got != want { t.Errorf("CheckSuite.String = %v, want %v", got, want) } From 8ea2d719e4f0ae96ab31bb996244c8f1fa87d01b Mon Sep 17 00:00:00 2001 From: Pranav Bansal Date: Sat, 21 Sep 2024 13:21:48 +0100 Subject: [PATCH 2/3] fix typo in struct field Signed-off-by: Pranav Bansal --- github/checks.go | 8 +++---- github/github-accessors.go | 8 +++---- github/github-accessors_test.go | 10 ++++----- github/github-stringify_test.go | 38 ++++++++++++++++----------------- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/github/checks.go b/github/checks.go index f12d86f5f98..71e50c15f29 100644 --- a/github/checks.go +++ b/github/checks.go @@ -85,10 +85,10 @@ type CheckSuite struct { PullRequests []*PullRequest `json:"pull_requests,omitempty"` // The following fields are only populated by Webhook events. - HeadCommit *Commit `json:"head_commit,omitempty"` - LatstCheckRunsCount *int64 `json:"latest_check_runs_count,omitempty"` - Rerequstable *bool `json:"rerequestable,omitempty"` - RunsRerequstable *bool `json:"runs_rerequestable,omitempty"` + HeadCommit *Commit `json:"head_commit,omitempty"` + LatestCheckRunsCount *int64 `json:"latest_check_runs_count,omitempty"` + Rerequstable *bool `json:"rerequestable,omitempty"` + RunsRerequstable *bool `json:"runs_rerequestable,omitempty"` } func (c CheckRun) String() string { diff --git a/github/github-accessors.go b/github/github-accessors.go index 31f10cf0043..a99a06aa314 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -2286,12 +2286,12 @@ func (c *CheckSuite) GetID() int64 { return *c.ID } -// GetLatstCheckRunsCount returns the LatstCheckRunsCount field if it's non-nil, zero value otherwise. -func (c *CheckSuite) GetLatstCheckRunsCount() int64 { - if c == nil || c.LatstCheckRunsCount == nil { +// GetLatestCheckRunsCount returns the LatestCheckRunsCount field if it's non-nil, zero value otherwise. +func (c *CheckSuite) GetLatestCheckRunsCount() int64 { + if c == nil || c.LatestCheckRunsCount == nil { return 0 } - return *c.LatstCheckRunsCount + return *c.LatestCheckRunsCount } // GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 94b2138bd1d..2db51bab3dd 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -2708,14 +2708,14 @@ func TestCheckSuite_GetID(tt *testing.T) { c.GetID() } -func TestCheckSuite_GetLatstCheckRunsCount(tt *testing.T) { +func TestCheckSuite_GetLatestCheckRunsCount(tt *testing.T) { var zeroValue int64 - c := &CheckSuite{LatstCheckRunsCount: &zeroValue} - c.GetLatstCheckRunsCount() + c := &CheckSuite{LatestCheckRunsCount: &zeroValue} + c.GetLatestCheckRunsCount() c = &CheckSuite{} - c.GetLatstCheckRunsCount() + c.GetLatestCheckRunsCount() c = nil - c.GetLatstCheckRunsCount() + c.GetLatestCheckRunsCount() } func TestCheckSuite_GetNodeID(tt *testing.T) { diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index 184d8704e69..4a210326f9a 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -182,25 +182,25 @@ func TestCheckRun_String(t *testing.T) { func TestCheckSuite_String(t *testing.T) { v := CheckSuite{ - ID: Int64(0), - NodeID: String(""), - HeadBranch: String(""), - HeadSHA: String(""), - URL: String(""), - BeforeSHA: String(""), - AfterSHA: String(""), - Status: String(""), - Conclusion: String(""), - CreatedAt: &Timestamp{}, - UpdatedAt: &Timestamp{}, - App: &App{}, - Repository: &Repository{}, - HeadCommit: &Commit{}, - LatstCheckRunsCount: Int64(0), - Rerequstable: Bool(false), - RunsRerequstable: Bool(false), - } - want := `github.CheckSuite{ID:0, NodeID:"", HeadBranch:"", HeadSHA:"", URL:"", BeforeSHA:"", AfterSHA:"", Status:"", Conclusion:"", CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, App:github.App{}, Repository:github.Repository{}, HeadCommit:github.Commit{}, LatstCheckRunsCount:0, Rerequstable:false, RunsRerequstable:false}` + ID: Int64(0), + NodeID: String(""), + HeadBranch: String(""), + HeadSHA: String(""), + URL: String(""), + BeforeSHA: String(""), + AfterSHA: String(""), + Status: String(""), + Conclusion: String(""), + CreatedAt: &Timestamp{}, + UpdatedAt: &Timestamp{}, + App: &App{}, + Repository: &Repository{}, + HeadCommit: &Commit{}, + LatestCheckRunsCount: Int64(0), + Rerequstable: Bool(false), + RunsRerequstable: Bool(false), + } + want := `github.CheckSuite{ID:0, NodeID:"", HeadBranch:"", HeadSHA:"", URL:"", BeforeSHA:"", AfterSHA:"", Status:"", Conclusion:"", CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, App:github.App{}, Repository:github.Repository{}, HeadCommit:github.Commit{}, LatestCheckRunsCount:0, Rerequstable:false, RunsRerequstable:false}` if got := v.String(); got != want { t.Errorf("CheckSuite.String = %v, want %v", got, want) } From a983ececc25195f9a17476b56fd30b21dfbeade9 Mon Sep 17 00:00:00 2001 From: Pranav Bansal Date: Sat, 21 Sep 2024 13:35:20 +0100 Subject: [PATCH 3/3] add test cov --- github/checks_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/github/checks_test.go b/github/checks_test.go index 2fdd2476e56..48f6370fe96 100644 --- a/github/checks_test.go +++ b/github/checks_test.go @@ -888,6 +888,9 @@ func Test_CheckSuiteMarshal(t *testing.T) { HeadCommit: &Commit{ SHA: String("s"), }, + LatestCheckRunsCount: Int64(1), + Rerequstable: Bool(true), + RunsRerequstable: Bool(true), } w := fmt.Sprintf(`{ @@ -949,7 +952,10 @@ func Test_CheckSuiteMarshal(t *testing.T) { ], "head_commit": { "sha": "s" - } + }, + "latest_check_runs_count": 1, + "rerequestable": true, + "runs_rerequestable": true }`, ts, ts) testJSONMarshal(t, &c, w)