Skip to content
Merged
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: 8 additions & 0 deletions github/github-accessors.go

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

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

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

2 changes: 2 additions & 0 deletions github/orgs_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ type CustomProperty struct {
ValueType PropertyValueType `json:"value_type"`
// Whether the property is required.
Required *bool `json:"required,omitempty"`
// Whether setting property values is mandatory.
RequireExplicitValues *bool `json:"require_explicit_values,omitempty"`
// Default value of the property.
DefaultValue any `json:"default_value,omitempty"`
// Short description of the property.
Expand Down
69 changes: 40 additions & 29 deletions github/orgs_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestOrganizationsService_GetAllCustomProperties(t *testing.T) {
"property_name": "name",
"value_type": "single_select",
"required": true,
"require_explicit_values": true,
"default_value": "production",
"description": "Prod or dev environment",
"allowed_values":[
Expand Down Expand Up @@ -76,13 +77,14 @@ func TestOrganizationsService_GetAllCustomProperties(t *testing.T) {

want := []*CustomProperty{
{
PropertyName: new("name"),
ValueType: PropertyValueTypeSingleSelect,
Required: new(true),
DefaultValue: "production",
Description: new("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: new("org_actors"),
PropertyName: new("name"),
ValueType: PropertyValueTypeSingleSelect,
Required: new(true),
RequireExplicitValues: new(true),
DefaultValue: "production",
Description: new("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: new("org_actors"),
},
{
PropertyName: new("test"),
Expand Down Expand Up @@ -135,9 +137,10 @@ func TestOrganizationsService_CreateOrUpdateCustomProperties(t *testing.T) {
}{
Properties: []*CustomProperty{
{
PropertyName: new("name"),
ValueType: PropertyValueTypeSingleSelect,
Required: new(true),
PropertyName: new("name"),
ValueType: PropertyValueTypeSingleSelect,
Required: new(true),
RequireExplicitValues: new(false),
},
{
PropertyName: new("service"),
Expand All @@ -153,7 +156,8 @@ func TestOrganizationsService_CreateOrUpdateCustomProperties(t *testing.T) {
{
"property_name": "name",
"value_type": "single_select",
"required": true
"required": true,
"require_explicit_values": false
},
{
"property_name": "service",
Expand All @@ -170,9 +174,10 @@ func TestOrganizationsService_CreateOrUpdateCustomProperties(t *testing.T) {

want := []*CustomProperty{
{
PropertyName: new("name"),
ValueType: PropertyValueTypeSingleSelect,
Required: new(true),
PropertyName: new("name"),
ValueType: PropertyValueTypeSingleSelect,
Required: new(true),
RequireExplicitValues: new(false),
},
{
PropertyName: new("service"),
Expand Down Expand Up @@ -249,12 +254,24 @@ func TestOrganizationsService_CreateOrUpdateCustomProperty(t *testing.T) {
t.Parallel()
client, mux, _ := setup(t)

input := &CustomProperty{
ValueType: PropertyValueTypeSingleSelect,
Required: new(true),
RequireExplicitValues: new(false),
DefaultValue: "production",
Description: new("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: new("org_actors"),
}

mux.HandleFunc("/orgs/o/properties/schema/name", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testJSONBody(t, r, input)
fmt.Fprint(w, `{
"property_name": "name",
"value_type": "single_select",
"required": true,
"require_explicit_values": false,
"default_value": "production",
"description": "Prod or dev environment",
"allowed_values":[
Expand All @@ -266,26 +283,20 @@ func TestOrganizationsService_CreateOrUpdateCustomProperty(t *testing.T) {
})

ctx := t.Context()
property, _, err := client.Organizations.CreateOrUpdateCustomProperty(ctx, "o", "name", &CustomProperty{
ValueType: PropertyValueTypeSingleSelect,
Required: new(true),
DefaultValue: "production",
Description: new("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: new("org_actors"),
})
property, _, err := client.Organizations.CreateOrUpdateCustomProperty(ctx, "o", "name", input)
if err != nil {
t.Errorf("Organizations.CreateOrUpdateCustomProperty returned error: %v", err)
}

want := &CustomProperty{
PropertyName: new("name"),
ValueType: PropertyValueTypeSingleSelect,
Required: new(true),
DefaultValue: "production",
Description: new("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: new("org_actors"),
PropertyName: new("name"),
ValueType: PropertyValueTypeSingleSelect,
Required: new(true),
RequireExplicitValues: new(false),
DefaultValue: "production",
Description: new("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: new("org_actors"),
}
if !cmp.Equal(property, want) {
t.Errorf("Organizations.CreateOrUpdateCustomProperty returned %+v, want %+v", property, want)
Expand Down
Loading