-
Notifications
You must be signed in to change notification settings - Fork 987
fix: Refactor repository custom property #3476
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
Open
stevehipwell
wants to merge
7
commits into
integrations:main
Choose a base branch
from
stevehipwell:refactor-repo-custom-prop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
070b861
fix: Refactor repository custom property
stevehipwell 53fe44a
fixup! fix: Refactor repository custom property
stevehipwell e1fe18e
fixup! fix: Refactor repository custom property
stevehipwell 8ceea22
fixup! fix: Refactor repository custom property
stevehipwell f467768
fixup! fix: Refactor repository custom property
stevehipwell 60f0086
fixup! fix: Refactor repository custom property
stevehipwell e0b46ed
Merge branch 'main' into refactor-repo-custom-prop
stevehipwell 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
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
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
4 changes: 4 additions & 0 deletions
4
examples/resources/github_repository_custom_property/import-by-string-id.tf
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,4 @@ | ||
| import { | ||
| to = github_repository_custom_property.example | ||
| id = "organization-name:repo-name:custom-property-name" | ||
| } | ||
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 @@ | ||
| terraform import github_repository_custom_property.example organization-name:repo-name:custom-property-name | ||
|
stevehipwell marked this conversation as resolved.
|
||
13 changes: 13 additions & 0 deletions
13
examples/resources/github_repository_custom_property/resource_1.tf
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,13 @@ | ||
| # NOTE: This assumes there already is a custom property defined on the org level called `my-cool-string` of type `string` | ||
|
|
||
| resource "github_repository" "example" { | ||
| name = "example" | ||
| description = "My awesome codebase" | ||
| } | ||
|
|
||
| resource "github_repository_custom_property" "example" { | ||
| repository = github_repository.example.name | ||
| property_name = "my-cool-string" | ||
| property_type = "string" | ||
| property_value = ["test"] | ||
| } |
10 changes: 0 additions & 10 deletions
10
examples/resources/repository_custom_property/example_1.tf
This file was deleted.
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,106 @@ | ||
| package github | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/google/go-github/v88/github" | ||
| "github.com/hashicorp/terraform-plugin-testing/helper/acctest" | ||
| ) | ||
|
|
||
| const testRandomIDLength = 5 | ||
|
|
||
| func mustGetTestMockResponse(t *testing.T, uri string, statusCode int, body any) *mockResponse { | ||
| resp := &mockResponse{ | ||
| ExpectedUri: uri, | ||
| StatusCode: statusCode, | ||
| } | ||
|
|
||
| if body != nil { | ||
| bodyBytes, err := json.Marshal(body) | ||
| if err != nil { | ||
| t.Fatalf("failed to marshal mock response body: %v", err) | ||
| } | ||
| resp.ResponseBody = string(bodyBytes) | ||
| } | ||
|
|
||
| return resp | ||
| } | ||
|
|
||
| func mustCreateTestGitHubClient(t *testing.T, baseURL string, opts ...github.ClientOptionsFunc) *github.Client { | ||
| client, err := github.NewClient(append([]github.ClientOptionsFunc{github.WithURLs(&baseURL, nil)}, opts...)...) | ||
| if err != nil { | ||
| t.Fatalf("failed to create GitHub client: %s", err) | ||
| } | ||
| return client | ||
| } | ||
|
|
||
| func mustCreateTestOrganizationRepositoryCustomProperty(t *testing.T, valType string, allowed []string) *github.CustomProperty { | ||
| t.Helper() | ||
|
|
||
| meta, err := getTestMeta() | ||
| if err != nil { | ||
| t.Fatalf("failed to get test meta: %v", err) | ||
| } | ||
|
|
||
| randomID := acctest.RandString(testRandomIDLength) | ||
| name := fmt.Sprintf("%s%s", testResourcePrefix, randomID) | ||
|
|
||
| req := &github.CustomProperty{ | ||
| PropertyName: &name, | ||
| ValueType: github.PropertyValueType(valType), | ||
| AllowedValues: allowed, | ||
| } | ||
|
|
||
| prop, _, err := meta.v3client.Organizations.CreateOrUpdateCustomProperty(t.Context(), meta.name, name, req) | ||
| if err != nil { | ||
| t.Fatalf("failed to create test organization repository custom property: %v", err) | ||
| } | ||
|
|
||
| t.Cleanup(func() { | ||
| if _, err := meta.v3client.Organizations.RemoveCustomProperty(context.Background(), meta.name, name); err != nil { | ||
| if err, ok := errors.AsType[*github.ErrorResponse](err); ok && err.Response.StatusCode == 404 { | ||
| return | ||
| } | ||
| t.Logf("failed to delete test organization repository custom property %s: %v", name, err) | ||
| } | ||
| }) | ||
|
|
||
| return prop | ||
| } | ||
|
|
||
| func mustCreateTestRepository(t *testing.T) *github.Repository { | ||
| t.Helper() | ||
|
|
||
| meta, err := getTestMeta() | ||
| if err != nil { | ||
| t.Fatalf("failed to get test meta: %v", err) | ||
| } | ||
|
|
||
| randomID := acctest.RandString(testRandomIDLength) | ||
| name := fmt.Sprintf("%s%s", testResourcePrefix, randomID) | ||
|
|
||
| req := &github.Repository{ | ||
| Name: &name, | ||
| AutoInit: new(true), | ||
| } | ||
|
|
||
| repo, _, err := meta.v3client.Repositories.Create(t.Context(), meta.name, req) | ||
| if err != nil { | ||
| t.Fatalf("failed to create test repository: %v", err) | ||
| } | ||
|
|
||
| t.Cleanup(func() { | ||
| if _, err := meta.v3client.Repositories.Delete(context.Background(), meta.name, name); err != nil { | ||
| if err, ok := errors.AsType[*github.ErrorResponse](err); ok && err.Response.StatusCode == 404 { | ||
| return | ||
| } | ||
| t.Logf("failed to delete test repository %s: %v", name, err) | ||
| } | ||
| }) | ||
|
|
||
| return repo | ||
| } |
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
This file was deleted.
Oops, something went wrong.
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.