Skip to content

[MAINT] Fixup github_repository_file#3175

Merged
stevehipwell merged 19 commits intointegrations:mainfrom
F-Secure-web:update-repository_file-import-docs
Feb 11, 2026
Merged

[MAINT] Fixup github_repository_file#3175
stevehipwell merged 19 commits intointegrations:mainfrom
F-Secure-web:update-repository_file-import-docs

Conversation

@deiga
Copy link
Copy Markdown
Collaborator

@deiga deiga commented Feb 9, 2026

Resolves #3161


Before the change?

  • There was no test for importing github_repository_file
  • Import format: repo/file or repo/file:branch; default branch was imported without an explicit branch segment.
  • Branch field: branch was optional and not Computed; state could omit it for default-branch resources.
  • State: No migration for old ID formats; repository_id was not part of the resource’s state.
  • autocreate_branch: Used in Read, Update, and Delete; no deprecation notice.

After the change?

  • We have tests for importing github_repository_file
  • Adds Computed: true to branch
  • Adds computed repository_id field and enables repo renaming without resource recreation
  • Computes branch on create or import if not specified
  • Changes ID schema from <repo>/<file> to <repo>:<file>:<branch> to enable safer usage of multiple files from same repo but different branches
  • Adds State migration for computing branch, repository_id and new ID format
  • Import format: repo:file:branch (colon-separated); default branch uses repo:file: (trailing colon). Matches the internal ID format.
  • autocreate_branch: Deprecated and no longer used in Read, Update, or Delete.

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

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 9, 2026

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@deiga deiga requested review from nickfloyd and stevehipwell and removed request for nickfloyd February 9, 2026 17:16
@deiga deiga marked this pull request as ready for review February 9, 2026 17:16
@deiga
Copy link
Copy Markdown
Collaborator Author

deiga commented Feb 9, 2026

image

deiga added 3 commits February 9, 2026 19:18
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
@deiga deiga force-pushed the update-repository_file-import-docs branch from 1337fdb to aef6dcf Compare February 9, 2026 17:18
nickfloyd
nickfloyd previously approved these changes Feb 9, 2026
Copy link
Copy Markdown
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

I missed the fact that the branch is optional, I think this should be required in the next major version. As it's optional then the import ID should allow it to be not set.

@nickfloyd nickfloyd self-requested a review February 9, 2026 17:22
@stevehipwell
Copy link
Copy Markdown
Collaborator

So what I'm saying is the following changes are needed to fix this resource.

  • Add Computed: true to branch
  • Compute branch on create if not specified
  • Support importing with ID missing branch (compute on import only if missing)
  • Add migration to fix defect with ID not containing branch and missing branch computed value

deiga added 3 commits February 9, 2026 20:46
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Copy link
Copy Markdown
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

We can simplify the logic by always requiring a 2 part ID, with the second part blank for the default ID; e.g. my-repo/my-file.txt:.

Longer term the ID should be in the form <repo>:<file>:<branch>, but that's a problem for another day.

Always use 2 part ID for import. Use buildID for resource ID
@deiga deiga requested a review from stevehipwell February 10, 2026 09:32
@deiga
Copy link
Copy Markdown
Collaborator Author

deiga commented Feb 10, 2026

@stevehipwell Done. But I wonder if I should just refactor the import ID now as well? Sure, it's technically a breaking change, but imports are "one-off" usually

@stevehipwell
Copy link
Copy Markdown
Collaborator

@stevehipwell Done. But I wonder if I should just refactor the import ID now as well? Sure, it's technically a breaking change, but imports are "one-off" usually

@deiga I think this makes sense. @nickfloyd thoughts?

We should also add repository_id to the schema as part of the migration, add the diffRepository, and remove ForceNew from repository; this will stop files being destroyed if the repo name changes.

Use 3 part ID for import as well
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
This required changing all tests to need a mock of the GH API

Signed-off-by: Timo Sand <timo.sand@f-secure.com>
@deiga
Copy link
Copy Markdown
Collaborator Author

deiga commented Feb 10, 2026

@stevehipwell Addressed your comments. And re-introduced the API Mock pattern here, since it's the only way to verify the migration.

Would you still prefer that we discuss before we can add this pattern?

@stevehipwell
Copy link
Copy Markdown
Collaborator

Would you still prefer that we discuss before we can add this pattern?

Yes, I don't think this is the time to add this; but I think it's something we need to explore further.

@deiga
Copy link
Copy Markdown
Collaborator Author

deiga commented Feb 10, 2026

@stevehipwell Done

Copy link
Copy Markdown
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

I've added inline comments, but you'll also need to add an ID set to update as the ID needs to be updated if the repo name has changed.

@deiga
Copy link
Copy Markdown
Collaborator Author

deiga commented Feb 10, 2026

@stevehipwell

you'll also need to add an ID set to update as the ID needs to be updated if the repo name has changed.

Doesn't ForceNew run Create, so that shouldn't be needed in Update?

@stevehipwell
Copy link
Copy Markdown
Collaborator

Doesn't ForceNew run Create, so that shouldn't be needed in Update?

The diff function supports changing the repo name without forcing new, so we have to set the ID in update.

@deiga
Copy link
Copy Markdown
Collaborator Author

deiga commented Feb 10, 2026

@stevehipwell If the repository_id changes, then we set ForceNew on repository. Which triggers Create instead if Update, or do I have that mixed up?
Is there any case where repository_id would change and need to be set in Update?

Signed-off-by: Timo Sand <timo.sand@f-secure.com>
@deiga deiga requested a review from stevehipwell February 10, 2026 21:38
@stevehipwell
Copy link
Copy Markdown
Collaborator

@stevehipwell If the repository_id changes, then we set ForceNew on repository. Which triggers Create instead if Update, or do I have that mixed up?
Is there any case where repository_id would change and need to be set in Update?

The resource ID uses repo name so we need to call d.SetId(), not update the repository_id as that is static.

@deiga
Copy link
Copy Markdown
Collaborator Author

deiga commented Feb 11, 2026

@stevehipwell Doh! 🤦
Sorry, I kept misunderstanding your point

Signed-off-by: Timo Sand <timo.sand@f-secure.com>
…ete`

Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
@deiga deiga requested a review from stevehipwell February 11, 2026 04:00
@deiga
Copy link
Copy Markdown
Collaborator Author

deiga commented Feb 11, 2026

@stevehipwell I went and deprecated the whole autocreate_branch stuff, let me know if I went too far :D

And, could you update the title of this PR to something like "resource_github_repository_file: fix import format and add state migrations"

Copy link
Copy Markdown
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

This is looking good @deiga, just a couple of things to look at.

Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
@deiga deiga requested a review from stevehipwell February 11, 2026 14:24
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
@stevehipwell stevehipwell changed the title [MAINT] Improve docs of github_repository_file [MAINT] Fixup github_repository_file Feb 11, 2026
@stevehipwell stevehipwell added this to the v6.11.1 Patch milestone Feb 11, 2026
@deiga deiga requested a review from stevehipwell February 11, 2026 18:15
Copy link
Copy Markdown
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

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

LGTM

@stevehipwell stevehipwell merged commit 256cdd8 into integrations:main Feb 11, 2026
7 checks passed
@deiga deiga deleted the update-repository_file-import-docs branch February 11, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Unable to import a github_repository_file from default branch with provider 6.11.0

3 participants