From a6a015e67834ca01f809f998ed34917bda35ad27 Mon Sep 17 00:00:00 2001 From: Dariusz Porowski Date: Tue, 28 Sep 2021 20:53:44 +0200 Subject: [PATCH 1/2] Fixed ProjOpt & added OrgProj attr to Proj struct --- github/github-accessors.go | 24 ++++++++++++++++++++---- github/github-accessors_test.go | 30 +++++++++++++++++++++++++----- github/github-stringify_test.go | 30 ++++++++++++++++-------------- github/projects.go | 28 +++++++++++++++------------- github/projects_test.go | 12 ++++++------ 5 files changed, 82 insertions(+), 42 deletions(-) diff --git a/github/github-accessors.go b/github/github-accessors.go index 68de9bb17c0..825d6e442d1 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -10236,6 +10236,14 @@ func (p *Project) GetNumber() int { return *p.Number } +// GetOrganizationPermission returns the OrganizationPermission field if it's non-nil, zero value otherwise. +func (p *Project) GetOrganizationPermission() string { + if p == nil || p.OrganizationPermission == nil { + return "" + } + return *p.OrganizationPermission +} + // GetOwnerURL returns the OwnerURL field if it's non-nil, zero value otherwise. func (p *Project) GetOwnerURL() string { if p == nil || p.OwnerURL == nil { @@ -10244,6 +10252,14 @@ func (p *Project) GetOwnerURL() string { return *p.OwnerURL } +// GetPrivate returns the Private field if it's non-nil, zero value otherwise. +func (p *Project) GetPrivate() bool { + if p == nil || p.Private == nil { + return false + } + return *p.Private +} + // GetState returns the State field if it's non-nil, zero value otherwise. func (p *Project) GetState() string { if p == nil || p.State == nil { @@ -10748,12 +10764,12 @@ func (p *ProjectOptions) GetOrganizationPermission() string { return *p.OrganizationPermission } -// GetPublic returns the Public field if it's non-nil, zero value otherwise. -func (p *ProjectOptions) GetPublic() bool { - if p == nil || p.Public == nil { +// GetPrivate returns the Private field if it's non-nil, zero value otherwise. +func (p *ProjectOptions) GetPrivate() bool { + if p == nil || p.Private == nil { return false } - return *p.Public + return *p.Private } // GetState returns the State field if it's non-nil, zero value otherwise. diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index aa9bd566825..bdcd1726686 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -11998,6 +11998,16 @@ func TestProject_GetNumber(tt *testing.T) { p.GetNumber() } +func TestProject_GetOrganizationPermission(tt *testing.T) { + var zeroValue string + p := &Project{OrganizationPermission: &zeroValue} + p.GetOrganizationPermission() + p = &Project{} + p.GetOrganizationPermission() + p = nil + p.GetOrganizationPermission() +} + func TestProject_GetOwnerURL(tt *testing.T) { var zeroValue string p := &Project{OwnerURL: &zeroValue} @@ -12008,6 +12018,16 @@ func TestProject_GetOwnerURL(tt *testing.T) { p.GetOwnerURL() } +func TestProject_GetPrivate(tt *testing.T) { + var zeroValue bool + p := &Project{Private: &zeroValue} + p.GetPrivate() + p = &Project{} + p.GetPrivate() + p = nil + p.GetPrivate() +} + func TestProject_GetState(tt *testing.T) { var zeroValue string p := &Project{State: &zeroValue} @@ -12569,14 +12589,14 @@ func TestProjectOptions_GetOrganizationPermission(tt *testing.T) { p.GetOrganizationPermission() } -func TestProjectOptions_GetPublic(tt *testing.T) { +func TestProjectOptions_GetPrivate(tt *testing.T) { var zeroValue bool - p := &ProjectOptions{Public: &zeroValue} - p.GetPublic() + p := &ProjectOptions{Private: &zeroValue} + p.GetPrivate() p = &ProjectOptions{} - p.GetPublic() + p.GetPrivate() p = nil - p.GetPublic() + p.GetPrivate() } func TestProjectOptions_GetState(tt *testing.T) { diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index 19334ea1e11..a7296d60d0e 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -1116,21 +1116,23 @@ func TestPreReceiveHook_String(t *testing.T) { func TestProject_String(t *testing.T) { v := Project{ - ID: Int64(0), - URL: String(""), - HTMLURL: String(""), - ColumnsURL: String(""), - OwnerURL: String(""), - Name: String(""), - Body: String(""), - Number: Int(0), - State: String(""), - CreatedAt: &Timestamp{}, - UpdatedAt: &Timestamp{}, - NodeID: String(""), - Creator: &User{}, + ID: Int64(0), + URL: String(""), + HTMLURL: String(""), + ColumnsURL: String(""), + OwnerURL: String(""), + Name: String(""), + Body: String(""), + Number: Int(0), + State: String(""), + CreatedAt: &Timestamp{}, + UpdatedAt: &Timestamp{}, + NodeID: String(""), + OrganizationPermission: String(""), + Private: Bool(false), + Creator: &User{}, } - want := `github.Project{ID:0, URL:"", HTMLURL:"", ColumnsURL:"", OwnerURL:"", Name:"", Body:"", Number:0, State:"", CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, NodeID:"", Creator:github.User{}}` + want := `github.Project{ID:0, URL:"", HTMLURL:"", ColumnsURL:"", OwnerURL:"", Name:"", Body:"", Number:0, State:"", CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, NodeID:"", OrganizationPermission:"", Private:false, Creator:github.User{}}` if got := v.String(); got != want { t.Errorf("Project.String = %v, want %v", got, want) } diff --git a/github/projects.go b/github/projects.go index 12c00bc3b70..2886c3a3b04 100644 --- a/github/projects.go +++ b/github/projects.go @@ -18,18 +18,20 @@ type ProjectsService service // Project represents a GitHub Project. type Project struct { - ID *int64 `json:"id,omitempty"` - URL *string `json:"url,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` - ColumnsURL *string `json:"columns_url,omitempty"` - OwnerURL *string `json:"owner_url,omitempty"` - Name *string `json:"name,omitempty"` - Body *string `json:"body,omitempty"` - Number *int `json:"number,omitempty"` - State *string `json:"state,omitempty"` - CreatedAt *Timestamp `json:"created_at,omitempty"` - UpdatedAt *Timestamp `json:"updated_at,omitempty"` - NodeID *string `json:"node_id,omitempty"` + ID *int64 `json:"id,omitempty"` + URL *string `json:"url,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + ColumnsURL *string `json:"columns_url,omitempty"` + OwnerURL *string `json:"owner_url,omitempty"` + Name *string `json:"name,omitempty"` + Body *string `json:"body,omitempty"` + Number *int `json:"number,omitempty"` + State *string `json:"state,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + NodeID *string `json:"node_id,omitempty"` + OrganizationPermission *string `json:"organization_permission,omitempty"` + Private *bool `json:"private,omitempty"` // The User object that generated the project. Creator *User `json:"creator,omitempty"` @@ -83,7 +85,7 @@ type ProjectOptions struct { // Sets visibility of the project within the organization. // Setting visibility is only available // for organization projects.(Optional.) - Public *bool `json:"public,omitempty"` + Private *bool `json:"private,omitempty"` } // UpdateProject updates a repository project. diff --git a/github/projects_test.go b/github/projects_test.go index 6960ce90213..27be57feeb3 100644 --- a/github/projects_test.go +++ b/github/projects_test.go @@ -89,10 +89,10 @@ func TestProjectsService_UpdateProject(t *testing.T) { defer teardown() input := &ProjectOptions{ - Name: String("Project Name"), - Body: String("Project body."), - State: String("open"), - Public: Bool(true), + Name: String("Project Name"), + Body: String("Project body."), + State: String("open"), + Private: Bool(true), OrganizationPermission: String("read"), } @@ -857,7 +857,7 @@ func TestProjectOptions_Marshal(t *testing.T) { Body: String("body"), State: String("state"), OrganizationPermission: String("op"), - Public: Bool(true), + Private: Bool(true), } want := `{ @@ -865,7 +865,7 @@ func TestProjectOptions_Marshal(t *testing.T) { "body": "body", "state": "state", "organization_permission": "op", - "public": true + "private": true }` testJSONMarshal(t, u, want) From 77bc22d2e8135fe00c070ffd321f71f06d82bf3d Mon Sep 17 00:00:00 2001 From: Dariusz Porowski Date: Tue, 28 Sep 2021 21:07:15 +0200 Subject: [PATCH 2/2] logic change --- github/projects_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/github/projects_test.go b/github/projects_test.go index 27be57feeb3..c4ccbd092af 100644 --- a/github/projects_test.go +++ b/github/projects_test.go @@ -92,7 +92,7 @@ func TestProjectsService_UpdateProject(t *testing.T) { Name: String("Project Name"), Body: String("Project body."), State: String("open"), - Private: Bool(true), + Private: Bool(false), OrganizationPermission: String("read"), } @@ -857,7 +857,7 @@ func TestProjectOptions_Marshal(t *testing.T) { Body: String("body"), State: String("state"), OrganizationPermission: String("op"), - Private: Bool(true), + Private: Bool(false), } want := `{ @@ -865,7 +865,7 @@ func TestProjectOptions_Marshal(t *testing.T) { "body": "body", "state": "state", "organization_permission": "op", - "private": true + "private": false }` testJSONMarshal(t, u, want)