@@ -772,13 +772,8 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
772
772
var units []repo_model.RepoUnit
773
773
var deleteUnitTypes []unit_model.Type
774
774
775
- currHasIssues := repo .UnitEnabled (ctx , unit_model .TypeIssues )
776
- newHasIssues := currHasIssues
777
775
if opts .HasIssues != nil {
778
- newHasIssues = * opts .HasIssues
779
- }
780
- if currHasIssues || newHasIssues {
781
- if newHasIssues && opts .ExternalTracker != nil && ! unit_model .TypeExternalTracker .UnitGlobalDisabled () {
776
+ if * opts .HasIssues && opts .ExternalTracker != nil && ! unit_model .TypeExternalTracker .UnitGlobalDisabled () {
782
777
// Check that values are valid
783
778
if ! validation .IsValidExternalURL (opts .ExternalTracker .ExternalTrackerURL ) {
784
779
err := errors .New ("External tracker URL not valid" )
@@ -802,7 +797,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
802
797
},
803
798
})
804
799
deleteUnitTypes = append (deleteUnitTypes , unit_model .TypeIssues )
805
- } else if newHasIssues && opts .ExternalTracker == nil && ! unit_model .TypeIssues .UnitGlobalDisabled () {
800
+ } else if * opts . HasIssues && opts .ExternalTracker == nil && ! unit_model .TypeIssues .UnitGlobalDisabled () {
806
801
// Default to built-in tracker
807
802
var config * repo_model.IssuesConfig
808
803
@@ -829,7 +824,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
829
824
Config : config ,
830
825
})
831
826
deleteUnitTypes = append (deleteUnitTypes , unit_model .TypeExternalTracker )
832
- } else if ! newHasIssues {
827
+ } else if ! * opts . HasIssues {
833
828
if ! unit_model .TypeExternalTracker .UnitGlobalDisabled () {
834
829
deleteUnitTypes = append (deleteUnitTypes , unit_model .TypeExternalTracker )
835
830
}
@@ -839,13 +834,8 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
839
834
}
840
835
}
841
836
842
- currHasWiki := repo .UnitEnabled (ctx , unit_model .TypeWiki )
843
- newHasWiki := currHasWiki
844
837
if opts .HasWiki != nil {
845
- newHasWiki = * opts .HasWiki
846
- }
847
- if currHasWiki || newHasWiki {
848
- if newHasWiki && opts .ExternalWiki != nil && ! unit_model .TypeExternalWiki .UnitGlobalDisabled () {
838
+ if * opts .HasWiki && opts .ExternalWiki != nil && ! unit_model .TypeExternalWiki .UnitGlobalDisabled () {
849
839
// Check that values are valid
850
840
if ! validation .IsValidExternalURL (opts .ExternalWiki .ExternalWikiURL ) {
851
841
err := errors .New ("External wiki URL not valid" )
@@ -861,15 +851,15 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
861
851
},
862
852
})
863
853
deleteUnitTypes = append (deleteUnitTypes , unit_model .TypeWiki )
864
- } else if newHasWiki && opts .ExternalWiki == nil && ! unit_model .TypeWiki .UnitGlobalDisabled () {
854
+ } else if * opts . HasWiki && opts .ExternalWiki == nil && ! unit_model .TypeWiki .UnitGlobalDisabled () {
865
855
config := & repo_model.UnitConfig {}
866
856
units = append (units , repo_model.RepoUnit {
867
857
RepoID : repo .ID ,
868
858
Type : unit_model .TypeWiki ,
869
859
Config : config ,
870
860
})
871
861
deleteUnitTypes = append (deleteUnitTypes , unit_model .TypeExternalWiki )
872
- } else if ! newHasWiki {
862
+ } else if ! * opts . HasWiki {
873
863
if ! unit_model .TypeExternalWiki .UnitGlobalDisabled () {
874
864
deleteUnitTypes = append (deleteUnitTypes , unit_model .TypeExternalWiki )
875
865
}
@@ -879,13 +869,8 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
879
869
}
880
870
}
881
871
882
- currHasPullRequests := repo .UnitEnabled (ctx , unit_model .TypePullRequests )
883
- newHasPullRequests := currHasPullRequests
884
- if opts .HasPullRequests != nil {
885
- newHasPullRequests = * opts .HasPullRequests
886
- }
887
- if currHasPullRequests || newHasPullRequests {
888
- if newHasPullRequests && ! unit_model .TypePullRequests .UnitGlobalDisabled () {
872
+ if opts .HasPullRequests != nil && ! unit_model .TypePullRequests .UnitGlobalDisabled () {
873
+ if * opts .HasPullRequests {
889
874
// We do allow setting individual PR settings through the API, so
890
875
// we get the config settings and then set them
891
876
// if those settings were provided in the opts.
@@ -953,18 +938,13 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
953
938
Type : unit_model .TypePullRequests ,
954
939
Config : config ,
955
940
})
956
- } else if ! newHasPullRequests && ! unit_model . TypePullRequests . UnitGlobalDisabled () {
941
+ } else {
957
942
deleteUnitTypes = append (deleteUnitTypes , unit_model .TypePullRequests )
958
943
}
959
944
}
960
945
961
- currHasProjects := repo .UnitEnabled (ctx , unit_model .TypeProjects )
962
- newHasProjects := currHasProjects
963
- if opts .HasProjects != nil {
964
- newHasProjects = * opts .HasProjects
965
- }
966
- if currHasProjects || newHasProjects {
967
- if newHasProjects && ! unit_model .TypeProjects .UnitGlobalDisabled () {
946
+ if opts .HasProjects != nil && ! unit_model .TypeProjects .UnitGlobalDisabled () {
947
+ if * opts .HasProjects {
968
948
unit , err := repo .GetUnit (ctx , unit_model .TypeProjects )
969
949
var config * repo_model.ProjectsConfig
970
950
if err != nil {
@@ -984,7 +964,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
984
964
Type : unit_model .TypeProjects ,
985
965
Config : config ,
986
966
})
987
- } else if ! newHasProjects && ! unit_model . TypeProjects . UnitGlobalDisabled () {
967
+ } else {
988
968
deleteUnitTypes = append (deleteUnitTypes , unit_model .TypeProjects )
989
969
}
990
970
}
0 commit comments