@@ -444,8 +444,8 @@ func resourceGitlabProjectCreate(d *schema.ResourceData, meta interface{}) error
444
444
}
445
445
}
446
446
447
- if v , ok := d .GetOk ("push_rules" ); ok {
448
- err := editOrAddPushRules (client , d .Id (), v .([] interface {})[ 0 ].( map [ string ] interface {}) )
447
+ if _ , ok := d .GetOk ("push_rules" ); ok {
448
+ err := editOrAddPushRules (client , d .Id (), d )
449
449
var httpError * gitlab.ErrorResponse
450
450
if errors .As (err , & httpError ) && httpError .Response .StatusCode == http .StatusNotFound {
451
451
log .Printf ("[DEBUG] Failed to edit push rules for project %q: %v" , d .Id (), err )
@@ -631,7 +631,7 @@ func resourceGitlabProjectUpdate(d *schema.ResourceData, meta interface{}) error
631
631
}
632
632
633
633
if d .HasChange ("push_rules" ) {
634
- err := editOrAddPushRules (client , d .Id (), d . Get ( "push_rules" ).([] interface {})[ 0 ].( map [ string ] interface {}) )
634
+ err := editOrAddPushRules (client , d .Id (), d )
635
635
var httpError * gitlab.ErrorResponse
636
636
if errors .As (err , & httpError ) && httpError .Response .StatusCode == http .StatusNotFound {
637
637
log .Printf ("[DEBUG] Failed to get push rules for project %q: %v" , d .Id (), err )
@@ -687,10 +687,10 @@ func resourceGitlabProjectDelete(d *schema.ResourceData, meta interface{}) error
687
687
return nil
688
688
}
689
689
690
- func editOrAddPushRules (client * gitlab.Client , projectID string , m map [ string ] interface {} ) error {
690
+ func editOrAddPushRules (client * gitlab.Client , projectID string , d * schema. ResourceData ) error {
691
691
log .Printf ("[DEBUG] Editing push rules for project %q" , projectID )
692
692
693
- editOptions := expandEditProjectPushRuleOptions (m )
693
+ editOptions := expandEditProjectPushRuleOptions (d )
694
694
_ , _ , err := client .Projects .EditProjectPushRule (projectID , editOptions )
695
695
if err == nil {
696
696
return nil
@@ -706,7 +706,7 @@ func editOrAddPushRules(client *gitlab.Client, projectID string, m map[string]in
706
706
log .Printf ("[DEBUG] Failed to edit push rules for project %q: %v" , projectID , err )
707
707
log .Printf ("[DEBUG] Creating new push rules for project %q" , projectID )
708
708
709
- addOptions := expandAddProjectPushRuleOptions (m )
709
+ addOptions := expandAddProjectPushRuleOptions (d )
710
710
_ , _ , err = client .Projects .AddProjectPushRule (projectID , addOptions )
711
711
if err != nil {
712
712
return err
@@ -715,36 +715,104 @@ func editOrAddPushRules(client *gitlab.Client, projectID string, m map[string]in
715
715
return nil
716
716
}
717
717
718
- func expandEditProjectPushRuleOptions (m map [string ]interface {}) * gitlab.EditProjectPushRuleOptions {
719
- return & gitlab.EditProjectPushRuleOptions {
720
- AuthorEmailRegex : gitlab .String (m ["author_email_regex" ].(string )),
721
- BranchNameRegex : gitlab .String (m ["branch_name_regex" ].(string )),
722
- CommitMessageRegex : gitlab .String (m ["commit_message_regex" ].(string )),
723
- CommitMessageNegativeRegex : gitlab .String (m ["commit_message_negative_regex" ].(string )),
724
- FileNameRegex : gitlab .String (m ["file_name_regex" ].(string )),
725
- CommitCommitterCheck : gitlab .Bool (m ["commit_committer_check" ].(bool )),
726
- DenyDeleteTag : gitlab .Bool (m ["deny_delete_tag" ].(bool )),
727
- MemberCheck : gitlab .Bool (m ["member_check" ].(bool )),
728
- PreventSecrets : gitlab .Bool (m ["prevent_secrets" ].(bool )),
729
- RejectUnsignedCommits : gitlab .Bool (m ["reject_unsigned_commits" ].(bool )),
730
- MaxFileSize : gitlab .Int (m ["max_file_size" ].(int )),
718
+ func expandEditProjectPushRuleOptions (d * schema.ResourceData ) * gitlab.EditProjectPushRuleOptions {
719
+ options := & gitlab.EditProjectPushRuleOptions {}
720
+
721
+ if d .HasChange ("push_rules.0.author_email_regex" ) {
722
+ options .AuthorEmailRegex = gitlab .String (d .Get ("push_rules.0.author_email_regex" ).(string ))
723
+ }
724
+
725
+ if d .HasChange ("push_rules.0.branch_name_regex" ) {
726
+ options .BranchNameRegex = gitlab .String (d .Get ("push_rules.0.branch_name_regex" ).(string ))
727
+ }
728
+
729
+ if d .HasChange ("push_rules.0.commit_message_regex" ) {
730
+ options .CommitMessageRegex = gitlab .String (d .Get ("push_rules.0.commit_message_regex" ).(string ))
731
+ }
732
+
733
+ if d .HasChange ("push_rules.0.commit_message_negative_regex" ) {
734
+ options .CommitMessageNegativeRegex = gitlab .String (d .Get ("push_rules.0.commit_message_negative_regex" ).(string ))
735
+ }
736
+
737
+ if d .HasChange ("push_rules.0.file_name_regex" ) {
738
+ options .FileNameRegex = gitlab .String (d .Get ("push_rules.0.file_name_regex" ).(string ))
739
+ }
740
+
741
+ if d .HasChange ("push_rules.0.commit_committer_check" ) {
742
+ options .CommitCommitterCheck = gitlab .Bool (d .Get ("push_rules.0.commit_committer_check" ).(bool ))
731
743
}
744
+
745
+ if d .HasChange ("push_rules.0.deny_delete_tag" ) {
746
+ options .DenyDeleteTag = gitlab .Bool (d .Get ("push_rules.0.deny_delete_tag" ).(bool ))
747
+ }
748
+
749
+ if d .HasChange ("push_rules.0.member_check" ) {
750
+ options .MemberCheck = gitlab .Bool (d .Get ("push_rules.0.member_check" ).(bool ))
751
+ }
752
+
753
+ if d .HasChange ("push_rules.0.prevent_secrets" ) {
754
+ options .PreventSecrets = gitlab .Bool (d .Get ("push_rules.0.prevent_secrets" ).(bool ))
755
+ }
756
+
757
+ if d .HasChange ("push_rules.0.reject_unsigned_commits" ) {
758
+ options .RejectUnsignedCommits = gitlab .Bool (d .Get ("push_rules.0.reject_unsigned_commits" ).(bool ))
759
+ }
760
+
761
+ if d .HasChange ("push_rules.0.max_file_size" ) {
762
+ options .MaxFileSize = gitlab .Int (d .Get ("push_rules.0.max_file_size" ).(int ))
763
+ }
764
+
765
+ return options
732
766
}
733
767
734
- func expandAddProjectPushRuleOptions (m map [string ]interface {}) * gitlab.AddProjectPushRuleOptions {
735
- return & gitlab.AddProjectPushRuleOptions {
736
- AuthorEmailRegex : gitlab .String (m ["author_email_regex" ].(string )),
737
- BranchNameRegex : gitlab .String (m ["branch_name_regex" ].(string )),
738
- CommitMessageRegex : gitlab .String (m ["commit_message_regex" ].(string )),
739
- CommitMessageNegativeRegex : gitlab .String (m ["commit_message_negative_regex" ].(string )),
740
- FileNameRegex : gitlab .String (m ["file_name_regex" ].(string )),
741
- CommitCommitterCheck : gitlab .Bool (m ["commit_committer_check" ].(bool )),
742
- DenyDeleteTag : gitlab .Bool (m ["deny_delete_tag" ].(bool )),
743
- MemberCheck : gitlab .Bool (m ["member_check" ].(bool )),
744
- PreventSecrets : gitlab .Bool (m ["prevent_secrets" ].(bool )),
745
- RejectUnsignedCommits : gitlab .Bool (m ["reject_unsigned_commits" ].(bool )),
746
- MaxFileSize : gitlab .Int (m ["max_file_size" ].(int )),
768
+ func expandAddProjectPushRuleOptions (d * schema.ResourceData ) * gitlab.AddProjectPushRuleOptions {
769
+ options := & gitlab.AddProjectPushRuleOptions {}
770
+
771
+ if v , ok := d .GetOk ("push_rules.0.author_email_regex" ); ok {
772
+ options .AuthorEmailRegex = gitlab .String (v .(string ))
773
+ }
774
+
775
+ if v , ok := d .GetOk ("push_rules.0.branch_name_regex" ); ok {
776
+ options .BranchNameRegex = gitlab .String (v .(string ))
777
+ }
778
+
779
+ if v , ok := d .GetOk ("push_rules.0.commit_message_regex" ); ok {
780
+ options .CommitMessageRegex = gitlab .String (v .(string ))
781
+ }
782
+
783
+ if v , ok := d .GetOk ("push_rules.0.commit_message_negative_regex" ); ok {
784
+ options .CommitMessageNegativeRegex = gitlab .String (v .(string ))
785
+ }
786
+
787
+ if v , ok := d .GetOk ("push_rules.0.file_name_regex" ); ok {
788
+ options .FileNameRegex = gitlab .String (v .(string ))
789
+ }
790
+
791
+ if v , ok := d .GetOk ("push_rules.0.commit_committer_check" ); ok {
792
+ options .CommitCommitterCheck = gitlab .Bool (v .(bool ))
747
793
}
794
+
795
+ if v , ok := d .GetOk ("push_rules.0.deny_delete_tag" ); ok {
796
+ options .DenyDeleteTag = gitlab .Bool (v .(bool ))
797
+ }
798
+
799
+ if v , ok := d .GetOk ("push_rules.0.member_check" ); ok {
800
+ options .MemberCheck = gitlab .Bool (v .(bool ))
801
+ }
802
+
803
+ if v , ok := d .GetOk ("push_rules.0.prevent_secrets" ); ok {
804
+ options .PreventSecrets = gitlab .Bool (v .(bool ))
805
+ }
806
+
807
+ if v , ok := d .GetOk ("push_rules.0.reject_unsigned_commits" ); ok {
808
+ options .RejectUnsignedCommits = gitlab .Bool (v .(bool ))
809
+ }
810
+
811
+ if v , ok := d .GetOk ("push_rules.0.max_file_size" ); ok {
812
+ options .MaxFileSize = gitlab .Int (v .(int ))
813
+ }
814
+
815
+ return options
748
816
}
749
817
750
818
func flattenProjectPushRules (pushRules * gitlab.ProjectPushRules ) (values []map [string ]interface {}) {
0 commit comments