mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-17 11:59:30 +00:00
Api: advanced settings for repository (external wiki, issue tracker etc.) (#7756)
* Add API for Repo Advanced Settings of wiki and issue tracker Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Add some integration tests for tracker and wiki settings through API * Should return StatusUnprocessableEntity in case of invalid API values. * Add tests for invalid URLs for external tracker and wiki. * Do not set inital values if they are default of type * Make issue tracker and wiki units separate structures in Repository API structure. Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Fix comment of structures Signed-off-by: David Svantesson <davidsvantesson@gmail.com> * Rewrite API to use struct for setting tracker and wiki settings. * LetOnlyContributorsTrackTime -> AllowOnlyContributorsToTrackTime
This commit is contained in:
parent
f8899678d2
commit
90ab3056eb
5 changed files with 327 additions and 41 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue