diff --git a/gitea/admin_test.go b/gitea/admin_test.go index 40ec11b..fa2244d 100644 --- a/gitea/admin_test.go +++ b/gitea/admin_test.go @@ -22,8 +22,7 @@ func TestAdminOrg(t *testing.T) { UserName: orgName, FullName: orgName + " FullName", Description: "test adminCreateOrg", - // enum: public,limited,private - Visibility: "public", + Visibility: VisibleTypePublic, }) assert.NoError(t, err) assert.NotEmpty(t, newOrg) diff --git a/gitea/org.go b/gitea/org.go index 0e98adb..48ea9da 100644 --- a/gitea/org.go +++ b/gitea/org.go @@ -23,6 +23,20 @@ type Organization struct { Visibility string `json:"visibility"` } +// VisibleType defines the visibility +type VisibleType string + +const ( + // VisibleTypePublic Visible for everyone + VisibleTypePublic VisibleType = "public" + + // VisibleTypeLimited Visible for every connected user + VisibleTypeLimited VisibleType = "limited" + + // VisibleTypePrivate Visible only for organization's members + VisibleTypePrivate VisibleType = "private" +) + // ListOrgsOptions options for listing organizations type ListOrgsOptions struct { ListOptions @@ -50,18 +64,17 @@ func (c *Client) GetOrg(orgname string) (*Organization, error) { // CreateOrgOption options for creating an organization type CreateOrgOption struct { - UserName string `json:"username"` - FullName string `json:"full_name"` - Description string `json:"description"` - Website string `json:"website"` - Location string `json:"location"` - // possible values are `public` (default), `limited` or `private` - Visibility string `json:"visibility"` + UserName string `json:"username"` + FullName string `json:"full_name"` + Description string `json:"description"` + Website string `json:"website"` + Location string `json:"location"` + Visibility VisibleType `json:"visibility"` } // checkVisibilityOpt check if mode exist -func checkVisibilityOpt(v string) bool { - return v == "public" || v == "limited" || v == "private" +func checkVisibilityOpt(v VisibleType) bool { + return v == VisibleTypePublic || v == VisibleTypeLimited || v == VisibleTypePrivate } // Validate the CreateOrgOption struct @@ -90,12 +103,11 @@ func (c *Client) CreateOrg(opt CreateOrgOption) (*Organization, error) { // EditOrgOption options for editing an organization type EditOrgOption struct { - FullName string `json:"full_name"` - Description string `json:"description"` - Website string `json:"website"` - Location string `json:"location"` - // possible values are `public`, `limited` or `private` - Visibility string `json:"visibility"` + FullName string `json:"full_name"` + Description string `json:"description"` + Website string `json:"website"` + Location string `json:"location"` + Visibility VisibleType `json:"visibility"` } // Validate the EditOrgOption struct diff --git a/gitea/org_type.go b/gitea/org_type.go deleted file mode 100644 index 930be18..0000000 --- a/gitea/org_type.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2019 The Gitea Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package gitea - -// VisibleType defines the visibility (Organization only) -type VisibleType int - -const ( - // VisibleTypePublic Visible for everyone - VisibleTypePublic VisibleType = iota - - // VisibleTypeLimited Visible for every connected user - VisibleTypeLimited - - // VisibleTypePrivate Visible only for organization's members - VisibleTypePrivate -) - -// ExtractKeysFromMapString provides a slice of keys from map -func ExtractKeysFromMapString(in map[string]VisibleType) (keys []string) { - for k := range in { - keys = append(keys, k) - } - return -}