-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Implement Custom Properties #2986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
65e9873
Create CustomProperty struct
liaodaniel ecc77c2
Add CreateOrUpdateCustomProperty function
liaodaniel 93faa5b
Add GetCustomProperty function
liaodaniel 2f48a7d
Add RemoveCustomProperty function
liaodaniel 9bda84c
Add GetAllCustomProperties function
liaodaniel d6c57a4
Add CreateOrUpdateCustomProperties function
liaodaniel d24c1e3
Add CreateOrUpdateCustomPropertyValuesForRepos function
liaodaniel dc2238b
Add ListCustomPropertyValues function
liaodaniel 05782e5
Match the ordering with the API docs
liaodaniel 0b1aa7b
Add openapi metadata
liaodaniel 2967adc
Address the PR comments
liaodaniel 756900a
Comment on PropertyName as pointer with omitempty
liaodaniel 74b47ef
Merge branch 'master' into support_repo_custom_props
liaodaniel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
// Copyright 2023 The go-github AUTHORS. All rights reserved. | ||
// | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package github | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
// CustomProperty represents an organization custom property object. | ||
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"` | ||
AllowedValues []string `json:"allowed_values,omitempty"` | ||
} | ||
|
||
// RepoCustomPropertyValue represents a repository custom property value. | ||
type RepoCustomPropertyValue struct { | ||
RepositoryID int64 `json:"repository_id"` | ||
RepositoryName string `json:"repository_name"` | ||
RepositoryFullName string `json:"repository_full_name"` | ||
Properties []*CustomPropertyValue `json:"properties"` | ||
} | ||
|
||
// CustomPropertyValue represents a custom property value. | ||
type CustomPropertyValue struct { | ||
PropertyName string `json:"property_name"` | ||
Value *string `json:"value,omitempty"` | ||
} | ||
|
||
// GetAllCustomProperties gets all custom properties that are defined for the specified organization. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/orgs/properties#get-all-custom-properties-for-an-organization | ||
// | ||
//meta:operation GET /orgs/{org}/properties/schema | ||
func (s *OrganizationsService) GetAllCustomProperties(ctx context.Context, org string) ([]*CustomProperty, *Response, error) { | ||
u := fmt.Sprintf("orgs/%v/properties/schema", org) | ||
|
||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
var customProperties []*CustomProperty | ||
resp, err := s.client.Do(ctx, req, &customProperties) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return customProperties, resp, nil | ||
} | ||
|
||
// CreateOrUpdateCustomProperties creates new or updates existing custom properties that are defined for the specified organization. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/orgs/properties#create-or-update-custom-properties-for-an-organization | ||
// | ||
//meta:operation PATCH /orgs/{org}/properties/schema | ||
func (s *OrganizationsService) CreateOrUpdateCustomProperties(ctx context.Context, org string, properties []*CustomProperty) ([]*CustomProperty, *Response, error) { | ||
u := fmt.Sprintf("orgs/%v/properties/schema", org) | ||
|
||
params := struct { | ||
Properties []*CustomProperty `json:"properties"` | ||
}{ | ||
Properties: properties, | ||
} | ||
|
||
req, err := s.client.NewRequest("PATCH", u, params) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
var customProperties []*CustomProperty | ||
resp, err := s.client.Do(ctx, req, &customProperties) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return customProperties, resp, nil | ||
} | ||
|
||
// GetCustomProperty gets a custom property that is defined for the specified organization. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/orgs/properties#get-a-custom-property-for-an-organization | ||
// | ||
//meta:operation GET /orgs/{org}/properties/schema/{custom_property_name} | ||
func (s *OrganizationsService) GetCustomProperty(ctx context.Context, org, name string) (*CustomProperty, *Response, error) { | ||
u := fmt.Sprintf("orgs/%v/properties/schema/%v", org, name) | ||
|
||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
var customProperty *CustomProperty | ||
resp, err := s.client.Do(ctx, req, &customProperty) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return customProperty, resp, nil | ||
} | ||
|
||
// CreateOrUpdateCustomProperty creates a new or updates an existing custom property that is defined for the specified organization. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/orgs/properties#create-or-update-a-custom-property-for-an-organization | ||
// | ||
//meta:operation PUT /orgs/{org}/properties/schema/{custom_property_name} | ||
func (s *OrganizationsService) CreateOrUpdateCustomProperty(ctx context.Context, org, customPropertyName string, property *CustomProperty) (*CustomProperty, *Response, error) { | ||
u := fmt.Sprintf("orgs/%v/properties/schema/%v", org, customPropertyName) | ||
|
||
req, err := s.client.NewRequest("PUT", u, property) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
var customProperty *CustomProperty | ||
resp, err := s.client.Do(ctx, req, &customProperty) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return customProperty, resp, nil | ||
} | ||
|
||
// RemoveCustomProperty removes a custom property that is defined for the specified organization. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/orgs/properties#remove-a-custom-property-for-an-organization | ||
// | ||
//meta:operation DELETE /orgs/{org}/properties/schema/{custom_property_name} | ||
func (s *OrganizationsService) RemoveCustomProperty(ctx context.Context, org, customPropertyName string) (*Response, error) { | ||
u := fmt.Sprintf("orgs/%v/properties/schema/%v", org, customPropertyName) | ||
|
||
req, err := s.client.NewRequest("DELETE", u, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return s.client.Do(ctx, req, nil) | ||
} | ||
|
||
// ListCustomPropertyValues lists all custom property values for repositories in the specified organization. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/orgs/properties#list-custom-property-values-for-organization-repositories | ||
// | ||
//meta:operation GET /orgs/{org}/properties/values | ||
func (s *OrganizationsService) ListCustomPropertyValues(ctx context.Context, org string, opts *ListOptions) ([]*RepoCustomPropertyValue, *Response, error) { | ||
u := fmt.Sprintf("orgs/%v/properties/values", org) | ||
u, err := addOptions(u, opts) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req, err := s.client.NewRequest("GET", u, nil) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
var repoCustomPropertyValues []*RepoCustomPropertyValue | ||
resp, err := s.client.Do(ctx, req, &repoCustomPropertyValues) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return repoCustomPropertyValues, resp, nil | ||
} | ||
|
||
// CreateOrUpdateRepoCustomPropertyValues creates new or updates existing custom property values across multiple repositories for the specified organization. | ||
// | ||
// GitHub API docs: https://docs.github.com/rest/orgs/properties#create-or-update-custom-property-values-for-organization-repositories | ||
// | ||
//meta:operation PATCH /orgs/{org}/properties/values | ||
func (s *OrganizationsService) CreateOrUpdateRepoCustomPropertyValues(ctx context.Context, org string, repoNames []string, properties []*CustomProperty) (*Response, error) { | ||
u := fmt.Sprintf("orgs/%v/properties/values", org) | ||
|
||
params := struct { | ||
RepositoryNames []string `json:"repository_names"` | ||
Properties []*CustomProperty `json:"properties"` | ||
}{ | ||
RepositoryNames: repoNames, | ||
Properties: properties, | ||
} | ||
|
||
req, err := s.client.NewRequest("PATCH", u, params) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return s.client.Do(ctx, req, nil) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.