Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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: 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.
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.
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
Loading