@@ -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,13 +869,8 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
879869		}
880870	}
881871
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  {
889874			// We do allow setting individual PR settings through the API, so 
890875			// we get the config settings and then set them 
891876			// if those settings were provided in the opts. 
@@ -953,18 +938,13 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
953938				Type :   unit_model .TypePullRequests ,
954939				Config : config ,
955940			})
956- 		} else  if   ! newHasPullRequests   &&   ! unit_model . TypePullRequests . UnitGlobalDisabled ()  {
941+ 		} else  {
957942			deleteUnitTypes  =  append (deleteUnitTypes , unit_model .TypePullRequests )
958943		}
959944	}
960945
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  {
968948			unit , err  :=  repo .GetUnit (ctx , unit_model .TypeProjects )
969949			var  config  * repo_model.ProjectsConfig 
970950			if  err  !=  nil  {
@@ -984,7 +964,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
984964				Type :   unit_model .TypeProjects ,
985965				Config : config ,
986966			})
987- 		} else  if   ! newHasProjects   &&   ! unit_model . TypeProjects . UnitGlobalDisabled ()  {
967+ 		} else  {
988968			deleteUnitTypes  =  append (deleteUnitTypes , unit_model .TypeProjects )
989969		}
990970	}
0 commit comments