@@ -18,6 +18,7 @@ import (
18
18
"code.gitea.io/gitea/modules/notification"
19
19
"code.gitea.io/gitea/modules/setting"
20
20
"code.gitea.io/gitea/modules/util"
21
+ "code.gitea.io/gitea/modules/validation"
21
22
"code.gitea.io/gitea/routers/api/v1/convert"
22
23
23
24
api "code.gitea.io/gitea/modules/structs"
@@ -659,27 +660,77 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
659
660
units = append (units , * unit )
660
661
}
661
662
} else if * opts .HasIssues {
662
- // We don't currently allow setting individual issue settings through the API,
663
- // only can enable/disable issues, so when enabling issues,
664
- // we either get the existing config which means it was already enabled,
665
- // or create a new config since it doesn't exist.
666
- unit , err := repo .GetUnit (models .UnitTypeIssues )
667
- var config * models.IssuesConfig
668
- if err != nil {
669
- // Unit type doesn't exist so we make a new config file with default values
670
- config = & models.IssuesConfig {
671
- EnableTimetracker : true ,
672
- AllowOnlyContributorsToTrackTime : true ,
673
- EnableDependencies : true ,
663
+ if opts .ExternalTracker != nil && * opts .ExternalTracker {
664
+
665
+ var config * models.ExternalTrackerConfig
666
+ if unit , err := repo .GetUnit (models .UnitTypeExternalTracker ); err != nil {
667
+ // Unit type doesn't exist so we make a new config file, default empty strings
668
+ config = & models.ExternalTrackerConfig {
669
+ ExternalTrackerURL : "" ,
670
+ ExternalTrackerFormat : "" ,
671
+ ExternalTrackerStyle : "" ,
672
+ }
673
+ } else {
674
+ config = unit .ExternalTrackerConfig ()
675
+ }
676
+
677
+ // Update values if set and valid
678
+ if opts .ExternalTrackerURL != nil {
679
+ if ! validation .IsValidExternalURL (* opts .ExternalTrackerURL ) {
680
+ err := fmt .Errorf ("External tracker URL not valid" )
681
+ ctx .Error (http .StatusBadRequest , "Invalid external tracker URL" , err )
682
+ return err
683
+ }
684
+ config .ExternalTrackerURL = * opts .ExternalTrackerURL
685
+ }
686
+ if opts .ExternalTrackerFormat != nil {
687
+ if len (* opts .ExternalTrackerFormat ) != 0 && ! validation .IsValidExternalTrackerURLFormat (* opts .ExternalTrackerFormat ) {
688
+ err := fmt .Errorf ("External tracker URL format not valid" )
689
+ ctx .Error (http .StatusBadRequest , "Invalid external tracker URL format" , err )
690
+ return err
691
+ }
692
+ config .ExternalTrackerFormat = * opts .ExternalTrackerFormat
693
+ }
694
+ if opts .ExternalTrackerStyle != nil {
695
+ config .ExternalTrackerStyle = * opts .ExternalTrackerStyle
674
696
}
697
+
698
+ units = append (units , models.RepoUnit {
699
+ RepoID : repo .ID ,
700
+ Type : models .UnitTypeExternalTracker ,
701
+ Config : config ,
702
+ })
675
703
} else {
676
- config = unit .IssuesConfig ()
704
+ // Default to built-in tracker
705
+ var config * models.IssuesConfig
706
+ if unit , err := repo .GetUnit (models .UnitTypeIssues ); err != nil {
707
+ // Unit type doesn't exist so we make a new config file with default values
708
+ config = & models.IssuesConfig {
709
+ EnableTimetracker : true ,
710
+ AllowOnlyContributorsToTrackTime : true ,
711
+ EnableDependencies : true ,
712
+ }
713
+ } else {
714
+ config = unit .IssuesConfig ()
715
+ }
716
+
717
+ // Update values if set
718
+ if opts .EnableTimeTracker != nil {
719
+ config .EnableTimetracker = * opts .EnableTimeTracker
720
+ }
721
+ if opts .LetOnlyContributorsTrackTime != nil {
722
+ config .AllowOnlyContributorsToTrackTime = * opts .LetOnlyContributorsTrackTime
723
+ }
724
+ if opts .EnableIssueDependencies != nil {
725
+ config .EnableDependencies = * opts .EnableIssueDependencies
726
+ }
727
+
728
+ units = append (units , models.RepoUnit {
729
+ RepoID : repo .ID ,
730
+ Type : models .UnitTypeIssues ,
731
+ Config : config ,
732
+ })
677
733
}
678
- units = append (units , models.RepoUnit {
679
- RepoID : repo .ID ,
680
- Type : models .UnitTypeIssues ,
681
- Config : config ,
682
- })
683
734
}
684
735
685
736
if opts .HasWiki == nil {
@@ -690,16 +741,39 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
690
741
units = append (units , * unit )
691
742
}
692
743
} else if * opts .HasWiki {
693
- // We don't currently allow setting individual wiki settings through the API,
694
- // only can enable/disable the wiki, so when enabling the wiki,
695
- // we either get the existing config which means it was already enabled,
696
- // or create a new config since it doesn't exist.
697
- config := & models.UnitConfig {}
698
- units = append (units , models.RepoUnit {
699
- RepoID : repo .ID ,
700
- Type : models .UnitTypeWiki ,
701
- Config : config ,
702
- })
744
+ if opts .ExternalWiki != nil && * opts .ExternalWiki {
745
+ var config * models.ExternalWikiConfig
746
+ if unit , err := repo .GetUnit (models .UnitTypeExternalWiki ); err != nil {
747
+ // Unit type doesn't exist so we make a new config file, default empty strings
748
+ config = & models.ExternalWikiConfig {
749
+ ExternalWikiURL : "" ,
750
+ }
751
+ } else {
752
+ config = unit .ExternalWikiConfig ()
753
+ }
754
+
755
+ // Update values if set and valid
756
+ if opts .ExternalWikiURL != nil {
757
+ if ! validation .IsValidExternalURL (* opts .ExternalWikiURL ) {
758
+ err := fmt .Errorf ("External wiki URL not valid" )
759
+ ctx .Error (http .StatusBadRequest , "" , "Invalid external wiki URL" )
760
+ return err
761
+ }
762
+ config .ExternalWikiURL = * opts .ExternalWikiURL
763
+ }
764
+ units = append (units , models.RepoUnit {
765
+ RepoID : repo .ID ,
766
+ Type : models .UnitTypeExternalWiki ,
767
+ Config : config ,
768
+ })
769
+ } else {
770
+ config := & models.UnitConfig {}
771
+ units = append (units , models.RepoUnit {
772
+ RepoID : repo .ID ,
773
+ Type : models .UnitTypeWiki ,
774
+ Config : config ,
775
+ })
776
+ }
703
777
}
704
778
705
779
if opts .HasPullRequests == nil {
0 commit comments