@@ -10,15 +10,19 @@ import (
1010 "encoding/json"
1111 "errors"
1212 "fmt"
13+ "strconv"
1314)
1415
16+ // PropertyValueType represents the type of a custom property value.
17+ type PropertyValueType string
18+
1519// Valid values for CustomProperty.ValueType.
1620const (
17- PropertyValueTypeString = "string"
18- PropertyValueTypeSingleSelect = "single_select"
19- PropertyValueTypeMultiSelect = "multi_select"
20- PropertyValueTypeTrueFalse = "true_false"
21- PropertyValueTypeURL = "url"
21+ PropertyValueTypeString PropertyValueType = "string"
22+ PropertyValueTypeSingleSelect PropertyValueType = "single_select"
23+ PropertyValueTypeMultiSelect PropertyValueType = "multi_select"
24+ PropertyValueTypeTrueFalse PropertyValueType = "true_false"
25+ PropertyValueTypeURL PropertyValueType = "url"
2226)
2327
2428// CustomProperty represents an organization custom property object.
@@ -31,11 +35,11 @@ type CustomProperty struct {
3135 // SourceType is the source type of the property where it has been created. Can be one of: organization, enterprise.
3236 SourceType * string `json:"source_type,omitempty"`
3337 // The type of the value for the property. Can be one of: string, single_select, multi_select, true_false, url.
34- ValueType string `json:"value_type"`
38+ ValueType PropertyValueType `json:"value_type"`
3539 // Whether the property is required.
3640 Required * bool `json:"required,omitempty"`
3741 // Default value of the property.
38- DefaultValue * string `json:"default_value,omitempty"`
42+ DefaultValue any `json:"default_value,omitempty"`
3943 // Short description of the property.
4044 Description * string `json:"description,omitempty"`
4145 // An ordered list of the allowed values of the property. The property can have up to 200
@@ -45,6 +49,42 @@ type CustomProperty struct {
4549 ValuesEditableBy * string `json:"values_editable_by,omitempty"`
4650}
4751
52+ // DefaultValueString returns the DefaultValue as a string if the ValueType is string or single_select or url.
53+ func (cp CustomProperty ) DefaultValueString () (string , bool ) {
54+ switch cp .ValueType {
55+ case PropertyValueTypeString , PropertyValueTypeSingleSelect , PropertyValueTypeURL :
56+ s , ok := cp .DefaultValue .(string )
57+ return s , ok
58+ default :
59+ return "" , false
60+ }
61+ }
62+
63+ // DefaultValueStrings returns the DefaultValue as a slice of string if the ValueType is string or multi_select.
64+ func (cp CustomProperty ) DefaultValueStrings () ([]string , bool ) {
65+ switch cp .ValueType {
66+ case PropertyValueTypeMultiSelect :
67+ s , ok := cp .DefaultValue .([]string )
68+ return s , ok
69+ default :
70+ return nil , false
71+ }
72+ }
73+
74+ // DefaultValueBool returns the DefaultValue as a string if the ValueType is string or true_false.
75+ func (cp CustomProperty ) DefaultValueBool () (bool , bool ) {
76+ switch cp .ValueType {
77+ case PropertyValueTypeTrueFalse :
78+ if s , ok := cp .DefaultValue .(string ); ok {
79+ b , err := strconv .ParseBool (s )
80+ return b , err == nil
81+ }
82+ return false , false
83+ default :
84+ return false , false
85+ }
86+ }
87+
4888// RepoCustomPropertyValue represents a repository custom property value.
4989type RepoCustomPropertyValue struct {
5090 RepositoryID int64 `json:"repository_id"`
0 commit comments