diff --git a/models/repo/repo_unit.go b/models/repo/repo_unit.go index 5a841f4d31..291bf3772b 100644 --- a/models/repo/repo_unit.go +++ b/models/repo/repo_unit.go @@ -118,6 +118,7 @@ func (cfg *IssuesConfig) ToDB() ([]byte, error) { // PullRequestsConfig describes pull requests config type PullRequestsConfig struct { IgnoreWhitespaceConflicts bool + ShowDependencies bool AllowMerge bool AllowRebase bool AllowRebaseMerge bool diff --git a/modules/structs/repo.go b/modules/structs/repo.go index bc8eb0b756..6b4b133e49 100644 --- a/modules/structs/repo.go +++ b/modules/structs/repo.go @@ -95,6 +95,7 @@ type Repository struct { HasPackages bool `json:"has_packages"` HasActions bool `json:"has_actions"` IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"` + ShowDependencies bool `json:"show_dependencies"` AllowMerge bool `json:"allow_merge_commits"` AllowRebase bool `json:"allow_rebase"` AllowRebaseMerge bool `json:"allow_rebase_explicit"` @@ -191,6 +192,8 @@ type EditRepoOption struct { HasActions *bool `json:"has_actions,omitempty"` // either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace. IgnoreWhitespaceConflicts *bool `json:"ignore_whitespace_conflicts,omitempty"` + // either `true` to show `depends on` and `blocks` in Pull Request list, or `false` to not show them. + ShowDependencies *bool `json:"show_dependencies,omitempty"` // either `true` to allow merging pull requests with a merge commit, or `false` to prevent merging pull requests with merge commits. AllowMerge *bool `json:"allow_merge_commits,omitempty"` // either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging. diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 6543e85831..7e2b6ad379 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2121,6 +2121,7 @@ settings.enable_timetracker = Enable Time Tracking settings.allow_only_contributors_to_track_time = Let Only Contributors Track Time settings.pulls_desc = Enable Repository Pull Requests settings.pulls.ignore_whitespace = Ignore Whitespace for Conflicts +settings.pulls.show_dependencies = Show depends on and blocks in Pull Requests list settings.pulls.enable_autodetect_manual_merge = Enable autodetect manual merge (Note: In some special cases, misjudgments can occur) settings.pulls.allow_rebase_update = Enable updating pull request branch by rebase settings.pulls.default_delete_branch_after_merge = Delete pull request branch after merge by default diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 80504b9c33..af47f69958 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -881,6 +881,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error { // Unit type doesn't exist so we make a new config file with default values config = &repo_model.PullRequestsConfig{ IgnoreWhitespaceConflicts: false, + ShowDependencies: false, AllowMerge: true, AllowRebase: true, AllowRebaseMerge: true, @@ -900,6 +901,9 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error { if opts.IgnoreWhitespaceConflicts != nil { config.IgnoreWhitespaceConflicts = *opts.IgnoreWhitespaceConflicts } + if opts.ShowDependencies != nil { + config.ShowDependencies = *opts.ShowDependencies + } if opts.AllowMerge != nil { config.AllowMerge = *opts.AllowMerge } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 0741af452e..5e36661753 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -344,25 +344,32 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt return } - blockingDependenciesTemplates := make(map[int64]template.HTML, len(issues)) - blockedByDependenciesTemplates := make(map[int64]template.HTML, len(issues)) + if unit, err := repo.GetUnit(ctx, unit.TypePullRequests); err == nil { + if config := unit.PullRequestsConfig(); config.ShowDependencies { + blockingDependenciesTemplates := make(map[int64]template.HTML, len(issues)) + blockedByDependenciesTemplates := make(map[int64]template.HTML, len(issues)) - blockingDependenciesMap, err := issues.BlockingDependenciesMap(ctx) - if err != nil { - ctx.ServerError("BlockingDependenciesMap", err) - return - } - for i, blockingDependencies := range blockingDependenciesMap { - blockingDependenciesTemplates[i] = dependenciesToHTML(ctx, blockingDependencies) - } + blockingDependenciesMap, err := issues.BlockingDependenciesMap(ctx) + if err != nil { + ctx.ServerError("BlockingDependenciesMap", err) + return + } + for i, blockingDependencies := range blockingDependenciesMap { + blockingDependenciesTemplates[i] = dependenciesToHTML(ctx, blockingDependencies) + } - blockedByDependenciesMap, err := issues.BlockedByDependenciesMap(ctx) - if err != nil { - ctx.ServerError("BlockedByDependenciesMap", err) - return - } - for i, blockedByDependencies := range blockedByDependenciesMap { - blockedByDependenciesTemplates[i] = dependenciesToHTML(ctx, blockedByDependencies) + blockedByDependenciesMap, err := issues.BlockedByDependenciesMap(ctx) + if err != nil { + ctx.ServerError("BlockedByDependenciesMap", err) + return + } + for i, blockedByDependencies := range blockedByDependenciesMap { + blockedByDependenciesTemplates[i] = dependenciesToHTML(ctx, blockedByDependencies) + } + + ctx.Data["BlockingDependenciesTemplates"] = blockingDependenciesTemplates + ctx.Data["BlockedByDependenciesTemplates"] = blockedByDependenciesTemplates + } } // Get posters. @@ -375,8 +382,6 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt return } } - ctx.Data["BlockingDependenciesTemplates"] = blockingDependenciesTemplates - ctx.Data["BlockedByDependenciesTemplates"] = blockedByDependenciesTemplates commitStatuses, lastStatus, err := pull_service.GetIssuesAllCommitStatus(ctx, issues) if err != nil { diff --git a/routers/web/repo/setting/setting.go b/routers/web/repo/setting/setting.go index e045e3b8dc..23f2acc799 100644 --- a/routers/web/repo/setting/setting.go +++ b/routers/web/repo/setting/setting.go @@ -582,6 +582,7 @@ func SettingsPost(ctx *context.Context) { Type: unit_model.TypePullRequests, Config: &repo_model.PullRequestsConfig{ IgnoreWhitespaceConflicts: form.PullsIgnoreWhitespace, + ShowDependencies: form.PullsShowDependencies, AllowMerge: form.PullsAllowMerge, AllowRebase: form.PullsAllowRebase, AllowRebaseMerge: form.PullsAllowRebaseMerge, diff --git a/services/convert/repository.go b/services/convert/repository.go index 39efd304a9..622538ecd5 100644 --- a/services/convert/repository.go +++ b/services/convert/repository.go @@ -89,6 +89,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, permissionInR } hasPullRequests := false ignoreWhitespaceConflicts := false + showDependencies := false allowMerge := false allowRebase := false allowRebaseMerge := false @@ -102,6 +103,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, permissionInR config := unit.PullRequestsConfig() hasPullRequests = true ignoreWhitespaceConflicts = config.IgnoreWhitespaceConflicts + showDependencies = config.ShowDependencies allowMerge = config.AllowMerge allowRebase = config.AllowRebase allowRebaseMerge = config.AllowRebaseMerge @@ -221,6 +223,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, permissionInR ExternalWiki: externalWiki, HasPullRequests: hasPullRequests, IgnoreWhitespaceConflicts: ignoreWhitespaceConflicts, + ShowDependencies: showDependencies, AllowMerge: allowMerge, AllowRebase: allowRebase, AllowRebaseMerge: allowRebaseMerge, diff --git a/services/forms/repo_form.go b/services/forms/repo_form.go index e45a2a1695..fd8497ff72 100644 --- a/services/forms/repo_form.go +++ b/services/forms/repo_form.go @@ -149,6 +149,7 @@ type RepoSettingForm struct { EnablePulls bool EnableActions bool PullsIgnoreWhitespace bool + PullsShowDependencies bool PullsAllowMerge bool PullsAllowRebase bool PullsAllowRebaseMerge bool diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index a699396a84..9bd893261c 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -645,6 +645,12 @@ +
+
+ + +
+
{{end}} diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl index d4135846d7..e8286d2f3e 100644 --- a/templates/shared/issuelist.tmpl +++ b/templates/shared/issuelist.tmpl @@ -118,12 +118,16 @@ {{end}} - {{template "shared/issue_dependency" (dict - "Dependencies" (index $.BlockedByDependenciesTemplates .ID) - "TitleKey" "repo.issues.dependency.blocked_by_following")}} - {{template "shared/issue_dependency" (dict - "Dependencies" (index $.BlockingDependenciesTemplates .ID) - "TitleKey" "repo.issues.dependency.blocks_following")}} + {{if $.BlockedByDependenciesTemplates}} + {{template "shared/issue_dependency" (dict + "Dependencies" (index $.BlockedByDependenciesTemplates .ID) + "TitleKey" "repo.issues.dependency.blocked_by_following")}} + {{end}} + {{if $.BlockingDependenciesTemplates}} + {{template "shared/issue_dependency" (dict + "Dependencies" (index $.BlockingDependenciesTemplates .ID) + "TitleKey" "repo.issues.dependency.blocks_following")}} + {{end}} {{if .IsPull}} {{$approveOfficial := call $approvalCounts .ID "approve"}} {{$rejectOfficial := call $approvalCounts .ID "reject"}} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 98198696bc..963d0368c9 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -19834,6 +19834,11 @@ "type": "boolean", "x-go-name": "IgnoreWhitespaceConflicts" }, + "show_dependencies": { + "description": "either `true` to show `depends on` and `blocks` in Pull Request list, or `false` to not show them.", + "type": "boolean", + "x-go-name": "ShowDependencies" + }, "internal_tracker": { "$ref": "#/definitions/InternalTracker" }, @@ -22707,6 +22712,10 @@ "type": "boolean", "x-go-name": "IgnoreWhitespaceConflicts" }, + "show_dependencies": { + "type": "boolean", + "x-go-name": "ShowDependencies" + }, "internal": { "type": "boolean", "x-go-name": "Internal"