Skip to content

fix: Refactor repository custom property#3476

Open
stevehipwell wants to merge 7 commits into
integrations:mainfrom
stevehipwell:refactor-repo-custom-prop
Open

fix: Refactor repository custom property#3476
stevehipwell wants to merge 7 commits into
integrations:mainfrom
stevehipwell:refactor-repo-custom-prop

Conversation

@stevehipwell

@stevehipwell stevehipwell commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Resolves #3358
Resolves #3377
Resolves #2639
Closes #3387
Closes #3378
Closes #2640


Before the change?

  • github_repository_custom_property had a number of bugs and was using the outdated pattern

After the change?

  • github_repository_custom_property has been updated to the latest pattern
    • Auto generated docs
    • Working import
    • Value can be changed without forcing a recreate
    • Empty values blocked by validation
    • Test updated to use cleaner pattern

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@stevehipwell stevehipwell added this to the v6.13.0 milestone Jun 4, 2026
@stevehipwell stevehipwell requested a review from deiga June 4, 2026 16:41
@stevehipwell stevehipwell self-assigned this Jun 4, 2026
@stevehipwell stevehipwell added the Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR label Jun 4, 2026
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

👋 Hi, and thank you for this contribution!

This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can.

You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions.


🤖 This is an automated message.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

These provider review instructions are being used. This PR refactors github_repository_custom_property to match newer provider patterns (context-aware CRUD, schema/state migration, tfplugindocs-generated docs/examples) while addressing prior bugs around import and in-place value updates.

Changes:

  • Refactors github_repository_custom_property to SDKv2 *Context CRUD, adds UpdateContext, diffRepository, and a v0→v1 state upgrader for repository_id.
  • Updates generated docs/templates and adds example + import snippets for the resource.
  • Expands acceptance coverage for additional value types/import and adds input validation for empty strings.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
templates/resources/repository_custom_property.md.tmpl Switches resource doc template to tfplugindocs-driven schema/examples/import sections.
github/resource_github_repository_custom_property.go Refactors resource to new CRUD/import/migration patterns; adds update support and validation.
github/resource_github_repository_custom_property_test.go Updates/extends acceptance tests (new URL test, import test, validation test).
github/resource_github_repository_custom_property_migration.go Adds v0 schema + state upgrader to populate repository_id.
github/resource_github_repository_custom_property_migration_test.go Adds a placeholder (currently commented) migration test scaffold.
examples/resources/github_repository_custom_property/resource_1.tf Updates example snippet used by docs.
examples/resources/github_repository_custom_property/import.sh Adds terraform import example for docs.
examples/resources/github_repository_custom_property/import-by-string-id.tf Adds import { id = ... } example for docs.
docs/resources/repository_custom_property.md Updates generated resource docs to new template/schema/import format.
ARCHITECTURE.md Updates architecture guidance snippet to reflect the newer resource structure patterns.
Comments suppressed due to low confidence (1)

examples/resources/github_repository_custom_property/resource_1.tf:8

  • The example names the resource github_repository_custom_property.string, but the generated import examples use github_repository_custom_property.example. Keeping these consistent avoids confusion when users copy/paste the example + import snippet from the docs.

Comment thread github/resource_github_repository_custom_property.go
Comment thread github/resource_github_repository_custom_property.go
Comment thread github/resource_github_repository_custom_property_test.go Outdated
Comment thread github/resource_github_repository_custom_property_test.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Comment thread examples/resources/github_repository_custom_property/import.sh
Comment thread github/resource_github_repository_custom_property_migration.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Comment thread github/resource_github_repository_custom_property.go
Comment thread github/resource_github_repository_custom_property.go
Comment thread github/resource_github_repository_custom_property_test.go Outdated
Comment thread github/resource_github_repository_custom_property_migration.go Outdated
Comment thread github/resource_github_repository_custom_property.go
Comment thread github/resource_github_repository_custom_property.go Outdated
Comment thread github/resource_github_repository_custom_property.go
@stevehipwell

Copy link
Copy Markdown
Collaborator Author

@deiga I've fixed your review comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Comment thread github/resource_github_repository_custom_property_migration.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Comment thread github/resource_github_repository_custom_property_migration.go Outdated

@robert-crandall robert-crandall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice refactor!

Comment on lines +63 to +66
repo, _, err := client.Repositories.Get(ctx, owner, repoName)
if err != nil {
return nil, fmt.Errorf("failed to retrieve repository %s: %w", repoName, err)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would this handle a 404 if the repository is deleted? Would this require manually removing the repo from terraform state?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's how it currently works in the provider. I don't really have the time to look into changing this now, but it might be that we could relax this if we can clear the ID in the migration; but this would require actual testing so a lot of effort.

Comment thread github/resource_github_repository_custom_property_migration_test.go Outdated
@stevehipwell stevehipwell force-pushed the refactor-repo-custom-prop branch from 0a0c1d8 to 60f0086 Compare June 5, 2026 17:08
robert-crandall
robert-crandall previously approved these changes Jun 5, 2026
@stevehipwell

Copy link
Copy Markdown
Collaborator Author

@deiga this one is just waiting on you.

@deiga deiga left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment thread github/resource_github_repository_custom_property_migration_test.go
Comment thread github/resource_github_repository_custom_property_test.go
Comment thread github/resource_github_repository_custom_property_test.go
PlanOnly: true,
},
{
Config: fmt.Sprintf(config, fmt.Sprintf(`["%s"]`, allowed[0])),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: this is getting hard to parse 😬

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's easier to parse what's going on now that it was before, and there is no way to remove required complexity.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Fetch the first element of this array and build a string representation of an array with that element then insert that into a string representation of the TF config" IMO requires a few mental hops too many.

You don't need to change this, just highlighting that others than you might have it harder with this.

I would extract the nested fmt call into a constant just to make it easier to read.
But I know that gophers have different opinions about what is easy to read 😂

@stevehipwell stevehipwell force-pushed the refactor-repo-custom-prop branch from e0b46ed to f02503b Compare June 11, 2026 12:53
@stevehipwell

Copy link
Copy Markdown
Collaborator Author

@deiga have you seen my responses?


tflog.Debug(ctx, "Migrating GitHub Repository Custom Property from v0 to v1.", map[string]any{"raw_state": rawState})

state, err := migrateRepositoryWithID(ctx, client, owner, rawState)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this pattern!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Maintenance Any dependency, housekeeping, and clean up Issue or PR

Projects

None yet

4 participants