-
Notifications
You must be signed in to change notification settings - Fork 961
[MAINT] Fixup github_repository_file
#3175
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
stevehipwell
merged 19 commits into
integrations:main
from
F-Secure-web:update-repository_file-import-docs
Feb 11, 2026
Merged
Changes from 12 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c634707
Improve docs of importing `github_repository_file`
deiga 3965ecb
Add missing test for import
deiga aef6dcf
Ensure we only set `branch` on import if it's not the default branch
deiga 6b2938f
Update `branch` to `Computed` field
deiga 76e4f34
Add state migration for missing branch field
deiga db068df
Add ID migration in the same bunch
deiga 3c2e590
Fix ID parsing
deiga e75070b
fixup! Fix ID parsing
deiga 581f684
fixup! fixup! Fix ID parsing
deiga 9b9f8b8
fixup! fixup! fixup! Add computed `repository_id` field to resource
deiga 46162f6
fixup! fixup! fixup! fixup! Add migration of the `repository_id` field.
deiga 08a8c4c
Comment out test in evaluation
deiga b07ed84
fixup! Address review comments
deiga 5e43cb5
fixup! Address review comments
deiga 0d8ebfe
fixup! Remove usage of autocreate_branch in `Read`, `Update` and `Del…
deiga d2f19df
Mark `autocreate_branch` as deprecated
deiga aa0a114
fixup! Address review comments
deiga 1fe800a
fixup! Change to use `UpdateFile` in `Update`
deiga e2cb7f4
fixup! Update docs with missing fields
deiga 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| package github | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/hashicorp/terraform-plugin-log/tflog" | ||
| "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
| ) | ||
|
|
||
| func resourceGithubRepositoryFileV0() *schema.Resource { | ||
| return &schema.Resource{ | ||
| Schema: map[string]*schema.Schema{ | ||
| "repository": { | ||
| Type: schema.TypeString, | ||
| Required: true, | ||
| ForceNew: true, | ||
| }, | ||
| "file": { | ||
| Type: schema.TypeString, | ||
| Required: true, | ||
| ForceNew: true, | ||
| }, | ||
| "content": { | ||
| Type: schema.TypeString, | ||
| Required: true, | ||
| }, | ||
| "branch": { | ||
| Type: schema.TypeString, | ||
| Optional: true, | ||
| ForceNew: true, | ||
| }, | ||
| "ref": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| ForceNew: true, | ||
| }, | ||
| "commit_sha": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| }, | ||
| "commit_message": { | ||
| Type: schema.TypeString, | ||
| Optional: true, | ||
| Computed: true, | ||
| }, | ||
| "commit_author": { | ||
| Type: schema.TypeString, | ||
| Optional: true, | ||
| RequiredWith: []string{"commit_email"}, | ||
| }, | ||
| "commit_email": { | ||
| Type: schema.TypeString, | ||
| Optional: true, | ||
| RequiredWith: []string{"commit_author"}, | ||
| }, | ||
| "sha": { | ||
| Type: schema.TypeString, | ||
| Computed: true, | ||
| }, | ||
| "overwrite_on_create": { | ||
| Type: schema.TypeBool, | ||
| Optional: true, | ||
| Default: false, | ||
| }, | ||
| "autocreate_branch": { | ||
| Type: schema.TypeBool, | ||
| Optional: true, | ||
| Default: false, | ||
| }, | ||
| "autocreate_branch_source_branch": { | ||
| Type: schema.TypeString, | ||
| Default: "main", | ||
| Optional: true, | ||
| RequiredWith: []string{"autocreate_branch"}, | ||
| }, | ||
| "autocreate_branch_source_sha": { | ||
| Type: schema.TypeString, | ||
| Optional: true, | ||
| Computed: true, | ||
| RequiredWith: []string{"autocreate_branch"}, | ||
| }, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func resourceGithubRepositoryFileStateUpgradeV0(ctx context.Context, rawState map[string]any, m any) (map[string]any, error) { | ||
| tflog.Debug(ctx, "GitHub Repository File State before migration", map[string]any{ | ||
| "rawState": rawState, | ||
| }) | ||
|
|
||
| meta := m.(*Owner) | ||
| client := meta.v3client | ||
| owner := meta.name | ||
|
|
||
| repoName, ok := rawState["repository"].(string) | ||
| if !ok { | ||
| return nil, fmt.Errorf("repository not found or is not a string") | ||
| } | ||
|
|
||
| repo, _, err := client.Repositories.Get(ctx, owner, repoName) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to retrieve repository '%s': %w", repoName, err) | ||
| } | ||
|
|
||
| rawState["repository_id"] = int(repo.GetID()) | ||
|
|
||
| // 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() | ||
| } | ||
|
|
||
| newResourceID, err := buildID(rawState["repository"].(string), rawState["file"].(string), rawState["branch"].(string)) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to build ID: %w", err) | ||
| } | ||
| rawState["id"] = newResourceID | ||
|
|
||
| tflog.Debug(ctx, "GitHub Repository File State after migration", map[string]any{ | ||
| "rawState": rawState, | ||
| }) | ||
| return rawState, nil | ||
| } |
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.