@@ -646,89 +646,102 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
646646 })
647647 }
648648
649- if opts .HasIssues != nil {
650- if * opts .HasIssues {
651- // We don't currently allow setting individual issue settings through the API,
652- // only can enable/disable issues, so when enabling issues,
653- // we either get the existing config which means it was already enabled,
654- // or create a new config since it doesn't exist.
655- unit , err := repo .GetUnit (models .UnitTypeIssues )
656- var config * models.IssuesConfig
657- if err != nil {
658- // Unit type doesn't exist so we make a new config file with default values
659- config = & models.IssuesConfig {
660- EnableTimetracker : true ,
661- AllowOnlyContributorsToTrackTime : true ,
662- EnableDependencies : true ,
663- }
664- } else {
665- config = unit .IssuesConfig ()
649+ if opts .HasIssues == nil {
650+ // If HasIssues setting not touched, rewrite existing repo unit
651+ if unit , err := repo .GetUnit (models .UnitTypeIssues ); err == nil {
652+ units = append (units , * unit )
653+ } else if unit , err := repo .GetUnit (models .UnitTypeExternalTracker ); err == nil {
654+ units = append (units , * unit )
655+ }
656+ } else if * opts .HasIssues {
657+ // We don't currently allow setting individual issue settings through the API,
658+ // only can enable/disable issues, so when enabling issues,
659+ // we either get the existing config which means it was already enabled,
660+ // or create a new config since it doesn't exist.
661+ unit , err := repo .GetUnit (models .UnitTypeIssues )
662+ var config * models.IssuesConfig
663+ if err != nil {
664+ // Unit type doesn't exist so we make a new config file with default values
665+ config = & models.IssuesConfig {
666+ EnableTimetracker : true ,
667+ AllowOnlyContributorsToTrackTime : true ,
668+ EnableDependencies : true ,
666669 }
667- units = append (units , models.RepoUnit {
668- RepoID : repo .ID ,
669- Type : models .UnitTypeIssues ,
670- Config : config ,
671- })
670+ } else {
671+ config = unit .IssuesConfig ()
672672 }
673+ units = append (units , models.RepoUnit {
674+ RepoID : repo .ID ,
675+ Type : models .UnitTypeIssues ,
676+ Config : config ,
677+ })
673678 }
674679
675- if opts .HasWiki != nil {
676- if * opts .HasWiki {
677- // We don't currently allow setting individual wiki settings through the API,
678- // only can enable/disable the wiki, so when enabling the wiki,
679- // we either get the existing config which means it was already enabled,
680- // or create a new config since it doesn't exist.
681- config := & models.UnitConfig {}
682- units = append (units , models.RepoUnit {
683- RepoID : repo .ID ,
684- Type : models .UnitTypeWiki ,
685- Config : config ,
686- })
680+ if opts .HasWiki == nil {
681+ // If HasWiki setting not touched, rewrite existing repo unit
682+ if unit , err := repo .GetUnit (models .UnitTypeWiki ); err == nil {
683+ units = append (units , * unit )
684+ } else if unit , err := repo .GetUnit (models .UnitTypeExternalWiki ); err == nil {
685+ units = append (units , * unit )
687686 }
687+ } else if * opts .HasWiki {
688+ // We don't currently allow setting individual wiki settings through the API,
689+ // only can enable/disable the wiki, so when enabling the wiki,
690+ // we either get the existing config which means it was already enabled,
691+ // or create a new config since it doesn't exist.
692+ config := & models.UnitConfig {}
693+ units = append (units , models.RepoUnit {
694+ RepoID : repo .ID ,
695+ Type : models .UnitTypeWiki ,
696+ Config : config ,
697+ })
688698 }
689699
690- if opts .HasPullRequests != nil {
691- if * opts .HasPullRequests {
692- // We do allow setting individual PR settings through the API, so
693- // we get the config settings and then set them
694- // if those settings were provided in the opts.
695- unit , err := repo .GetUnit (models .UnitTypePullRequests )
696- var config * models.PullRequestsConfig
697- if err != nil {
698- // Unit type doesn't exist so we make a new config file with default values
699- config = & models.PullRequestsConfig {
700- IgnoreWhitespaceConflicts : false ,
701- AllowMerge : true ,
702- AllowRebase : true ,
703- AllowRebaseMerge : true ,
704- AllowSquash : true ,
705- }
706- } else {
707- config = unit .PullRequestsConfig ()
708- }
709-
710- if opts .IgnoreWhitespaceConflicts != nil {
711- config .IgnoreWhitespaceConflicts = * opts .IgnoreWhitespaceConflicts
712- }
713- if opts .AllowMerge != nil {
714- config .AllowMerge = * opts .AllowMerge
715- }
716- if opts .AllowRebase != nil {
717- config .AllowRebase = * opts .AllowRebase
718- }
719- if opts .AllowRebaseMerge != nil {
720- config .AllowRebaseMerge = * opts .AllowRebaseMerge
721- }
722- if opts .AllowSquash != nil {
723- config .AllowSquash = * opts .AllowSquash
700+ if opts .HasPullRequests == nil {
701+ // If HasPullRequest setting not touched, rewrite existing repo unit
702+ if unit , err := repo .GetUnit (models .UnitTypePullRequests ); err == nil {
703+ units = append (units , * unit )
704+ }
705+ } else if * opts .HasPullRequests {
706+ // We do allow setting individual PR settings through the API, so
707+ // we get the config settings and then set them
708+ // if those settings were provided in the opts.
709+ unit , err := repo .GetUnit (models .UnitTypePullRequests )
710+ var config * models.PullRequestsConfig
711+ if err != nil {
712+ // Unit type doesn't exist so we make a new config file with default values
713+ config = & models.PullRequestsConfig {
714+ IgnoreWhitespaceConflicts : false ,
715+ AllowMerge : true ,
716+ AllowRebase : true ,
717+ AllowRebaseMerge : true ,
718+ AllowSquash : true ,
724719 }
720+ } else {
721+ config = unit .PullRequestsConfig ()
722+ }
725723
726- units = append (units , models.RepoUnit {
727- RepoID : repo .ID ,
728- Type : models .UnitTypePullRequests ,
729- Config : config ,
730- })
724+ if opts .IgnoreWhitespaceConflicts != nil {
725+ config .IgnoreWhitespaceConflicts = * opts .IgnoreWhitespaceConflicts
726+ }
727+ if opts .AllowMerge != nil {
728+ config .AllowMerge = * opts .AllowMerge
729+ }
730+ if opts .AllowRebase != nil {
731+ config .AllowRebase = * opts .AllowRebase
732+ }
733+ if opts .AllowRebaseMerge != nil {
734+ config .AllowRebaseMerge = * opts .AllowRebaseMerge
735+ }
736+ if opts .AllowSquash != nil {
737+ config .AllowSquash = * opts .AllowSquash
731738 }
739+
740+ units = append (units , models.RepoUnit {
741+ RepoID : repo .ID ,
742+ Type : models .UnitTypePullRequests ,
743+ Config : config ,
744+ })
732745 }
733746
734747 if err := models .UpdateRepositoryUnits (repo , units ); err != nil {
0 commit comments