Skip to content

[BUG]: fix github repository file id escaping#3415

Open
deiga wants to merge 7 commits into
integrations:mainfrom
F-Secure-web:fix-github_repository_file-id-escaping
Open

[BUG]: fix github repository file id escaping#3415
deiga wants to merge 7 commits into
integrations:mainfrom
F-Secure-web:fix-github_repository_file-id-escaping

Conversation

@deiga
Copy link
Copy Markdown
Collaborator

@deiga deiga commented May 10, 2026

Resolves #3335


Before the change?

After the change?

  • Terraform successfully operates on resources when filePath in github_repository_resource contains a colon

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

👋 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! 🚀

@github-actions github-actions Bot added the Type: Bug Something isn't working as documented label May 10, 2026
@deiga deiga marked this pull request as ready for review May 10, 2026 18:54
@deiga deiga changed the title fix github repository file id escaping [BUG]: fix github repository file id escaping May 10, 2026
@deiga deiga requested a review from stevehipwell May 10, 2026 18:55
@deiga deiga added the vNextPatch These issues and PRs should be included in the next patch release label May 10, 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.

Have we tested this doesn't break existing IDs? It looks OK, but worth checking. Also should we add this to the next minor release milestone as we can always cherry pick it into a patch if required?

@deiga deiga removed the vNextPatch These issues and PRs should be included in the next patch release label May 24, 2026
@deiga deiga force-pushed the fix-github_repository_file-id-escaping branch from 65ea3b4 to 2598ebe Compare May 24, 2026 12:34
@deiga deiga requested a review from stevehipwell May 24, 2026 12:35
@deiga
Copy link
Copy Markdown
Collaborator Author

deiga commented May 24, 2026

@stevehipwell Thanks for asking, I ran v6.11.0 locally and then tried to run this code: same failure, since it was already the v0 migration that was failing!

@deiga deiga added the vNextPatch These issues and PRs should be included in the next patch release label May 24, 2026
@deiga
Copy link
Copy Markdown
Collaborator Author

deiga commented May 24, 2026

I think we should release this as a patch, considering that the changes in v6.11.1 are blocking upgrading for anyone with colons in repository_file resources

@stevehipwell
Copy link
Copy Markdown
Collaborator

@deiga do you want to rebase this and then we can get it merged in. Once it's been merged we can decide if we want to cherry pick it onto a patch branch.

Comment thread examples/dev.tfrc Outdated
direct {
exclude = ["registry.terraform.io/hashicorp/github"]
}
} No newline at end of file
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.

Could we fix the EOF?

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.

Actually should this file even be in this PR?

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.

No, it's not directly related. It's a Scout Rule thing, since I used the example to verify the changes and noticed that the config file didn't work as we had it


rawState["repository_id"] = int(repo.GetID())

branch, ok := rawState["branch"].(string)
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.

Is there a reason this has been changed from a single line?

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.

forcetypeassert linter bit it :)

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'm not sure I follow why, the code is identical as there isn't a new check for the map lookup (which could be nested single lines anyway).

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.

In this commit I needed to touch that line, which caused it to be checked by make lintcheck-new

And since we didn't use forcetypeassert when that migration was originally created: it had a lot to complain about

deiga added 6 commits May 26, 2026 20:38
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
…capred ID parts

Signed-off-by: Timo Sand <timo.sand@f-secure.com>
- We want to ensure that users never accidentally get `hashicorp/github`
- `~/` failed to expand on macOS

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 fix-github_repository_file-id-escaping branch from 7cb06fa to 8f0bfe8 Compare May 26, 2026 17:42
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
@deiga deiga requested a review from stevehipwell May 26, 2026 17:43
Comment on lines +108 to +118
branch, ok := rawState["branch"].(string)
// If branch is missing or empty, fetch the default branch from the repository
if branch, ok := rawState["branch"].(string); !ok || branch == "" {
rawState["branch"] = repo.GetDefaultBranch()
if !ok || branch == "" {
branch = repo.GetDefaultBranch()
rawState["branch"] = branch
}

newResourceID, err := buildID(rawState["repository"].(string), rawState["file"].(string), rawState["branch"].(string))
filePath, ok := rawState["file"].(string)
if !ok {
return nil, fmt.Errorf("state upgrade v0: file path is not a string")
}
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.

Suggested change
branch, ok := rawState["branch"].(string)
// If branch is missing or empty, fetch the default branch from the repository
if branch, ok := rawState["branch"].(string); !ok || branch == "" {
rawState["branch"] = repo.GetDefaultBranch()
if !ok || branch == "" {
branch = repo.GetDefaultBranch()
rawState["branch"] = branch
}
newResourceID, err := buildID(rawState["repository"].(string), rawState["file"].(string), rawState["branch"].(string))
filePath, ok := rawState["file"].(string)
if !ok {
return nil, fmt.Errorf("state upgrade v0: file path is not a string")
}
branchSet := false
if v, ok := rawState["branch"]; ok {
if _, ok := v.(string); ok || s != "" {
branchSet = true
}
}
if !branchSet {
rawState["branch"] = repo.GetDefaultBranch()
}
pathSet := false
if v, ok := rawState["file"]; ok {
if _, ok := v.(string); ok {
pathSet = true
}
}
if !pathSet {
return nil, fmt.Errorf("state upgrade v0: file path is not a string")
}

This would be my prefered pattern here, otherwise we're still masking a conversion.

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

Labels

Type: Bug Something isn't working as documented vNextPatch These issues and PRs should be included in the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: github_repository_file rejects valid file paths containing ':' in v6.11.1

2 participants