From 9adf0ba7f0bca93323d50ac036b9bb5525f23354 Mon Sep 17 00:00:00 2001 From: munlicode Date: Wed, 25 Feb 2026 21:48:37 +0500 Subject: [PATCH] feat: Add Type field to Team struct --- github/copilot_test.go | 8 ++++---- github/github-accessors.go | 8 ++++++++ github/github-accessors_test.go | 11 +++++++++++ github/github-stringify_test.go | 3 ++- github/teams.go | 4 ++++ github/teams_test.go | 12 +++++++----- 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/github/copilot_test.go b/github/copilot_test.go index 823ac92043e..2565b330a64 100644 --- a/github/copilot_test.go +++ b/github/copilot_test.go @@ -207,7 +207,8 @@ func TestCopilotService_GetSeatDetailsTeam(t *testing.T) { } want := &Team{ - ID: Ptr(int64(1)), + ID: Ptr(int64(1)), + Type: Ptr("Team"), } if got, ok := seatDetails.GetTeam(); ok && !cmp.Equal(got, want) { @@ -575,6 +576,7 @@ func TestCopilotService_ListCopilotSeats(t *testing.T) { Assignee: &Team{ ID: Ptr(int64(1)), Name: Ptr("octokittens"), + Type: Ptr("Team"), }, AssigningTeam: nil, CreatedAt: &createdAt2, @@ -599,9 +601,7 @@ func TestCopilotService_ListCopilotSeats(t *testing.T) { }, } - if !cmp.Equal(got, want) { - t.Errorf("Copilot.ListCopilotSeats returned %+v, want %+v", got, want) - } + assertNoDiff(t, want, got) const methodName = "ListCopilotSeats" diff --git a/github/github-accessors.go b/github/github-accessors.go index 73ff2a4f3fa..70b20e70dc9 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -29358,6 +29358,14 @@ func (t *Team) GetSlug() string { return *t.Slug } +// GetType returns the Type field if it's non-nil, zero value otherwise. +func (t *Team) GetType() string { + if t == nil || t.Type == nil { + return "" + } + return *t.Type +} + // GetURL returns the URL field if it's non-nil, zero value otherwise. func (t *Team) GetURL() string { if t == nil || t.URL == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index ef28f61d699..c9441a749c0 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -37861,6 +37861,17 @@ func TestTeam_GetSlug(tt *testing.T) { t.GetSlug() } +func TestTeam_GetType(tt *testing.T) { + tt.Parallel() + var zeroValue string + t := &Team{Type: &zeroValue} + t.GetType() + t = &Team{} + t.GetType() + t = nil + t.GetType() +} + func TestTeam_GetURL(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go index e134a127a91..edd28ddb50a 100644 --- a/github/github-stringify_test.go +++ b/github/github-stringify_test.go @@ -2251,8 +2251,9 @@ func TestTeam_String(t *testing.T) { Parent: &Team{}, LDAPDN: Ptr(""), Assignment: Ptr(""), + Type: Ptr(""), } - want := `github.Team{ID:0, NodeID:"", Name:"", Description:"", URL:"", Slug:"", Permission:"", Privacy:"", NotificationSetting:"", MembersCount:0, ReposCount:0, Organization:github.Organization{}, HTMLURL:"", MembersURL:"", RepositoriesURL:"", Parent:github.Team{}, LDAPDN:"", Assignment:""}` + want := `github.Team{ID:0, NodeID:"", Name:"", Description:"", URL:"", Slug:"", Permission:"", Privacy:"", NotificationSetting:"", MembersCount:0, ReposCount:0, Organization:github.Organization{}, HTMLURL:"", MembersURL:"", RepositoriesURL:"", Parent:github.Team{}, LDAPDN:"", Assignment:"", Type:""}` if got := v.String(); got != want { t.Errorf("Team.String = %v, want %v", got, want) } diff --git a/github/teams.go b/github/teams.go index e4d7e9c4aca..cf9a616d3fd 100644 --- a/github/teams.go +++ b/github/teams.go @@ -60,6 +60,10 @@ type Team struct { // possible values are: "direct", "indirect", "mixed". This is only populated when // calling the ListTeamsAssignedToOrgRole method. Assignment *string `json:"assignment,omitempty"` + + // Type identifies the ownership type of the team + // Possible values are: "organization", "enterprise". + Type *string `json:"type,omitempty"` } func (t Team) String() string { diff --git a/github/teams_test.go b/github/teams_test.go index 735d86c3a57..c1de4fea406 100644 --- a/github/teams_test.go +++ b/github/teams_test.go @@ -68,7 +68,7 @@ func TestTeamsService_GetTeamByID(t *testing.T) { mux.HandleFunc("/organizations/1/team/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"id":1, "name":"n", "description": "d", "url":"u", "slug": "s", "permission":"p", "ldap_dn":"cn=n,ou=groups,dc=example,dc=com", "parent":null}`) + fmt.Fprint(w, `{"id":1, "name":"n", "description": "d", "url":"u", "slug": "s", "permission":"p", "ldap_dn":"cn=n,ou=groups,dc=example,dc=com", "type": "organization", "parent":null}`) }) ctx := t.Context() @@ -77,7 +77,7 @@ func TestTeamsService_GetTeamByID(t *testing.T) { t.Errorf("Teams.GetTeamByID returned error: %v", err) } - want := &Team{ID: Ptr(int64(1)), Name: Ptr("n"), Description: Ptr("d"), URL: Ptr("u"), Slug: Ptr("s"), Permission: Ptr("p"), LDAPDN: Ptr("cn=n,ou=groups,dc=example,dc=com")} + want := &Team{ID: Ptr(int64(1)), Name: Ptr("n"), Description: Ptr("d"), URL: Ptr("u"), Slug: Ptr("s"), Permission: Ptr("p"), LDAPDN: Ptr("cn=n,ou=groups,dc=example,dc=com"), Type: Ptr("organization")} if !cmp.Equal(team, want) { t.Errorf("Teams.GetTeamByID returned %+v, want %+v", team, want) } @@ -125,7 +125,7 @@ func TestTeamsService_GetTeamBySlug(t *testing.T) { mux.HandleFunc("/orgs/o/teams/s", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `{"id":1, "name":"n", "description": "d", "url":"u", "slug": "s", "permission":"p", "ldap_dn":"cn=n,ou=groups,dc=example,dc=com", "parent":null}`) + fmt.Fprint(w, `{"id":1, "name":"n", "description": "d", "url":"u", "slug": "s", "permission":"p", "ldap_dn":"cn=n,ou=groups,dc=example,dc=com", "type": "organization", "parent":null}`) }) ctx := t.Context() @@ -134,7 +134,7 @@ func TestTeamsService_GetTeamBySlug(t *testing.T) { t.Errorf("Teams.GetTeamBySlug returned error: %v", err) } - want := &Team{ID: Ptr(int64(1)), Name: Ptr("n"), Description: Ptr("d"), URL: Ptr("u"), Slug: Ptr("s"), Permission: Ptr("p"), LDAPDN: Ptr("cn=n,ou=groups,dc=example,dc=com")} + want := &Team{ID: Ptr(int64(1)), Name: Ptr("n"), Description: Ptr("d"), URL: Ptr("u"), Slug: Ptr("s"), Permission: Ptr("p"), LDAPDN: Ptr("cn=n,ou=groups,dc=example,dc=com"), Type: Ptr("organization")} if !cmp.Equal(team, want) { t.Errorf("Teams.GetTeamBySlug returned %+v, want %+v", team, want) } @@ -1650,6 +1650,7 @@ func TestTeams_Marshal(t *testing.T) { ReposCount: Ptr(1), }, LDAPDN: Ptr("l"), + Type: Ptr("t"), } want := `{ @@ -1689,7 +1690,8 @@ func TestTeams_Marshal(t *testing.T) { "members_count": 1, "repos_count": 1 }, - "ldap_dn": "l" + "ldap_dn": "l", + "type": "t" }` testJSONMarshal(t, u, want)