@@ -66,6 +66,32 @@ type GitHubRepositoryResourceModel struct {
6666 NodeID types.String `tfsdk:"node_id"`
6767}
6868
69+ // UpdateFromAPI populates the model with data from the GitHub API repository object.
70+ func (m * GitHubRepositoryResourceModel ) UpdateFromAPI (repo * github.Repository ) {
71+ // Arguments
72+ m .Name = types .StringValue (repo .GetName ())
73+ m .Description = types .StringValue (repo .GetDescription ())
74+ m .Homepage = types .StringValue (repo .GetHomepage ())
75+ m .Private = types .BoolValue (repo .GetPrivate ())
76+ m .HasIssues = types .BoolValue (repo .GetHasIssues ())
77+ m .HasProjects = types .BoolValue (repo .GetHasProjects ())
78+ m .HasWiki = types .BoolValue (repo .GetHasWiki ())
79+ m .HasDiscussions = types .BoolValue (repo .GetHasDiscussions ())
80+ m .AllowSquashMerge = types .BoolValue (repo .GetAllowSquashMerge ())
81+ m .AllowMergeCommit = types .BoolValue (repo .GetAllowMergeCommit ())
82+ m .AllowRebaseMerge = types .BoolValue (repo .GetAllowRebaseMerge ())
83+ m .AllowAutoMerge = types .BoolValue (repo .GetAllowAutoMerge ())
84+ m .DeleteBranchOnMerge = types .BoolValue (repo .GetDeleteBranchOnMerge ())
85+ m .SquashMergeCommitTitle = types .StringValue (repo .GetSquashMergeCommitTitle ())
86+ m .SquashMergeCommitMessage = types .StringValue (repo .GetSquashMergeCommitMessage ())
87+ m .MergeCommitTitle = types .StringValue (repo .GetMergeCommitTitle ())
88+ m .MergeCommitMessage = types .StringValue (repo .GetMergeCommitMessage ())
89+ m .IsTemplate = types .BoolValue (repo .GetIsTemplate ())
90+ // Attributes
91+ m .ID = types .Int64Value (repo .GetID ())
92+ m .NodeID = types .StringValue (repo .GetNodeID ())
93+ }
94+
6995func (r * GitHubRepositoryResource ) Metadata (_ context.Context , req resource.MetadataRequest , resp * resource.MetadataResponse ) {
7096 resp .TypeName = req .ProviderTypeName + "_repository"
7197}
@@ -389,27 +415,7 @@ func (r *GitHubRepositoryResource) Read(ctx context.Context, req resource.ReadRe
389415 return
390416 }
391417
392- model .Name = types .StringValue (repo .GetName ())
393- model .Description = types .StringValue (repo .GetDescription ())
394- model .Homepage = types .StringValue (repo .GetHomepage ())
395- model .Private = types .BoolValue (repo .GetPrivate ())
396- model .HasIssues = types .BoolValue (repo .GetHasIssues ())
397- model .HasProjects = types .BoolValue (repo .GetHasProjects ())
398- model .HasWiki = types .BoolValue (repo .GetHasWiki ())
399- model .HasDiscussions = types .BoolValue (repo .GetHasDiscussions ())
400- model .AllowSquashMerge = types .BoolValue (repo .GetAllowSquashMerge ())
401- model .AllowMergeCommit = types .BoolValue (repo .GetAllowMergeCommit ())
402- model .AllowRebaseMerge = types .BoolValue (repo .GetAllowRebaseMerge ())
403- model .AllowAutoMerge = types .BoolValue (repo .GetAllowAutoMerge ())
404- model .DeleteBranchOnMerge = types .BoolValue (repo .GetDeleteBranchOnMerge ())
405- model .SquashMergeCommitTitle = types .StringValue (repo .GetSquashMergeCommitTitle ())
406- model .SquashMergeCommitMessage = types .StringValue (repo .GetSquashMergeCommitMessage ())
407- model .MergeCommitTitle = types .StringValue (repo .GetMergeCommitTitle ())
408- model .MergeCommitMessage = types .StringValue (repo .GetMergeCommitMessage ())
409- model .IsTemplate = types .BoolValue (repo .GetIsTemplate ())
410-
411- model .ID = types .Int64Value (repo .GetID ())
412- model .NodeID = types .StringValue (repo .GetNodeID ())
418+ model .UpdateFromAPI (repo )
413419
414420 // Save updated data into Terraform state.
415421 resp .Diagnostics .Append (resp .State .Set (ctx , & model )... )
@@ -428,9 +434,9 @@ func (r *GitHubRepositoryResource) Create(ctx context.Context, req resource.Crea
428434 return
429435 }
430436
431- useTemplate :=
432- ! model .TemplateRepositoryName .IsNull () &&
433- ! model .TemplateRepositoryName .IsUnknown ()
437+ useTemplate := false
438+ // !model.TemplateRepositoryName.IsNull() &&
439+ // !model.TemplateRepositoryName.IsUnknown()
434440
435441 if useTemplate {
436442 repository := & github.Repository {
@@ -491,27 +497,7 @@ func (r *GitHubRepositoryResource) Create(ctx context.Context, req resource.Crea
491497 return
492498 }
493499
494- model .Name = types .StringValue (repo .GetName ())
495- model .Description = types .StringValue (repo .GetDescription ())
496- model .Homepage = types .StringValue (repo .GetHomepage ())
497- model .Private = types .BoolValue (repo .GetPrivate ())
498- model .HasIssues = types .BoolValue (repo .GetHasIssues ())
499- model .HasProjects = types .BoolValue (repo .GetHasProjects ())
500- model .HasWiki = types .BoolValue (repo .GetHasWiki ())
501- model .HasDiscussions = types .BoolValue (repo .GetHasDiscussions ())
502- model .AllowSquashMerge = types .BoolValue (repo .GetAllowSquashMerge ())
503- model .AllowMergeCommit = types .BoolValue (repo .GetAllowMergeCommit ())
504- model .AllowRebaseMerge = types .BoolValue (repo .GetAllowRebaseMerge ())
505- model .AllowAutoMerge = types .BoolValue (repo .GetAllowAutoMerge ())
506- model .DeleteBranchOnMerge = types .BoolValue (repo .GetDeleteBranchOnMerge ())
507- model .SquashMergeCommitTitle = types .StringValue (repo .GetSquashMergeCommitTitle ())
508- model .SquashMergeCommitMessage = types .StringValue (repo .GetSquashMergeCommitMessage ())
509- model .MergeCommitTitle = types .StringValue (repo .GetMergeCommitTitle ())
510- model .MergeCommitMessage = types .StringValue (repo .GetMergeCommitMessage ())
511- model .IsTemplate = types .BoolValue (repo .GetIsTemplate ())
512-
513- model .ID = types .Int64Value (repo .GetID ())
514- model .NodeID = types .StringValue (repo .GetNodeID ())
500+ model .UpdateFromAPI (repo )
515501
516502 // Save updated data into Terraform state.
517503 resp .Diagnostics .Append (resp .State .Set (ctx , & model )... )
@@ -550,27 +536,7 @@ func (r *GitHubRepositoryResource) Create(ctx context.Context, req resource.Crea
550536 return
551537 }
552538
553- model .Name = types .StringValue (repo .GetName ())
554- model .Description = types .StringValue (repo .GetDescription ())
555- model .Homepage = types .StringValue (repo .GetHomepage ())
556- model .Private = types .BoolValue (repo .GetPrivate ())
557- model .HasIssues = types .BoolValue (repo .GetHasIssues ())
558- model .HasProjects = types .BoolValue (repo .GetHasProjects ())
559- model .HasWiki = types .BoolValue (repo .GetHasWiki ())
560- model .HasDiscussions = types .BoolValue (repo .GetHasDiscussions ())
561- model .AllowSquashMerge = types .BoolValue (repo .GetAllowSquashMerge ())
562- model .AllowMergeCommit = types .BoolValue (repo .GetAllowMergeCommit ())
563- model .AllowRebaseMerge = types .BoolValue (repo .GetAllowRebaseMerge ())
564- model .AllowAutoMerge = types .BoolValue (repo .GetAllowAutoMerge ())
565- model .DeleteBranchOnMerge = types .BoolValue (repo .GetDeleteBranchOnMerge ())
566- model .SquashMergeCommitTitle = types .StringValue (repo .GetSquashMergeCommitTitle ())
567- model .SquashMergeCommitMessage = types .StringValue (repo .GetSquashMergeCommitMessage ())
568- model .MergeCommitTitle = types .StringValue (repo .GetMergeCommitTitle ())
569- model .MergeCommitMessage = types .StringValue (repo .GetMergeCommitMessage ())
570- model .IsTemplate = types .BoolValue (repo .GetIsTemplate ())
571-
572- model .ID = types .Int64Value (repo .GetID ())
573- model .NodeID = types .StringValue (repo .GetNodeID ())
539+ model .UpdateFromAPI (repo )
574540
575541 // Save updated data into Terraform state.
576542 resp .Diagnostics .Append (resp .State .Set (ctx , & model )... )
@@ -632,27 +598,7 @@ func (r *GitHubRepositoryResource) Update(ctx context.Context, req resource.Upda
632598 return
633599 }
634600
635- model .Name = types .StringValue (repo .GetName ())
636- model .Description = types .StringValue (repo .GetDescription ())
637- model .Homepage = types .StringValue (repo .GetHomepage ())
638- model .Private = types .BoolValue (repo .GetPrivate ())
639- model .HasIssues = types .BoolValue (repo .GetHasIssues ())
640- model .HasProjects = types .BoolValue (repo .GetHasProjects ())
641- model .HasWiki = types .BoolValue (repo .GetHasWiki ())
642- model .HasDiscussions = types .BoolValue (repo .GetHasDiscussions ())
643- model .AllowSquashMerge = types .BoolValue (repo .GetAllowSquashMerge ())
644- model .AllowMergeCommit = types .BoolValue (repo .GetAllowMergeCommit ())
645- model .AllowRebaseMerge = types .BoolValue (repo .GetAllowRebaseMerge ())
646- model .AllowAutoMerge = types .BoolValue (repo .GetAllowAutoMerge ())
647- model .DeleteBranchOnMerge = types .BoolValue (repo .GetDeleteBranchOnMerge ())
648- model .SquashMergeCommitTitle = types .StringValue (repo .GetSquashMergeCommitTitle ())
649- model .SquashMergeCommitMessage = types .StringValue (repo .GetSquashMergeCommitMessage ())
650- model .MergeCommitTitle = types .StringValue (repo .GetMergeCommitTitle ())
651- model .MergeCommitMessage = types .StringValue (repo .GetMergeCommitMessage ())
652- model .IsTemplate = types .BoolValue (repo .GetIsTemplate ())
653-
654- model .ID = types .Int64Value (repo .GetID ())
655- model .NodeID = types .StringValue (repo .GetNodeID ())
601+ model .UpdateFromAPI (repo )
656602
657603 // Save updated data into Terraform state.
658604 resp .Diagnostics .Append (resp .State .Set (ctx , & model )... )
0 commit comments