Skip to content

Commit

Permalink
feat: Add missing values_editable_by field for organization custom pr…
Browse files Browse the repository at this point in the history
…operties (#3164)
  • Loading branch information
lrstanley committed May 11, 2024
1 parent 87c3716 commit 51bedeb
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 32 deletions.
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.

10 changes: 10 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.

17 changes: 12 additions & 5 deletions github/orgs_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ type CustomProperty struct {
// PropertyName is required for most endpoints except when calling CreateOrUpdateCustomProperty;
// where this is sent in the path and thus can be omitted.
PropertyName *string `json:"property_name,omitempty"`
// Possible values for ValueType are: string, single_select
ValueType string `json:"value_type"`
Required *bool `json:"required,omitempty"`
DefaultValue *string `json:"default_value,omitempty"`
Description *string `json:"description,omitempty"`
// The type of the value for the property. Can be one of: string, single_select.
ValueType string `json:"value_type"`
// Whether the property is required.
Required *bool `json:"required,omitempty"`
// Default value of the property.
DefaultValue *string `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
// allowed values.
AllowedValues []string `json:"allowed_values,omitempty"`
// Who can edit the values of the property. Can be one of: org_actors, org_and_repo_actors, nil (null).
ValuesEditableBy *string `json:"values_editable_by,omitempty"`
}

// RepoCustomPropertyValue represents a repository custom property value.
Expand Down
61 changes: 34 additions & 27 deletions github/orgs_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func TestOrganizationsService_GetAllCustomProperties(t *testing.T) {
"allowed_values":[
"production",
"development"
]
],
"values_editable_by": "org_actors"
},
{
"property_name": "service",
Expand All @@ -52,12 +53,13 @@ func TestOrganizationsService_GetAllCustomProperties(t *testing.T) {

want := []*CustomProperty{
{
PropertyName: String("name"),
ValueType: "single_select",
Required: Bool(true),
DefaultValue: String("production"),
Description: String("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
PropertyName: String("name"),
ValueType: "single_select",
Required: Bool(true),
DefaultValue: String("production"),
Description: String("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: String("org_actors"),
},
{
PropertyName: String("service"),
Expand Down Expand Up @@ -162,7 +164,8 @@ func TestOrganizationsService_GetCustomProperty(t *testing.T) {
"allowed_values":[
"production",
"development"
]
],
"values_editable_by": "org_actors"
}`)
})

Expand All @@ -173,12 +176,13 @@ func TestOrganizationsService_GetCustomProperty(t *testing.T) {
}

want := &CustomProperty{
PropertyName: String("name"),
ValueType: "single_select",
Required: Bool(true),
DefaultValue: String("production"),
Description: String("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
PropertyName: String("name"),
ValueType: "single_select",
Required: Bool(true),
DefaultValue: String("production"),
Description: String("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: String("org_actors"),
}
if !cmp.Equal(property, want) {
t.Errorf("Organizations.GetCustomProperty returned %+v, want %+v", property, want)
Expand Down Expand Up @@ -210,29 +214,32 @@ func TestOrganizationsService_CreateOrUpdateCustomProperty(t *testing.T) {
"allowed_values":[
"production",
"development"
]
],
"values_editable_by": "org_actors"
}`)
})

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

want := &CustomProperty{
PropertyName: String("name"),
ValueType: "single_select",
Required: Bool(true),
DefaultValue: String("production"),
Description: String("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
PropertyName: String("name"),
ValueType: "single_select",
Required: Bool(true),
DefaultValue: String("production"),
Description: String("Prod or dev environment"),
AllowedValues: []string{"production", "development"},
ValuesEditableBy: String("org_actors"),
}
if !cmp.Equal(property, want) {
t.Errorf("Organizations.CreateOrUpdateCustomProperty returned %+v, want %+v", property, want)
Expand Down Expand Up @@ -280,7 +287,7 @@ func TestOrganizationsService_ListCustomPropertyValues(t *testing.T) {
fmt.Fprint(w, `[{
"repository_id": 1296269,
"repository_name": "Hello-World",
"repository_full_name": "octocat/Hello-World",
"repository_full_name": "octocat/Hello-World",
"properties": [
{
"property_name": "environment",
Expand Down

0 comments on commit 51bedeb

Please sign in to comment.