From 9d6bfd02c3f05e605f4e412071fbd1770def50a3 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Mon, 26 Sep 2022 18:59:36 +0000 Subject: [PATCH 1/4] Add Name field. --- modules/convert/convert.go | 1 + modules/structs/org.go | 1 + templates/swagger/v1_json.tmpl | 4 ++++ 3 files changed, 6 insertions(+) diff --git a/modules/convert/convert.go b/modules/convert/convert.go index c62b4303ed276..0c60a087745a3 100644 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -295,6 +295,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, diff --git a/modules/structs/org.go b/modules/structs/org.go index d8bd59e1ecb7a..b487c51b02b77 100644 --- a/modules/structs/org.go +++ b/modules/structs/org.go @@ -7,6 +7,7 @@ package structs // Organization represents an organization type Organization struct { ID int64 `json:"id"` + Name string `json:"name"` UserName string `json:"username"` FullName string `json:"full_name"` AvatarURL string `json:"avatar_url"` diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 15f71c244a0e4..35c461f9104a1 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -17206,6 +17206,10 @@ "type": "string", "x-go-name": "Location" }, + "name": { + "type": "string", + "x-go-name": "Name" + }, "repo_admin_change_team_access": { "type": "boolean", "x-go-name": "RepoAdminChangeTeamAccess" From b79a66c412e479e63f8d6e02b5064c2fcfa49a34 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Mon, 26 Sep 2022 19:23:13 +0000 Subject: [PATCH 2/4] Use Name in tests. --- modules/structs/org.go | 2 +- tests/integration/api_admin_org_test.go | 2 +- tests/integration/api_org_test.go | 6 +++--- tests/integration/api_user_orgs_test.go | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/modules/structs/org.go b/modules/structs/org.go index b487c51b02b77..b3546acbc9f05 100644 --- a/modules/structs/org.go +++ b/modules/structs/org.go @@ -8,7 +8,7 @@ package structs type Organization struct { ID int64 `json:"id"` Name string `json:"name"` - UserName string `json:"username"` + UserName string `json:"username"` // deprecated FullName string `json:"full_name"` AvatarURL string `json:"avatar_url"` Description string `json:"description"` diff --git a/tests/integration/api_admin_org_test.go b/tests/integration/api_admin_org_test.go index 720f6fc6b645b..a8770db4ca40a 100644 --- a/tests/integration/api_admin_org_test.go +++ b/tests/integration/api_admin_org_test.go @@ -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) diff --git a/tests/integration/api_org_test.go b/tests/integration/api_org_test.go index 4b8c5c97a8a56..16e53d6b81581 100644 --- a/tests/integration/api_org_test.go +++ b/tests/integration/api_org_test.go @@ -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) @@ -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) @@ -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) diff --git a/tests/integration/api_user_orgs_test.go b/tests/integration/api_user_orgs_test.go index 622dfdcf21e09..96356677c481d 100644 --- a/tests/integration/api_user_orgs_test.go +++ b/tests/integration/api_user_orgs_test.go @@ -32,7 +32,7 @@ func TestUserOrgs(t *testing.T) { assert.Equal(t, []*api.Organization{ { ID: 17, - UserName: user17.Name, + Name: user17.Name, FullName: user17.FullName, AvatarURL: user17.AvatarLink(), Description: "", @@ -42,7 +42,7 @@ func TestUserOrgs(t *testing.T) { }, { ID: 3, - UserName: user3.Name, + Name: user3.Name, FullName: user3.FullName, AvatarURL: user3.AvatarLink(), Description: "", @@ -99,7 +99,7 @@ func TestMyOrgs(t *testing.T) { assert.Equal(t, []*api.Organization{ { ID: 17, - UserName: user17.Name, + Name: user17.Name, FullName: user17.FullName, AvatarURL: user17.AvatarLink(), Description: "", @@ -109,7 +109,7 @@ func TestMyOrgs(t *testing.T) { }, { ID: 3, - UserName: user3.Name, + Name: user3.Name, FullName: user3.FullName, AvatarURL: user3.AvatarLink(), Description: "", From f281f450ac9773f75ed29ae49a2f901b3c4d77bd Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Mon, 26 Sep 2022 20:15:15 +0000 Subject: [PATCH 3/4] Fix tests. --- tests/integration/api_user_orgs_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/integration/api_user_orgs_test.go b/tests/integration/api_user_orgs_test.go index 96356677c481d..c28bf391eb3af 100644 --- a/tests/integration/api_user_orgs_test.go +++ b/tests/integration/api_user_orgs_test.go @@ -33,6 +33,7 @@ func TestUserOrgs(t *testing.T) { { ID: 17, Name: user17.Name, + UserName: user17.Name, FullName: user17.FullName, AvatarURL: user17.AvatarLink(), Description: "", @@ -43,6 +44,7 @@ func TestUserOrgs(t *testing.T) { { ID: 3, Name: user3.Name, + UserName: user3.Name, FullName: user3.FullName, AvatarURL: user3.AvatarLink(), Description: "", @@ -100,6 +102,7 @@ func TestMyOrgs(t *testing.T) { { ID: 17, Name: user17.Name, + UserName: user17.Name, FullName: user17.FullName, AvatarURL: user17.AvatarLink(), Description: "", @@ -110,6 +113,7 @@ func TestMyOrgs(t *testing.T) { { ID: 3, Name: user3.Name, + UserName: user3.Name, FullName: user3.FullName, AvatarURL: user3.AvatarLink(), Description: "", From f1dd54f3668cd7d21bf754733510b7f659f31435 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 27 Sep 2022 23:54:10 +0200 Subject: [PATCH 4/4] swagger contain deprecated note --- modules/structs/org.go | 3 ++- templates/swagger/v1_json.tmpl | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/structs/org.go b/modules/structs/org.go index b3546acbc9f05..1e98c59ba49c5 100644 --- a/modules/structs/org.go +++ b/modules/structs/org.go @@ -8,7 +8,6 @@ package structs type Organization struct { ID int64 `json:"id"` Name string `json:"name"` - UserName string `json:"username"` // deprecated FullName string `json:"full_name"` AvatarURL string `json:"avatar_url"` Description string `json:"description"` @@ -16,6 +15,8 @@ type Organization struct { 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 diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 35c461f9104a1..8880ed8e238b2 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -17215,6 +17215,7 @@ "x-go-name": "RepoAdminChangeTeamAccess" }, "username": { + "description": "deprecated", "type": "string", "x-go-name": "UserName" },