Skip to content

feat: support repository level custom_property resource and custom_properties datasource #2316

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 40 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a7e562c
add octokit sdk client
Jul 12, 2024
af0245a
stash half working solution
Jul 12, 2024
cdd112a
add repository custom properties data source
Jul 13, 2024
f9633fb
break out custom props parsing logic to its own function
Jul 13, 2024
5e0894d
use background ctx
Jul 14, 2024
2accb56
format provider.go
Jul 14, 2024
b3f44ca
fix error msg to include repoName instead of its pointer
Jul 15, 2024
98947a3
use type switch instead of if else
Jul 15, 2024
2125cab
fix linting errors
Jul 15, 2024
ec2755e
restructure datasource to take a property name and call it github_rep…
Jul 16, 2024
1e88e7a
formatting
Jul 16, 2024
31f9a2b
rename file to match datasource name
Jul 16, 2024
5ed47ba
Merge branch 'main' into repository-custom-properties
felixlut Jul 31, 2024
697c43c
remove go-sdk in favor of go-github
Oct 5, 2024
9933170
implement data_source_github_repository_custom_property with go-github
Oct 5, 2024
a7aefae
implement resource_github_repository_custom_property
Oct 5, 2024
ce87c42
update descriptions
Oct 5, 2024
6b76479
remove custom_property resource in favour of custom_propertIES one
Oct 9, 2024
d9ad9a9
add custom_property resource to provider.go
Oct 9, 2024
7982a1a
formatting
Oct 9, 2024
7366a88
add tests for repository_custom_property
Oct 9, 2024
fe5add1
update description of test
Oct 9, 2024
0dbd149
add tests for each custom_property type
Oct 9, 2024
d9f13fd
rollback repo changes
Oct 9, 2024
7615100
add tests for custom_property datasource
Oct 9, 2024
c72ce22
formatting
Oct 9, 2024
bc93a88
Merge branch 'main' into repository-custom-properties
felixlut Oct 9, 2024
d298e07
breakout parsing custom_property_value as a string slice to its own f…
Oct 9, 2024
8eff6f4
Merge branch 'main' into repository-custom-properties
felixlut Nov 21, 2024
3deb3ed
bump go-github to v66 for new files
felixlut Nov 21, 2024
31ac7db
add property_type as a required attribute
felixlut Nov 22, 2024
10bb6f0
flip datasource to use typeList instead of typeSet
felixlut Nov 22, 2024
1e3ba1d
refactor tests for data source to use property_type
felixlut Nov 22, 2024
5be94bd
Update data_source_github_repository_custom_properties.go
felixlut Nov 22, 2024
d9974e6
cleanup incorrect comments
felixlut Nov 22, 2024
add24a8
remove old comment
felixlut Nov 23, 2024
46c1846
add docs
felixlut Nov 24, 2024
15b61e7
fix typo
felixlut Nov 24, 2024
2b169f1
Merge branch 'main' into repository-custom-properties
felixlut Nov 26, 2024
1b6bfaa
Merge branch 'main' into repository-custom-properties
kfcampbell Jan 17, 2025
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
Prev Previous commit
Next Next commit
breakout parsing custom_property_value as a string slice to its own f…
…unction
  • Loading branch information
felixlut committed Oct 9, 2024
commit d298e07eb423d05128195c79acdbf16f135b3f32
23 changes: 16 additions & 7 deletions github/data_source_github_repository_custom_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,26 @@ func flattenRepositoryCustomProperties(customProperties []*github.CustomProperty

result["property_name"] = prop.PropertyName

switch value := prop.Value.(type) {
case string:
result["property_value"] = []string{value}
case []string:
result["property_value"] = value
default:
return nil, fmt.Errorf("custom property value couldn't be parsed as a string or a list of strings: %s", value)
propertyValue, err := parseRepositoryCustomPropertyValueToStringSlice(prop)
if err != nil {
return nil, err
}

result["property_value"] = propertyValue

results = append(results, result)
}

return results, nil
}

func parseRepositoryCustomPropertyValueToStringSlice(prop *github.CustomPropertyValue) ([]string, error) {
switch value := prop.Value.(type) {
case string:
return []string{value}, nil
case []string:
return value, nil
default:
return nil, fmt.Errorf("custom property value couldn't be parsed as a string or a list of strings: %s", value)
}
}
13 changes: 4 additions & 9 deletions github/resource_github_repository_custom_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,10 @@ func readRepositoryCustomPropertyValue(ctx context.Context, client *github.Clien
return nil, fmt.Errorf("could not find a custom property with name: %s", propertyName)
}

var wantedCustomPropertyValue []string
switch value := wantedCustomProperty.Value.(type) {
case string:
wantedCustomPropertyValue = []string{value}
case []string:
wantedCustomPropertyValue = value
default:
return nil, fmt.Errorf("custom property value couldn't be parsed as a string or a list of strings: %s", value)
wantedPropertyValue, err := parseRepositoryCustomPropertyValueToStringSlice(wantedCustomProperty)
if err != nil {
return nil, err
}

return wantedCustomPropertyValue, nil
return wantedPropertyValue, nil
}
Loading