Skip to content

Commit 8cd3237

Browse files
jolheiserwxiaoguang6543
authored
Better repo API unit checks (#21130)
This PR would presumably Fix #20522 Fix #18773 Fix #19069 Fix #21077 Fix #13622 ----- 1. Check whether unit type is currently enabled 2. Check if it _will_ be enabled via opt 3. Allow modification as necessary Signed-off-by: jolheiser <[email protected]> Co-authored-by: wxiaoguang <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent 904b324 commit 8cd3237

File tree

4 files changed

+45
-31
lines changed

4 files changed

+45
-31
lines changed

modules/structs/repo.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -151,39 +151,39 @@ type EditRepoOption struct {
151151
Template *bool `json:"template,omitempty"`
152152
// either `true` to enable issues for this repository or `false` to disable them.
153153
HasIssues *bool `json:"has_issues,omitempty"`
154-
// set this structure to configure internal issue tracker (requires has_issues)
154+
// set this structure to configure internal issue tracker
155155
InternalTracker *InternalTracker `json:"internal_tracker,omitempty"`
156-
// set this structure to use external issue tracker (requires has_issues)
156+
// set this structure to use external issue tracker
157157
ExternalTracker *ExternalTracker `json:"external_tracker,omitempty"`
158158
// either `true` to enable the wiki for this repository or `false` to disable it.
159159
HasWiki *bool `json:"has_wiki,omitempty"`
160-
// set this structure to use external wiki instead of internal (requires has_wiki)
160+
// set this structure to use external wiki instead of internal
161161
ExternalWiki *ExternalWiki `json:"external_wiki,omitempty"`
162162
// sets the default branch for this repository.
163163
DefaultBranch *string `json:"default_branch,omitempty"`
164164
// either `true` to allow pull requests, or `false` to prevent pull request.
165165
HasPullRequests *bool `json:"has_pull_requests,omitempty"`
166166
// either `true` to enable project unit, or `false` to disable them.
167167
HasProjects *bool `json:"has_projects,omitempty"`
168-
// either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace. `has_pull_requests` must be `true`.
168+
// either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace.
169169
IgnoreWhitespaceConflicts *bool `json:"ignore_whitespace_conflicts,omitempty"`
170-
// either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits. `has_pull_requests` must be `true`.
170+
// either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits.
171171
AllowMerge *bool `json:"allow_merge_commits,omitempty"`
172-
// either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging. `has_pull_requests` must be `true`.
172+
// either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging.
173173
AllowRebase *bool `json:"allow_rebase,omitempty"`
174-
// either `true` to allow rebase with explicit merge commits (--no-ff), or `false` to prevent rebase with explicit merge commits. `has_pull_requests` must be `true`.
174+
// either `true` to allow rebase with explicit merge commits (--no-ff), or `false` to prevent rebase with explicit merge commits.
175175
AllowRebaseMerge *bool `json:"allow_rebase_explicit,omitempty"`
176-
// either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging. `has_pull_requests` must be `true`.
176+
// either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging.
177177
AllowSquash *bool `json:"allow_squash_merge,omitempty"`
178-
// either `true` to allow mark pr as merged manually, or `false` to prevent it. `has_pull_requests` must be `true`.
178+
// either `true` to allow mark pr as merged manually, or `false` to prevent it.
179179
AllowManualMerge *bool `json:"allow_manual_merge,omitempty"`
180-
// either `true` to enable AutodetectManualMerge, or `false` to prevent it. `has_pull_requests` must be `true`, Note: In some special cases, misjudgments can occur.
180+
// either `true` to enable AutodetectManualMerge, or `false` to prevent it. Note: In some special cases, misjudgments can occur.
181181
AutodetectManualMerge *bool `json:"autodetect_manual_merge,omitempty"`
182-
// either `true` to allow updating pull request branch by rebase, or `false` to prevent it. `has_pull_requests` must be `true`.
182+
// either `true` to allow updating pull request branch by rebase, or `false` to prevent it.
183183
AllowRebaseUpdate *bool `json:"allow_rebase_update,omitempty"`
184184
// set to `true` to delete pr branch after merge by default
185185
DefaultDeleteBranchAfterMerge *bool `json:"default_delete_branch_after_merge,omitempty"`
186-
// set to a merge style to be used by this repository: "merge", "rebase", "rebase-merge", or "squash". `has_pull_requests` must be `true`.
186+
// set to a merge style to be used by this repository: "merge", "rebase", "rebase-merge", or "squash".
187187
DefaultMergeStyle *string `json:"default_merge_style,omitempty"`
188188
// set to `true` to archive this repository.
189189
Archived *bool `json:"archived,omitempty"`

routers/api/v1/repo/repo.go

+23-8
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,13 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
732732
var units []repo_model.RepoUnit
733733
var deleteUnitTypes []unit_model.Type
734734

735+
currHasIssues := repo.UnitEnabledCtx(ctx, unit_model.TypeIssues)
736+
newHasIssues := currHasIssues
735737
if opts.HasIssues != nil {
736-
if *opts.HasIssues && opts.ExternalTracker != nil && !unit_model.TypeExternalTracker.UnitGlobalDisabled() {
738+
newHasIssues = *opts.HasIssues
739+
}
740+
if currHasIssues || newHasIssues {
741+
if newHasIssues && opts.ExternalTracker != nil && !unit_model.TypeExternalTracker.UnitGlobalDisabled() {
737742
// Check that values are valid
738743
if !validation.IsValidExternalURL(opts.ExternalTracker.ExternalTrackerURL) {
739744
err := fmt.Errorf("External tracker URL not valid")
@@ -756,7 +761,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
756761
},
757762
})
758763
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeIssues)
759-
} else if *opts.HasIssues && opts.ExternalTracker == nil && !unit_model.TypeIssues.UnitGlobalDisabled() {
764+
} else if newHasIssues && opts.ExternalTracker == nil && !unit_model.TypeIssues.UnitGlobalDisabled() {
760765
// Default to built-in tracker
761766
var config *repo_model.IssuesConfig
762767

@@ -783,7 +788,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
783788
Config: config,
784789
})
785790
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalTracker)
786-
} else if !*opts.HasIssues {
791+
} else if !newHasIssues {
787792
if !unit_model.TypeExternalTracker.UnitGlobalDisabled() {
788793
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalTracker)
789794
}
@@ -793,8 +798,13 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
793798
}
794799
}
795800

801+
currHasWiki := repo.UnitEnabledCtx(ctx, unit_model.TypeWiki)
802+
newHasWiki := currHasWiki
796803
if opts.HasWiki != nil {
797-
if *opts.HasWiki && opts.ExternalWiki != nil && !unit_model.TypeExternalWiki.UnitGlobalDisabled() {
804+
newHasWiki = *opts.HasWiki
805+
}
806+
if currHasWiki || newHasWiki {
807+
if newHasWiki && opts.ExternalWiki != nil && !unit_model.TypeExternalWiki.UnitGlobalDisabled() {
798808
// Check that values are valid
799809
if !validation.IsValidExternalURL(opts.ExternalWiki.ExternalWikiURL) {
800810
err := fmt.Errorf("External wiki URL not valid")
@@ -810,15 +820,15 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
810820
},
811821
})
812822
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeWiki)
813-
} else if *opts.HasWiki && opts.ExternalWiki == nil && !unit_model.TypeWiki.UnitGlobalDisabled() {
823+
} else if newHasWiki && opts.ExternalWiki == nil && !unit_model.TypeWiki.UnitGlobalDisabled() {
814824
config := &repo_model.UnitConfig{}
815825
units = append(units, repo_model.RepoUnit{
816826
RepoID: repo.ID,
817827
Type: unit_model.TypeWiki,
818828
Config: config,
819829
})
820830
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalWiki)
821-
} else if !*opts.HasWiki {
831+
} else if !newHasWiki {
822832
if !unit_model.TypeExternalWiki.UnitGlobalDisabled() {
823833
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalWiki)
824834
}
@@ -828,8 +838,13 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
828838
}
829839
}
830840

841+
currHasPullRequests := repo.UnitEnabledCtx(ctx, unit_model.TypePullRequests)
842+
newHasPullRequests := currHasPullRequests
831843
if opts.HasPullRequests != nil {
832-
if *opts.HasPullRequests && !unit_model.TypePullRequests.UnitGlobalDisabled() {
844+
newHasPullRequests = *opts.HasPullRequests
845+
}
846+
if currHasPullRequests || newHasPullRequests {
847+
if newHasPullRequests && !unit_model.TypePullRequests.UnitGlobalDisabled() {
833848
// We do allow setting individual PR settings through the API, so
834849
// we get the config settings and then set them
835850
// if those settings were provided in the opts.
@@ -889,7 +904,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
889904
Type: unit_model.TypePullRequests,
890905
Config: config,
891906
})
892-
} else if !*opts.HasPullRequests && !unit_model.TypePullRequests.UnitGlobalDisabled() {
907+
} else if !newHasPullRequests && !unit_model.TypePullRequests.UnitGlobalDisabled() {
893908
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePullRequests)
894909
}
895910
}

templates/swagger/v1_json.tmpl

+9-9
Original file line numberDiff line numberDiff line change
@@ -15569,32 +15569,32 @@
1556915569
"type": "object",
1557015570
"properties": {
1557115571
"allow_manual_merge": {
15572-
"description": "either `true` to allow mark pr as merged manually, or `false` to prevent it. `has_pull_requests` must be `true`.",
15572+
"description": "either `true` to allow mark pr as merged manually, or `false` to prevent it.",
1557315573
"type": "boolean",
1557415574
"x-go-name": "AllowManualMerge"
1557515575
},
1557615576
"allow_merge_commits": {
15577-
"description": "either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits. `has_pull_requests` must be `true`.",
15577+
"description": "either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits.",
1557815578
"type": "boolean",
1557915579
"x-go-name": "AllowMerge"
1558015580
},
1558115581
"allow_rebase": {
15582-
"description": "either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging. `has_pull_requests` must be `true`.",
15582+
"description": "either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging.",
1558315583
"type": "boolean",
1558415584
"x-go-name": "AllowRebase"
1558515585
},
1558615586
"allow_rebase_explicit": {
15587-
"description": "either `true` to allow rebase with explicit merge commits (--no-ff), or `false` to prevent rebase with explicit merge commits. `has_pull_requests` must be `true`.",
15587+
"description": "either `true` to allow rebase with explicit merge commits (--no-ff), or `false` to prevent rebase with explicit merge commits.",
1558815588
"type": "boolean",
1558915589
"x-go-name": "AllowRebaseMerge"
1559015590
},
1559115591
"allow_rebase_update": {
15592-
"description": "either `true` to allow updating pull request branch by rebase, or `false` to prevent it. `has_pull_requests` must be `true`.",
15592+
"description": "either `true` to allow updating pull request branch by rebase, or `false` to prevent it.",
1559315593
"type": "boolean",
1559415594
"x-go-name": "AllowRebaseUpdate"
1559515595
},
1559615596
"allow_squash_merge": {
15597-
"description": "either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging. `has_pull_requests` must be `true`.",
15597+
"description": "either `true` to allow squash-merging pull requests, or `false` to prevent squash-merging.",
1559815598
"type": "boolean",
1559915599
"x-go-name": "AllowSquash"
1560015600
},
@@ -15604,7 +15604,7 @@
1560415604
"x-go-name": "Archived"
1560515605
},
1560615606
"autodetect_manual_merge": {
15607-
"description": "either `true` to enable AutodetectManualMerge, or `false` to prevent it. `has_pull_requests` must be `true`, Note: In some special cases, misjudgments can occur.",
15607+
"description": "either `true` to enable AutodetectManualMerge, or `false` to prevent it. Note: In some special cases, misjudgments can occur.",
1560815608
"type": "boolean",
1560915609
"x-go-name": "AutodetectManualMerge"
1561015610
},
@@ -15619,7 +15619,7 @@
1561915619
"x-go-name": "DefaultDeleteBranchAfterMerge"
1562015620
},
1562115621
"default_merge_style": {
15622-
"description": "set to a merge style to be used by this repository: \"merge\", \"rebase\", \"rebase-merge\", or \"squash\". `has_pull_requests` must be `true`.",
15622+
"description": "set to a merge style to be used by this repository: \"merge\", \"rebase\", \"rebase-merge\", or \"squash\".",
1562315623
"type": "string",
1562415624
"x-go-name": "DefaultMergeStyle"
1562515625
},
@@ -15660,7 +15660,7 @@
1566015660
"x-go-name": "HasWiki"
1566115661
},
1566215662
"ignore_whitespace_conflicts": {
15663-
"description": "either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace. `has_pull_requests` must be `true`.",
15663+
"description": "either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace.",
1566415664
"type": "boolean",
1566515665
"x-go-name": "IgnoreWhitespaceConflicts"
1566615666
},

tests/e2e/e2e_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ func TestMain(m *testing.M) {
7272
os.Exit(exitVal)
7373
}
7474

75-
// TestE2e should be the only test e2e necessary. It will collect all "*.test.e2e.js"
76-
// files in this directory and build a test for each.
75+
// TestE2e should be the only test e2e necessary. It will collect all "*.test.e2e.js" files in this directory and build a test for each.
7776
func TestE2e(t *testing.T) {
7877
// Find the paths of all e2e test files in test test directory.
7978
searchGlob := filepath.Join(filepath.Dir(setting.AppPath), "tests", "e2e", "*.test.e2e.js")

0 commit comments

Comments
 (0)