|
|
@ -651,89 +651,102 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if opts.HasIssues != nil { |
|
|
|
if opts.HasIssues == nil { |
|
|
|
if *opts.HasIssues { |
|
|
|
// If HasIssues setting not touched, rewrite existing repo unit
|
|
|
|
// We don't currently allow setting individual issue settings through the API,
|
|
|
|
if unit, err := repo.GetUnit(models.UnitTypeIssues); err == nil { |
|
|
|
// only can enable/disable issues, so when enabling issues,
|
|
|
|
units = append(units, *unit) |
|
|
|
// we either get the existing config which means it was already enabled,
|
|
|
|
} else if unit, err := repo.GetUnit(models.UnitTypeExternalTracker); err == nil { |
|
|
|
// or create a new config since it doesn't exist.
|
|
|
|
units = append(units, *unit) |
|
|
|
unit, err := repo.GetUnit(models.UnitTypeIssues) |
|
|
|
} |
|
|
|
var config *models.IssuesConfig |
|
|
|
} else if *opts.HasIssues { |
|
|
|
if err != nil { |
|
|
|
// We don't currently allow setting individual issue settings through the API,
|
|
|
|
// Unit type doesn't exist so we make a new config file with default values
|
|
|
|
// only can enable/disable issues, so when enabling issues,
|
|
|
|
config = &models.IssuesConfig{ |
|
|
|
// we either get the existing config which means it was already enabled,
|
|
|
|
EnableTimetracker: true, |
|
|
|
// or create a new config since it doesn't exist.
|
|
|
|
AllowOnlyContributorsToTrackTime: true, |
|
|
|
unit, err := repo.GetUnit(models.UnitTypeIssues) |
|
|
|
EnableDependencies: true, |
|
|
|
var config *models.IssuesConfig |
|
|
|
} |
|
|
|
if err != nil { |
|
|
|
} else { |
|
|
|
// Unit type doesn't exist so we make a new config file with default values
|
|
|
|
config = unit.IssuesConfig() |
|
|
|
config = &models.IssuesConfig{ |
|
|
|
|
|
|
|
EnableTimetracker: true, |
|
|
|
|
|
|
|
AllowOnlyContributorsToTrackTime: true, |
|
|
|
|
|
|
|
EnableDependencies: true, |
|
|
|
} |
|
|
|
} |
|
|
|
units = append(units, models.RepoUnit{ |
|
|
|
} else { |
|
|
|
RepoID: repo.ID, |
|
|
|
config = unit.IssuesConfig() |
|
|
|
Type: models.UnitTypeIssues, |
|
|
|
|
|
|
|
Config: config, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
units = append(units, models.RepoUnit{ |
|
|
|
|
|
|
|
RepoID: repo.ID, |
|
|
|
|
|
|
|
Type: models.UnitTypeIssues, |
|
|
|
|
|
|
|
Config: config, |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if opts.HasWiki != nil { |
|
|
|
if opts.HasWiki == nil { |
|
|
|
if *opts.HasWiki { |
|
|
|
// If HasWiki setting not touched, rewrite existing repo unit
|
|
|
|
// We don't currently allow setting individual wiki settings through the API,
|
|
|
|
if unit, err := repo.GetUnit(models.UnitTypeWiki); err == nil { |
|
|
|
// only can enable/disable the wiki, so when enabling the wiki,
|
|
|
|
units = append(units, *unit) |
|
|
|
// we either get the existing config which means it was already enabled,
|
|
|
|
} else if unit, err := repo.GetUnit(models.UnitTypeExternalWiki); err == nil { |
|
|
|
// or create a new config since it doesn't exist.
|
|
|
|
units = append(units, *unit) |
|
|
|
config := &models.UnitConfig{} |
|
|
|
|
|
|
|
units = append(units, models.RepoUnit{ |
|
|
|
|
|
|
|
RepoID: repo.ID, |
|
|
|
|
|
|
|
Type: models.UnitTypeWiki, |
|
|
|
|
|
|
|
Config: config, |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} 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.HasPullRequests != nil { |
|
|
|
if opts.HasPullRequests == nil { |
|
|
|
if *opts.HasPullRequests { |
|
|
|
// If HasPullRequest setting not touched, rewrite existing repo unit
|
|
|
|
// We do allow setting individual PR settings through the API, so
|
|
|
|
if unit, err := repo.GetUnit(models.UnitTypePullRequests); err == nil { |
|
|
|
// we get the config settings and then set them
|
|
|
|
units = append(units, *unit) |
|
|
|
// if those settings were provided in the opts.
|
|
|
|
} |
|
|
|
unit, err := repo.GetUnit(models.UnitTypePullRequests) |
|
|
|
} else if *opts.HasPullRequests { |
|
|
|
var config *models.PullRequestsConfig |
|
|
|
// We do allow setting individual PR settings through the API, so
|
|
|
|
if err != nil { |
|
|
|
// we get the config settings and then set them
|
|
|
|
// Unit type doesn't exist so we make a new config file with default values
|
|
|
|
// if those settings were provided in the opts.
|
|
|
|
config = &models.PullRequestsConfig{ |
|
|
|
unit, err := repo.GetUnit(models.UnitTypePullRequests) |
|
|
|
IgnoreWhitespaceConflicts: false, |
|
|
|
var config *models.PullRequestsConfig |
|
|
|
AllowMerge: true, |
|
|
|
if err != nil { |
|
|
|
AllowRebase: true, |
|
|
|
// Unit type doesn't exist so we make a new config file with default values
|
|
|
|
AllowRebaseMerge: true, |
|
|
|
config = &models.PullRequestsConfig{ |
|
|
|
AllowSquash: true, |
|
|
|
IgnoreWhitespaceConflicts: false, |
|
|
|
} |
|
|
|
AllowMerge: true, |
|
|
|
} else { |
|
|
|
AllowRebase: true, |
|
|
|
config = unit.PullRequestsConfig() |
|
|
|
AllowRebaseMerge: true, |
|
|
|
} |
|
|
|
AllowSquash: true, |
|
|
|
|
|
|
|
|
|
|
|
if opts.IgnoreWhitespaceConflicts != nil { |
|
|
|
|
|
|
|
config.IgnoreWhitespaceConflicts = *opts.IgnoreWhitespaceConflicts |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if opts.AllowMerge != nil { |
|
|
|
|
|
|
|
config.AllowMerge = *opts.AllowMerge |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if opts.AllowRebase != nil { |
|
|
|
|
|
|
|
config.AllowRebase = *opts.AllowRebase |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if opts.AllowRebaseMerge != nil { |
|
|
|
|
|
|
|
config.AllowRebaseMerge = *opts.AllowRebaseMerge |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if opts.AllowSquash != nil { |
|
|
|
|
|
|
|
config.AllowSquash = *opts.AllowSquash |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
config = unit.PullRequestsConfig() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
units = append(units, models.RepoUnit{ |
|
|
|
if opts.IgnoreWhitespaceConflicts != nil { |
|
|
|
RepoID: repo.ID, |
|
|
|
config.IgnoreWhitespaceConflicts = *opts.IgnoreWhitespaceConflicts |
|
|
|
Type: models.UnitTypePullRequests, |
|
|
|
} |
|
|
|
Config: config, |
|
|
|
if opts.AllowMerge != nil { |
|
|
|
}) |
|
|
|
config.AllowMerge = *opts.AllowMerge |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if opts.AllowRebase != nil { |
|
|
|
|
|
|
|
config.AllowRebase = *opts.AllowRebase |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if opts.AllowRebaseMerge != nil { |
|
|
|
|
|
|
|
config.AllowRebaseMerge = *opts.AllowRebaseMerge |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if opts.AllowSquash != nil { |
|
|
|
|
|
|
|
config.AllowSquash = *opts.AllowSquash |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
units = append(units, models.RepoUnit{ |
|
|
|
|
|
|
|
RepoID: repo.ID, |
|
|
|
|
|
|
|
Type: models.UnitTypePullRequests, |
|
|
|
|
|
|
|
Config: config, |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := models.UpdateRepositoryUnits(repo, units); err != nil { |
|
|
|
if err := models.UpdateRepositoryUnits(repo, units); err != nil { |
|
|
|