Skip to content

Commit b7309b8

Browse files
authored
Add name field for org api (#21270)
related #21205 The field `UserName` is not really usefull for an organization. This adds a second `Name` field. The [GitHub API](https://docs.github.com/en/rest/orgs/orgs#get-an-organization) uses `name` too. `UserName` should be deprecated then.
1 parent 1dfa28f commit b7309b8

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-5
lines changed

modules/convert/convert.go

+1
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ func ToOrganization(org *organization.Organization) *api.Organization {
296296
return &api.Organization{
297297
ID: org.ID,
298298
AvatarURL: org.AsUser().AvatarLink(),
299+
Name: org.Name,
299300
UserName: org.Name,
300301
FullName: org.FullName,
301302
Description: org.Description,

modules/structs/org.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ package structs
77
// Organization represents an organization
88
type Organization struct {
99
ID int64 `json:"id"`
10-
UserName string `json:"username"`
10+
Name string `json:"name"`
1111
FullName string `json:"full_name"`
1212
AvatarURL string `json:"avatar_url"`
1313
Description string `json:"description"`
1414
Website string `json:"website"`
1515
Location string `json:"location"`
1616
Visibility string `json:"visibility"`
1717
RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"`
18+
// deprecated
19+
UserName string `json:"username"`
1820
}
1921

2022
// OrganizationPermissions list different users permissions on an organization

templates/swagger/v1_json.tmpl

+5
Original file line numberDiff line numberDiff line change
@@ -17326,11 +17326,16 @@
1732617326
"type": "string",
1732717327
"x-go-name": "Location"
1732817328
},
17329+
"name": {
17330+
"type": "string",
17331+
"x-go-name": "Name"
17332+
},
1732917333
"repo_admin_change_team_access": {
1733017334
"type": "boolean",
1733117335
"x-go-name": "RepoAdminChangeTeamAccess"
1733217336
},
1733317337
"username": {
17338+
"description": "deprecated",
1733417339
"type": "string",
1733517340
"x-go-name": "UserName"
1733617341
},

tests/integration/api_admin_org_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestAPIAdminOrgCreate(t *testing.T) {
3737
var apiOrg api.Organization
3838
DecodeJSON(t, resp, &apiOrg)
3939

40-
assert.Equal(t, org.UserName, apiOrg.UserName)
40+
assert.Equal(t, org.UserName, apiOrg.Name)
4141
assert.Equal(t, org.FullName, apiOrg.FullName)
4242
assert.Equal(t, org.Description, apiOrg.Description)
4343
assert.Equal(t, org.Website, apiOrg.Website)

tests/integration/api_org_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestAPIOrgCreate(t *testing.T) {
3838
var apiOrg api.Organization
3939
DecodeJSON(t, resp, &apiOrg)
4040

41-
assert.Equal(t, org.UserName, apiOrg.UserName)
41+
assert.Equal(t, org.UserName, apiOrg.Name)
4242
assert.Equal(t, org.FullName, apiOrg.FullName)
4343
assert.Equal(t, org.Description, apiOrg.Description)
4444
assert.Equal(t, org.Website, apiOrg.Website)
@@ -54,7 +54,7 @@ func TestAPIOrgCreate(t *testing.T) {
5454
req = NewRequestf(t, "GET", "/api/v1/orgs/%s?token=%s", org.UserName, token)
5555
resp = MakeRequest(t, req, http.StatusOK)
5656
DecodeJSON(t, resp, &apiOrg)
57-
assert.EqualValues(t, org.UserName, apiOrg.UserName)
57+
assert.EqualValues(t, org.UserName, apiOrg.Name)
5858

5959
req = NewRequestf(t, "GET", "/api/v1/orgs/%s/repos?token=%s", org.UserName, token)
6060
resp = MakeRequest(t, req, http.StatusOK)
@@ -94,7 +94,7 @@ func TestAPIOrgEdit(t *testing.T) {
9494
var apiOrg api.Organization
9595
DecodeJSON(t, resp, &apiOrg)
9696

97-
assert.Equal(t, "user3", apiOrg.UserName)
97+
assert.Equal(t, "user3", apiOrg.Name)
9898
assert.Equal(t, org.FullName, apiOrg.FullName)
9999
assert.Equal(t, org.Description, apiOrg.Description)
100100
assert.Equal(t, org.Website, apiOrg.Website)

tests/integration/api_user_orgs_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func TestUserOrgs(t *testing.T) {
3232
assert.Equal(t, []*api.Organization{
3333
{
3434
ID: 17,
35+
Name: user17.Name,
3536
UserName: user17.Name,
3637
FullName: user17.FullName,
3738
AvatarURL: user17.AvatarLink(),
@@ -42,6 +43,7 @@ func TestUserOrgs(t *testing.T) {
4243
},
4344
{
4445
ID: 3,
46+
Name: user3.Name,
4547
UserName: user3.Name,
4648
FullName: user3.FullName,
4749
AvatarURL: user3.AvatarLink(),
@@ -99,6 +101,7 @@ func TestMyOrgs(t *testing.T) {
99101
assert.Equal(t, []*api.Organization{
100102
{
101103
ID: 17,
104+
Name: user17.Name,
102105
UserName: user17.Name,
103106
FullName: user17.FullName,
104107
AvatarURL: user17.AvatarLink(),
@@ -109,6 +112,7 @@ func TestMyOrgs(t *testing.T) {
109112
},
110113
{
111114
ID: 3,
115+
Name: user3.Name,
112116
UserName: user3.Name,
113117
FullName: user3.FullName,
114118
AvatarURL: user3.AvatarLink(),

0 commit comments

Comments
 (0)