Skip to content

Commit

Permalink
Add name field for org api (#21270)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
KN4CK3R authored Sep 29, 2022
1 parent 1dfa28f commit b7309b8
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions modules/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ func ToOrganization(org *organization.Organization) *api.Organization {
return &api.Organization{
ID: org.ID,
AvatarURL: org.AsUser().AvatarLink(),
Name: org.Name,
UserName: org.Name,
FullName: org.FullName,
Description: org.Description,
Expand Down
4 changes: 3 additions & 1 deletion modules/structs/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ package structs
// Organization represents an organization
type Organization struct {
ID int64 `json:"id"`
UserName string `json:"username"`
Name string `json:"name"`
FullName string `json:"full_name"`
AvatarURL string `json:"avatar_url"`
Description string `json:"description"`
Website string `json:"website"`
Location string `json:"location"`
Visibility string `json:"visibility"`
RepoAdminChangeTeamAccess bool `json:"repo_admin_change_team_access"`
// deprecated
UserName string `json:"username"`
}

// OrganizationPermissions list different users permissions on an organization
Expand Down
5 changes: 5 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17326,11 +17326,16 @@
"type": "string",
"x-go-name": "Location"
},
"name": {
"type": "string",
"x-go-name": "Name"
},
"repo_admin_change_team_access": {
"type": "boolean",
"x-go-name": "RepoAdminChangeTeamAccess"
},
"username": {
"description": "deprecated",
"type": "string",
"x-go-name": "UserName"
},
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/api_admin_org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestAPIAdminOrgCreate(t *testing.T) {
var apiOrg api.Organization
DecodeJSON(t, resp, &apiOrg)

assert.Equal(t, org.UserName, apiOrg.UserName)
assert.Equal(t, org.UserName, apiOrg.Name)
assert.Equal(t, org.FullName, apiOrg.FullName)
assert.Equal(t, org.Description, apiOrg.Description)
assert.Equal(t, org.Website, apiOrg.Website)
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/api_org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestAPIOrgCreate(t *testing.T) {
var apiOrg api.Organization
DecodeJSON(t, resp, &apiOrg)

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

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

assert.Equal(t, "user3", apiOrg.UserName)
assert.Equal(t, "user3", apiOrg.Name)
assert.Equal(t, org.FullName, apiOrg.FullName)
assert.Equal(t, org.Description, apiOrg.Description)
assert.Equal(t, org.Website, apiOrg.Website)
Expand Down
4 changes: 4 additions & 0 deletions tests/integration/api_user_orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestUserOrgs(t *testing.T) {
assert.Equal(t, []*api.Organization{
{
ID: 17,
Name: user17.Name,
UserName: user17.Name,
FullName: user17.FullName,
AvatarURL: user17.AvatarLink(),
Expand All @@ -42,6 +43,7 @@ func TestUserOrgs(t *testing.T) {
},
{
ID: 3,
Name: user3.Name,
UserName: user3.Name,
FullName: user3.FullName,
AvatarURL: user3.AvatarLink(),
Expand Down Expand Up @@ -99,6 +101,7 @@ func TestMyOrgs(t *testing.T) {
assert.Equal(t, []*api.Organization{
{
ID: 17,
Name: user17.Name,
UserName: user17.Name,
FullName: user17.FullName,
AvatarURL: user17.AvatarLink(),
Expand All @@ -109,6 +112,7 @@ func TestMyOrgs(t *testing.T) {
},
{
ID: 3,
Name: user3.Name,
UserName: user3.Name,
FullName: user3.FullName,
AvatarURL: user3.AvatarLink(),
Expand Down

0 comments on commit b7309b8

Please sign in to comment.