@ -757,25 +757,10 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
repo := ctx . Repo . Repository
var units [ ] models . RepoUnit
var deleteUnitTypes [ ] models . UnitType
for _ , tp := range models . MustRepoUnits {
units = append ( units , models . RepoUnit {
RepoID : repo . ID ,
Type : tp ,
Config : new ( models . UnitConfig ) ,
} )
}
if opts . HasIssues == nil {
// If HasIssues setting not touched, rewrite existing repo unit
if unit , err := repo . GetUnit ( models . UnitTypeIssues ) ; err == nil {
units = append ( units , * unit )
} else if unit , err := repo . GetUnit ( models . UnitTypeExternalTracker ) ; err == nil {
units = append ( units , * unit )
}
} else if * opts . HasIssues {
if opts . ExternalTracker != nil {
if opts . HasIssues != nil {
if * opts . HasIssues && opts . ExternalTracker != nil && ! models . UnitTypeExternalTracker . UnitGlobalDisabled ( ) {
// Check that values are valid
if ! validation . IsValidExternalURL ( opts . ExternalTracker . ExternalTrackerURL ) {
err := fmt . Errorf ( "External tracker URL not valid" )
@ -797,7 +782,8 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
ExternalTrackerStyle : opts . ExternalTracker . ExternalTrackerStyle ,
} ,
} )
} else {
deleteUnitTypes = append ( deleteUnitTypes , models . UnitTypeIssues )
} else if * opts . HasIssues && opts . ExternalTracker == nil && ! models . UnitTypeIssues . UnitGlobalDisabled ( ) {
// Default to built-in tracker
var config * models . IssuesConfig
@ -823,19 +809,19 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
Type : models . UnitTypeIssues ,
Config : config ,
} )
deleteUnitTypes = append ( deleteUnitTypes , models . UnitTypeExternalTracker )
} else if ! * opts . HasIssues {
if ! models . UnitTypeExternalTracker . UnitGlobalDisabled ( ) {
deleteUnitTypes = append ( deleteUnitTypes , models . UnitTypeExternalTracker )
}
if ! models . UnitTypeIssues . UnitGlobalDisabled ( ) {
deleteUnitTypes = append ( deleteUnitTypes , models . UnitTypeIssues )
}
}
}
if opts . HasWiki == nil {
// If HasWiki setting not touched, rewrite existing repo unit
if unit , err := repo . GetUnit ( models . UnitTypeWiki ) ; err == nil {
units = append ( units , * unit )
} else if unit , err := repo . GetUnit ( models . UnitTypeExternalWiki ) ; err == nil {
units = append ( units , * unit )
}
} else if * opts . HasWiki {
if opts . ExternalWiki != nil {
if opts . HasWiki != nil {
if * opts . HasWiki && opts . ExternalWiki != nil && ! models . UnitTypeExternalWiki . UnitGlobalDisabled ( ) {
// Check that values are valid
if ! validation . IsValidExternalURL ( opts . ExternalWiki . ExternalWikiURL ) {
err := fmt . Errorf ( "External wiki URL not valid" )
@ -850,64 +836,72 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
ExternalWikiURL : opts . ExternalWiki . ExternalWikiURL ,
} ,
} )
} else {
deleteUnitTypes = append ( deleteUnitTypes , models . UnitTypeWiki )
} else if * opts . HasWiki && opts . ExternalWiki == nil && ! models . UnitTypeWiki . UnitGlobalDisabled ( ) {
config := & models . UnitConfig { }
units = append ( units , models . RepoUnit {
RepoID : repo . ID ,
Type : models . UnitTypeWiki ,
Config : config ,
} )
deleteUnitTypes = append ( deleteUnitTypes , models . UnitTypeExternalWiki )
} else if ! * opts . HasWiki {
if ! models . UnitTypeExternalWiki . UnitGlobalDisabled ( ) {
deleteUnitTypes = append ( deleteUnitTypes , models . UnitTypeExternalWiki )
}
if ! models . UnitTypeWiki . UnitGlobalDisabled ( ) {
deleteUnitTypes = append ( deleteUnitTypes , models . UnitTypeWiki )
}
}
}
if opts . HasPullRequests == nil {
// If HasPullRequest setting not touched, rewrite existing repo unit
if unit , err := repo . GetUnit ( models . UnitTypePullRequests ) ; err == nil {
units = append ( units , * unit )
}
} else if * opts . HasPullRequests {
// We do allow setting individual PR settings through the API, so
// we get the config settings and then set them
// if those settings were provided in the opts.
unit , err := repo . GetUnit ( models . UnitTypePullRequests )
var config * models . PullRequestsConfig
if err != nil {
// Unit type doesn't exist so we make a new config file with default values
config = & models . PullRequestsConfig {
IgnoreWhitespaceConflicts : false ,
AllowMerge : true ,
AllowRebase : true ,
AllowRebaseMerge : true ,
AllowSquash : true ,
if opts . HasPullRequests != nil {
if * opts . HasPullRequests && ! models . UnitTypePullRequests . UnitGlobalDisabled ( ) {
// We do allow setting individual PR settings through the API, so
// we get the config settings and then set them
// if those settings were provided in the opts.
unit , err := repo . GetUnit ( models . UnitTypePullRequests )
var config * models . PullRequestsConfig
if err != nil {
// Unit type doesn't exist so we make a new config file with default values
config = & models . PullRequestsConfig {
IgnoreWhitespaceConflicts : false ,
AllowMerge : true ,
AllowRebase : true ,
AllowRebaseMerge : true ,
AllowSquash : true ,
}
} else {
config = unit . PullRequestsConfig ( )
}
} else {
config = unit . PullRequestsConfig ( )
}
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
}
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
}
units = append ( units , models . RepoUnit {
RepoID : repo . ID ,
Type : models . UnitTypePullRequests ,
Config : config ,
} )
units = append ( units , models . RepoUnit {
RepoID : repo . ID ,
Type : models . UnitTypePullRequests ,
Config : config ,
} )
} else if ! * opts . HasPullRequests && ! models . UnitTypePullRequests . UnitGlobalDisabled ( ) {
deleteUnitTypes = append ( deleteUnitTypes , models . UnitTypePullRequests )
}
}
if err := models . UpdateRepositoryUnits ( repo , units ) ; err != nil {
if err := models . UpdateRepositoryUnits ( repo , units , deleteUnitTypes ) ; err != nil {
ctx . Error ( http . StatusInternalServerError , "UpdateRepositoryUnits" , err )
return err
}