Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions github/enterprise_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestEnterpriseService_GetAllCustomProperties(t *testing.T) {
PropertyName: Ptr("name"),
ValueType: PropertyValueTypeSingleSelect,
Required: Ptr(true),
DefaultValue: Ptr("production"),
DefaultValue: "production",
Description: Ptr("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: Ptr("org_actors"),
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestEnterpriseService_GetCustomProperty(t *testing.T) {
PropertyName: Ptr("name"),
ValueType: PropertyValueTypeSingleSelect,
Required: Ptr(true),
DefaultValue: Ptr("production"),
DefaultValue: "production",
Description: Ptr("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: Ptr("org_actors"),
Expand Down Expand Up @@ -222,7 +222,7 @@ func TestEnterpriseService_CreateOrUpdateCustomProperty(t *testing.T) {
property, _, err := client.Enterprise.CreateOrUpdateCustomProperty(ctx, "e", "name", &CustomProperty{
ValueType: PropertyValueTypeSingleSelect,
Required: Ptr(true),
DefaultValue: Ptr("production"),
DefaultValue: "production",
Description: Ptr("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: Ptr("org_actors"),
Expand All @@ -235,7 +235,7 @@ func TestEnterpriseService_CreateOrUpdateCustomProperty(t *testing.T) {
PropertyName: Ptr("name"),
ValueType: PropertyValueTypeSingleSelect,
Required: Ptr(true),
DefaultValue: Ptr("production"),
DefaultValue: "production",
Description: Ptr("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: Ptr("org_actors"),
Expand Down
2 changes: 1 addition & 1 deletion github/event_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13732,7 +13732,7 @@ func TestCustomPropertyEvent_Marshal(t *testing.T) {
ValueType: PropertyValueTypeSingleSelect,
SourceType: Ptr("enterprise"),
Required: Ptr(true),
DefaultValue: Ptr("production"),
DefaultValue: "production",
Description: Ptr("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: Ptr("org_actors"),
Expand Down
8 changes: 0 additions & 8 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 47 additions & 7 deletions github/orgs_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import (
"encoding/json"
"errors"
"fmt"
"strconv"
)

// PropertyValueType represents the type of a custom property value.
type PropertyValueType string

// Valid values for CustomProperty.ValueType.
const (
PropertyValueTypeString = "string"
PropertyValueTypeSingleSelect = "single_select"
PropertyValueTypeMultiSelect = "multi_select"
PropertyValueTypeTrueFalse = "true_false"
PropertyValueTypeURL = "url"
PropertyValueTypeString PropertyValueType = "string"
PropertyValueTypeSingleSelect PropertyValueType = "single_select"
PropertyValueTypeMultiSelect PropertyValueType = "multi_select"
PropertyValueTypeTrueFalse PropertyValueType = "true_false"
PropertyValueTypeURL PropertyValueType = "url"
)

// CustomProperty represents an organization custom property object.
Expand All @@ -31,11 +35,11 @@ type CustomProperty struct {
// SourceType is the source type of the property where it has been created. Can be one of: organization, enterprise.
SourceType *string `json:"source_type,omitempty"`
// The type of the value for the property. Can be one of: string, single_select, multi_select, true_false, url.
ValueType string `json:"value_type"`
ValueType PropertyValueType `json:"value_type"`
// Whether the property is required.
Required *bool `json:"required,omitempty"`
// Default value of the property.
DefaultValue *string `json:"default_value,omitempty"`
DefaultValue any `json:"default_value,omitempty"`
// Short description of the property.
Description *string `json:"description,omitempty"`
// An ordered list of the allowed values of the property. The property can have up to 200
Expand All @@ -45,6 +49,42 @@ type CustomProperty struct {
ValuesEditableBy *string `json:"values_editable_by,omitempty"`
}

// DefaultValueString returns the DefaultValue as a string if the ValueType is string or single_select or url.
func (cp CustomProperty) DefaultValueString() (string, bool) {
switch cp.ValueType {
case PropertyValueTypeString, PropertyValueTypeSingleSelect, PropertyValueTypeURL:
s, ok := cp.DefaultValue.(string)
return s, ok
default:
return "", false
}
}

// DefaultValueStrings returns the DefaultValue as a slice of string if the ValueType is string or multi_select.
Comment thread
stevehipwell marked this conversation as resolved.
Outdated
func (cp CustomProperty) DefaultValueStrings() ([]string, bool) {
switch cp.ValueType {
case PropertyValueTypeMultiSelect:
s, ok := cp.DefaultValue.([]string)
return s, ok
default:
return nil, false
}
}

// DefaultValueBool returns the DefaultValue as a string if the ValueType is string or true_false.
Comment thread
stevehipwell marked this conversation as resolved.
Outdated
func (cp CustomProperty) DefaultValueBool() (bool, bool) {
switch cp.ValueType {
case PropertyValueTypeTrueFalse:
if s, ok := cp.DefaultValue.(string); ok {
b, err := strconv.ParseBool(s)
return b, err == nil
}
return false, false
default:
return false, false
}
}

// RepoCustomPropertyValue represents a repository custom property value.
type RepoCustomPropertyValue struct {
RepositoryID int64 `json:"repository_id"`
Expand Down
10 changes: 5 additions & 5 deletions github/orgs_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestOrganizationsService_GetAllCustomProperties(t *testing.T) {
PropertyName: Ptr("name"),
ValueType: PropertyValueTypeSingleSelect,
Required: Ptr(true),
DefaultValue: Ptr("production"),
DefaultValue: "production",
Description: Ptr("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: Ptr("org_actors"),
Expand All @@ -81,7 +81,7 @@ func TestOrganizationsService_GetAllCustomProperties(t *testing.T) {
ValueType: PropertyValueTypeURL,
Required: Ptr(true),
Description: Ptr("Link to the documentation"),
DefaultValue: Ptr("https://example.com/docs"),
DefaultValue: "https://example.com/docs",
},
}
if !cmp.Equal(properties, want) {
Expand Down Expand Up @@ -192,7 +192,7 @@ func TestOrganizationsService_GetCustomProperty(t *testing.T) {
PropertyName: Ptr("name"),
ValueType: PropertyValueTypeSingleSelect,
Required: Ptr(true),
DefaultValue: Ptr("production"),
DefaultValue: "production",
Description: Ptr("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: Ptr("org_actors"),
Expand Down Expand Up @@ -236,7 +236,7 @@ func TestOrganizationsService_CreateOrUpdateCustomProperty(t *testing.T) {
property, _, err := client.Organizations.CreateOrUpdateCustomProperty(ctx, "o", "name", &CustomProperty{
ValueType: PropertyValueTypeSingleSelect,
Required: Ptr(true),
DefaultValue: Ptr("production"),
DefaultValue: "production",
Description: Ptr("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: Ptr("org_actors"),
Expand All @@ -249,7 +249,7 @@ func TestOrganizationsService_CreateOrUpdateCustomProperty(t *testing.T) {
PropertyName: Ptr("name"),
ValueType: PropertyValueTypeSingleSelect,
Required: Ptr(true),
DefaultValue: Ptr("production"),
DefaultValue: "production",
Description: Ptr("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: Ptr("org_actors"),
Expand Down
Loading