@@ -772,13 +772,8 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
772772 var units []repo_model.RepoUnit
773773 var deleteUnitTypes []unit_model.Type
774774
775- currHasIssues := repo .UnitEnabled (ctx , unit_model .TypeIssues )
776- newHasIssues := currHasIssues
777775 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 () {
782777 // Check that values are valid
783778 if ! validation .IsValidExternalURL (opts .ExternalTracker .ExternalTrackerURL ) {
784779 err := errors .New ("External tracker URL not valid" )
@@ -802,7 +797,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
802797 },
803798 })
804799 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 () {
806801 // Default to built-in tracker
807802 var config * repo_model.IssuesConfig
808803
@@ -829,7 +824,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
829824 Config : config ,
830825 })
831826 deleteUnitTypes = append (deleteUnitTypes , unit_model .TypeExternalTracker )
832- } else if ! newHasIssues {
827+ } else if ! * opts . HasIssues {
833828 if ! unit_model .TypeExternalTracker .UnitGlobalDisabled () {
834829 deleteUnitTypes = append (deleteUnitTypes , unit_model .TypeExternalTracker )
835830 }
@@ -839,13 +834,8 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
839834 }
840835 }
841836
842- currHasWiki := repo .UnitEnabled (ctx , unit_model .TypeWiki )
843- newHasWiki := currHasWiki
844837 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 () {
849839 // Check that values are valid
850840 if ! validation .IsValidExternalURL (opts .ExternalWiki .ExternalWikiURL ) {
851841 err := errors .New ("External wiki URL not valid" )
@@ -861,15 +851,15 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
861851 },
862852 })
863853 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 () {
865855 config := & repo_model.UnitConfig {}
866856 units = append (units , repo_model.RepoUnit {
867857 RepoID : repo .ID ,
868858 Type : unit_model .TypeWiki ,
869859 Config : config ,
870860 })
871861 deleteUnitTypes = append (deleteUnitTypes , unit_model .TypeExternalWiki )
872- } else if ! newHasWiki {
862+ } else if ! * opts . HasWiki {
873863 if ! unit_model .TypeExternalWiki .UnitGlobalDisabled () {
874864 deleteUnitTypes = append (deleteUnitTypes , unit_model .TypeExternalWiki )
875865 }
@@ -879,30 +869,20 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
879869 }
880870 }
881871
882- currHasCode := repo .UnitEnabled (ctx , unit_model .TypeCode )
883- newHasCode := currHasCode
884- if opts .HasCode != nil {
885- newHasCode = * opts .HasCode
886- }
887- if currHasCode || newHasCode {
888- if newHasCode && ! unit_model .TypeCode .UnitGlobalDisabled () {
889- units = append (units , repo_model.RepoUnit {
890- RepoID : repo .ID ,
891- Type : unit_model .TypeCode ,
892- Config : & repo_model.UnitConfig {},
893- })
894- } else if ! newHasCode && ! unit_model .TypeCode .UnitGlobalDisabled () {
895- deleteUnitTypes = append (deleteUnitTypes , unit_model .TypeCode )
896- }
897- }
898-
899- currHasPullRequests := repo .UnitEnabled (ctx , unit_model .TypePullRequests )
900- newHasPullRequests := currHasPullRequests
901- if opts .HasPullRequests != nil {
902- newHasPullRequests = * opts .HasPullRequests
903- }
904- if currHasPullRequests || newHasPullRequests {
905- if newHasPullRequests && ! unit_model .TypePullRequests .UnitGlobalDisabled () {
872+ if opts .HasCode != nil && ! unit_model .TypeCode .UnitGlobalDisabled () {
873+ if * opts .HasCode {
874+ units = append (units , repo_model.RepoUnit {
875+ RepoID : repo .ID ,
876+ Type : unit_model .TypeCode ,
877+ Config : & repo_model.UnitConfig {},
878+ })
879+ } else {
880+ deleteUnitTypes = append (deleteUnitTypes , unit_model .TypeCode )
881+ }
882+ }
883+
884+ if opts .HasPullRequests != nil && ! unit_model .TypePullRequests .UnitGlobalDisabled () {
885+ if * opts .HasPullRequests {
906886 // We do allow setting individual PR settings through the API, so
907887 // we get the config settings and then set them
908888 // if those settings were provided in the opts.
@@ -970,18 +950,13 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
970950 Type : unit_model .TypePullRequests ,
971951 Config : config ,
972952 })
973- } else if ! newHasPullRequests && ! unit_model . TypePullRequests . UnitGlobalDisabled () {
953+ } else {
974954 deleteUnitTypes = append (deleteUnitTypes , unit_model .TypePullRequests )
975955 }
976956 }
977957
978- currHasProjects := repo .UnitEnabled (ctx , unit_model .TypeProjects )
979- newHasProjects := currHasProjects
980- if opts .HasProjects != nil {
981- newHasProjects = * opts .HasProjects
982- }
983- if currHasProjects || newHasProjects {
984- if newHasProjects && ! unit_model .TypeProjects .UnitGlobalDisabled () {
958+ if opts .HasProjects != nil && ! unit_model .TypeProjects .UnitGlobalDisabled () {
959+ if * opts .HasProjects {
985960 unit , err := repo .GetUnit (ctx , unit_model .TypeProjects )
986961 var config * repo_model.ProjectsConfig
987962 if err != nil {
@@ -1001,7 +976,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
1001976 Type : unit_model .TypeProjects ,
1002977 Config : config ,
1003978 })
1004- } else if ! newHasProjects && ! unit_model . TypeProjects . UnitGlobalDisabled () {
979+ } else {
1005980 deleteUnitTypes = append (deleteUnitTypes , unit_model .TypeProjects )
1006981 }
1007982 }
0 commit comments