enhancement: show dependencies only with enabled setting

This commit is contained in:
Tim-Niclas Oelschläger 2024-02-17 17:34:47 +01:00 committed by Lunny Xiao
parent f2ae3bdc01
commit 0df1b3766a
11 changed files with 63 additions and 25 deletions

View File

@ -118,6 +118,7 @@ func (cfg *IssuesConfig) ToDB() ([]byte, error) {
// PullRequestsConfig describes pull requests config // PullRequestsConfig describes pull requests config
type PullRequestsConfig struct { type PullRequestsConfig struct {
IgnoreWhitespaceConflicts bool IgnoreWhitespaceConflicts bool
ShowDependencies bool
AllowMerge bool AllowMerge bool
AllowRebase bool AllowRebase bool
AllowRebaseMerge bool AllowRebaseMerge bool

View File

@ -95,6 +95,7 @@ type Repository struct {
HasPackages bool `json:"has_packages"` HasPackages bool `json:"has_packages"`
HasActions bool `json:"has_actions"` HasActions bool `json:"has_actions"`
IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"` IgnoreWhitespaceConflicts bool `json:"ignore_whitespace_conflicts"`
ShowDependencies bool `json:"show_dependencies"`
AllowMerge bool `json:"allow_merge_commits"` AllowMerge bool `json:"allow_merge_commits"`
AllowRebase bool `json:"allow_rebase"` AllowRebase bool `json:"allow_rebase"`
AllowRebaseMerge bool `json:"allow_rebase_explicit"` AllowRebaseMerge bool `json:"allow_rebase_explicit"`
@ -191,6 +192,8 @@ type EditRepoOption struct {
HasActions *bool `json:"has_actions,omitempty"` HasActions *bool `json:"has_actions,omitempty"`
// either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace. // either `true` to ignore whitespace for conflicts, or `false` to not ignore whitespace.
IgnoreWhitespaceConflicts *bool `json:"ignore_whitespace_conflicts,omitempty"` 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. // 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"` AllowMerge *bool `json:"allow_merge_commits,omitempty"`
// either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging. // either `true` to allow rebase-merging pull requests, or `false` to prevent rebase-merging.

View File

@ -2121,6 +2121,7 @@ settings.enable_timetracker = Enable Time Tracking
settings.allow_only_contributors_to_track_time = Let Only Contributors Track Time settings.allow_only_contributors_to_track_time = Let Only Contributors Track Time
settings.pulls_desc = Enable Repository Pull Requests settings.pulls_desc = Enable Repository Pull Requests
settings.pulls.ignore_whitespace = Ignore Whitespace for Conflicts settings.pulls.ignore_whitespace = Ignore Whitespace for Conflicts
settings.pulls.show_dependencies = Show <b>depends on</b> and <b>blocks</b> in Pull Requests list
settings.pulls.enable_autodetect_manual_merge = Enable autodetect manual merge (Note: In some special cases, misjudgments can occur) 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.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 settings.pulls.default_delete_branch_after_merge = Delete pull request branch after merge by default

View File

@ -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 // Unit type doesn't exist so we make a new config file with default values
config = &repo_model.PullRequestsConfig{ config = &repo_model.PullRequestsConfig{
IgnoreWhitespaceConflicts: false, IgnoreWhitespaceConflicts: false,
ShowDependencies: false,
AllowMerge: true, AllowMerge: true,
AllowRebase: true, AllowRebase: true,
AllowRebaseMerge: true, AllowRebaseMerge: true,
@ -900,6 +901,9 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error {
if opts.IgnoreWhitespaceConflicts != nil { if opts.IgnoreWhitespaceConflicts != nil {
config.IgnoreWhitespaceConflicts = *opts.IgnoreWhitespaceConflicts config.IgnoreWhitespaceConflicts = *opts.IgnoreWhitespaceConflicts
} }
if opts.ShowDependencies != nil {
config.ShowDependencies = *opts.ShowDependencies
}
if opts.AllowMerge != nil { if opts.AllowMerge != nil {
config.AllowMerge = *opts.AllowMerge config.AllowMerge = *opts.AllowMerge
} }

View File

@ -344,25 +344,32 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
return return
} }
blockingDependenciesTemplates := make(map[int64]template.HTML, len(issues)) if unit, err := repo.GetUnit(ctx, unit.TypePullRequests); err == nil {
blockedByDependenciesTemplates := make(map[int64]template.HTML, len(issues)) 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) blockingDependenciesMap, err := issues.BlockingDependenciesMap(ctx)
if err != nil { if err != nil {
ctx.ServerError("BlockingDependenciesMap", err) ctx.ServerError("BlockingDependenciesMap", err)
return return
} }
for i, blockingDependencies := range blockingDependenciesMap { for i, blockingDependencies := range blockingDependenciesMap {
blockingDependenciesTemplates[i] = dependenciesToHTML(ctx, blockingDependencies) blockingDependenciesTemplates[i] = dependenciesToHTML(ctx, blockingDependencies)
} }
blockedByDependenciesMap, err := issues.BlockedByDependenciesMap(ctx) blockedByDependenciesMap, err := issues.BlockedByDependenciesMap(ctx)
if err != nil { if err != nil {
ctx.ServerError("BlockedByDependenciesMap", err) ctx.ServerError("BlockedByDependenciesMap", err)
return return
} }
for i, blockedByDependencies := range blockedByDependenciesMap { for i, blockedByDependencies := range blockedByDependenciesMap {
blockedByDependenciesTemplates[i] = dependenciesToHTML(ctx, blockedByDependencies) blockedByDependenciesTemplates[i] = dependenciesToHTML(ctx, blockedByDependencies)
}
ctx.Data["BlockingDependenciesTemplates"] = blockingDependenciesTemplates
ctx.Data["BlockedByDependenciesTemplates"] = blockedByDependenciesTemplates
}
} }
// Get posters. // Get posters.
@ -375,8 +382,6 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
return return
} }
} }
ctx.Data["BlockingDependenciesTemplates"] = blockingDependenciesTemplates
ctx.Data["BlockedByDependenciesTemplates"] = blockedByDependenciesTemplates
commitStatuses, lastStatus, err := pull_service.GetIssuesAllCommitStatus(ctx, issues) commitStatuses, lastStatus, err := pull_service.GetIssuesAllCommitStatus(ctx, issues)
if err != nil { if err != nil {

View File

@ -582,6 +582,7 @@ func SettingsPost(ctx *context.Context) {
Type: unit_model.TypePullRequests, Type: unit_model.TypePullRequests,
Config: &repo_model.PullRequestsConfig{ Config: &repo_model.PullRequestsConfig{
IgnoreWhitespaceConflicts: form.PullsIgnoreWhitespace, IgnoreWhitespaceConflicts: form.PullsIgnoreWhitespace,
ShowDependencies: form.PullsShowDependencies,
AllowMerge: form.PullsAllowMerge, AllowMerge: form.PullsAllowMerge,
AllowRebase: form.PullsAllowRebase, AllowRebase: form.PullsAllowRebase,
AllowRebaseMerge: form.PullsAllowRebaseMerge, AllowRebaseMerge: form.PullsAllowRebaseMerge,

View File

@ -89,6 +89,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, permissionInR
} }
hasPullRequests := false hasPullRequests := false
ignoreWhitespaceConflicts := false ignoreWhitespaceConflicts := false
showDependencies := false
allowMerge := false allowMerge := false
allowRebase := false allowRebase := false
allowRebaseMerge := false allowRebaseMerge := false
@ -102,6 +103,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, permissionInR
config := unit.PullRequestsConfig() config := unit.PullRequestsConfig()
hasPullRequests = true hasPullRequests = true
ignoreWhitespaceConflicts = config.IgnoreWhitespaceConflicts ignoreWhitespaceConflicts = config.IgnoreWhitespaceConflicts
showDependencies = config.ShowDependencies
allowMerge = config.AllowMerge allowMerge = config.AllowMerge
allowRebase = config.AllowRebase allowRebase = config.AllowRebase
allowRebaseMerge = config.AllowRebaseMerge allowRebaseMerge = config.AllowRebaseMerge
@ -221,6 +223,7 @@ func innerToRepo(ctx context.Context, repo *repo_model.Repository, permissionInR
ExternalWiki: externalWiki, ExternalWiki: externalWiki,
HasPullRequests: hasPullRequests, HasPullRequests: hasPullRequests,
IgnoreWhitespaceConflicts: ignoreWhitespaceConflicts, IgnoreWhitespaceConflicts: ignoreWhitespaceConflicts,
ShowDependencies: showDependencies,
AllowMerge: allowMerge, AllowMerge: allowMerge,
AllowRebase: allowRebase, AllowRebase: allowRebase,
AllowRebaseMerge: allowRebaseMerge, AllowRebaseMerge: allowRebaseMerge,

View File

@ -149,6 +149,7 @@ type RepoSettingForm struct {
EnablePulls bool EnablePulls bool
EnableActions bool EnableActions bool
PullsIgnoreWhitespace bool PullsIgnoreWhitespace bool
PullsShowDependencies bool
PullsAllowMerge bool PullsAllowMerge bool
PullsAllowRebase bool PullsAllowRebase bool
PullsAllowRebaseMerge bool PullsAllowRebaseMerge bool

View File

@ -645,6 +645,12 @@
<label>{{ctx.Locale.Tr "repo.settings.pulls.ignore_whitespace"}}</label> <label>{{ctx.Locale.Tr "repo.settings.pulls.ignore_whitespace"}}</label>
</div> </div>
</div> </div>
<div class="field">
<div class="ui checkbox">
<input name="pulls_show_dependencies" type="checkbox" {{if and $pullRequestEnabled ($prUnit.PullRequestsConfig.ShowDependencies)}}checked{{end}}>
<label>{{ctx.Locale.Tr "repo.settings.pulls.show_dependencies"}}</label>
</div>
</div>
</div> </div>
{{end}} {{end}}

View File

@ -118,12 +118,16 @@
</span> </span>
</span> </span>
{{end}} {{end}}
{{template "shared/issue_dependency" (dict {{if $.BlockedByDependenciesTemplates}}
"Dependencies" (index $.BlockedByDependenciesTemplates .ID) {{template "shared/issue_dependency" (dict
"TitleKey" "repo.issues.dependency.blocked_by_following")}} "Dependencies" (index $.BlockedByDependenciesTemplates .ID)
{{template "shared/issue_dependency" (dict "TitleKey" "repo.issues.dependency.blocked_by_following")}}
"Dependencies" (index $.BlockingDependenciesTemplates .ID) {{end}}
"TitleKey" "repo.issues.dependency.blocks_following")}} {{if $.BlockingDependenciesTemplates}}
{{template "shared/issue_dependency" (dict
"Dependencies" (index $.BlockingDependenciesTemplates .ID)
"TitleKey" "repo.issues.dependency.blocks_following")}}
{{end}}
{{if .IsPull}} {{if .IsPull}}
{{$approveOfficial := call $approvalCounts .ID "approve"}} {{$approveOfficial := call $approvalCounts .ID "approve"}}
{{$rejectOfficial := call $approvalCounts .ID "reject"}} {{$rejectOfficial := call $approvalCounts .ID "reject"}}

View File

@ -19834,6 +19834,11 @@
"type": "boolean", "type": "boolean",
"x-go-name": "IgnoreWhitespaceConflicts" "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": { "internal_tracker": {
"$ref": "#/definitions/InternalTracker" "$ref": "#/definitions/InternalTracker"
}, },
@ -22707,6 +22712,10 @@
"type": "boolean", "type": "boolean",
"x-go-name": "IgnoreWhitespaceConflicts" "x-go-name": "IgnoreWhitespaceConflicts"
}, },
"show_dependencies": {
"type": "boolean",
"x-go-name": "ShowDependencies"
},
"internal": { "internal": {
"type": "boolean", "type": "boolean",
"x-go-name": "Internal" "x-go-name": "Internal"