summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/repo/repo.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/api/v1/repo/repo.go')
-rw-r--r--routers/api/v1/repo/repo.go100
1 files changed, 72 insertions, 28 deletions
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index 513e7a37b3..d8b06862a5 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -19,6 +19,7 @@ import (
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
+ "code.gitea.io/gitea/modules/validation"
"code.gitea.io/gitea/routers/api/v1/convert"
mirror_service "code.gitea.io/gitea/services/mirror"
)
@@ -669,27 +670,56 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
units = append(units, *unit)
}
} else if *opts.HasIssues {
- // We don't currently allow setting individual issue settings through the API,
- // only can enable/disable issues, so when enabling issues,
- // we either get the existing config which means it was already enabled,
- // or create a new config since it doesn't exist.
- unit, err := repo.GetUnit(models.UnitTypeIssues)
- var config *models.IssuesConfig
- if err != nil {
- // Unit type doesn't exist so we make a new config file with default values
- config = &models.IssuesConfig{
- EnableTimetracker: true,
- AllowOnlyContributorsToTrackTime: true,
- EnableDependencies: true,
+ if opts.ExternalTracker != nil {
+
+ // Check that values are valid
+ if !validation.IsValidExternalURL(opts.ExternalTracker.ExternalTrackerURL) {
+ err := fmt.Errorf("External tracker URL not valid")
+ ctx.Error(http.StatusUnprocessableEntity, "Invalid external tracker URL", err)
+ return err
}
+ if len(opts.ExternalTracker.ExternalTrackerFormat) != 0 && !validation.IsValidExternalTrackerURLFormat(opts.ExternalTracker.ExternalTrackerFormat) {
+ err := fmt.Errorf("External tracker URL format not valid")
+ ctx.Error(http.StatusUnprocessableEntity, "Invalid external tracker URL format", err)
+ return err
+ }
+
+ units = append(units, models.RepoUnit{
+ RepoID: repo.ID,
+ Type: models.UnitTypeExternalTracker,
+ Config: &models.ExternalTrackerConfig{
+ ExternalTrackerURL: opts.ExternalTracker.ExternalTrackerURL,
+ ExternalTrackerFormat: opts.ExternalTracker.ExternalTrackerFormat,
+ ExternalTrackerStyle: opts.ExternalTracker.ExternalTrackerStyle,
+ },
+ })
} else {
- config = unit.IssuesConfig()
+ // Default to built-in tracker
+ var config *models.IssuesConfig
+
+ if opts.InternalTracker != nil {
+ config = &models.IssuesConfig{
+ EnableTimetracker: opts.InternalTracker.EnableTimeTracker,
+ AllowOnlyContributorsToTrackTime: opts.InternalTracker.AllowOnlyContributorsToTrackTime,
+ EnableDependencies: opts.InternalTracker.EnableIssueDependencies,
+ }
+ } else if unit, err := repo.GetUnit(models.UnitTypeIssues); err != nil {
+ // Unit type doesn't exist so we make a new config file with default values
+ config = &models.IssuesConfig{
+ EnableTimetracker: true,
+ AllowOnlyContributorsToTrackTime: true,
+ EnableDependencies: true,
+ }
+ } else {
+ config = unit.IssuesConfig()
+ }
+
+ units = append(units, models.RepoUnit{
+ RepoID: repo.ID,
+ Type: models.UnitTypeIssues,
+ Config: config,
+ })
}
- units = append(units, models.RepoUnit{
- RepoID: repo.ID,
- Type: models.UnitTypeIssues,
- Config: config,
- })
}
if opts.HasWiki == nil {
@@ -700,16 +730,30 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
units = append(units, *unit)
}
} else if *opts.HasWiki {
- // We don't currently allow setting individual wiki settings through the API,
- // only can enable/disable the wiki, so when enabling the wiki,
- // we either get the existing config which means it was already enabled,
- // or create a new config since it doesn't exist.
- config := &models.UnitConfig{}
- units = append(units, models.RepoUnit{
- RepoID: repo.ID,
- Type: models.UnitTypeWiki,
- Config: config,
- })
+ if opts.ExternalWiki != nil {
+
+ // Check that values are valid
+ if !validation.IsValidExternalURL(opts.ExternalWiki.ExternalWikiURL) {
+ err := fmt.Errorf("External wiki URL not valid")
+ ctx.Error(http.StatusUnprocessableEntity, "", "Invalid external wiki URL")
+ return err
+ }
+
+ units = append(units, models.RepoUnit{
+ RepoID: repo.ID,
+ Type: models.UnitTypeExternalWiki,
+ Config: &models.ExternalWikiConfig{
+ ExternalWikiURL: opts.ExternalWiki.ExternalWikiURL,
+ },
+ })
+ } else {
+ config := &models.UnitConfig{}
+ units = append(units, models.RepoUnit{
+ RepoID: repo.ID,
+ Type: models.UnitTypeWiki,
+ Config: config,
+ })
+ }
}
if opts.HasPullRequests == nil {