From c9480c5f606e1e83f8f9c373052c0ba758bf300b Mon Sep 17 00:00:00 2001 From: Jimmy Praet Date: Thu, 27 May 2021 22:02:04 +0200 Subject: [PATCH] Add links to toggle WIP status (#14677) * Add links to toggle PR WIP status * Allow PR author to toggle WIP status * refactors and restyling, remove links from translations Co-authored-by: Norwin Co-authored-by: silverwind --- integrations/pull_merge_test.go | 6 +-- options/locale/locale_en-US.ini | 5 +- routers/repo/pull.go | 2 + templates/repo/issue/view_content/pull.tmpl | 53 ++++++++++++------- .../repo/issue/view_content/sidebar.tmpl | 7 +++ web_src/js/index.js | 11 ++++ 6 files changed, 59 insertions(+), 25 deletions(-) diff --git a/integrations/pull_merge_test.go b/integrations/pull_merge_test.go index 79f62c32c1..b4a3397a45 100644 --- a/integrations/pull_merge_test.go +++ b/integrations/pull_merge_test.go @@ -197,10 +197,8 @@ func TestCantMergeWorkInProgress(t *testing.T) { text := strings.TrimSpace(htmlDoc.doc.Find(".merge-section > .item").Last().Text()) assert.NotEmpty(t, text, "Can't find WIP text") - // remove from lang - expected := i18n.Tr("en", "repo.pulls.cannot_merge_work_in_progress", "[wip]") - replacer := strings.NewReplacer("", "", "", "") - assert.Equal(t, replacer.Replace(expected), text, "Unable to find WIP text") + assert.Contains(t, text, i18n.Tr("en", "repo.pulls.cannot_merge_work_in_progress"), "Unable to find WIP text") + assert.Contains(t, text, "[wip]", "Unable to find WIP text") }) } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index d7d5abce1f..1d39f99425 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1316,7 +1316,10 @@ pulls.manually_merged_as = The pull request has been manually merged as Start the title with %s to prevent the pull request from being merged accidentally.` -pulls.cannot_merge_work_in_progress = This pull request is marked as a work in progress. Remove the %s prefix from the title when it's ready +pulls.cannot_merge_work_in_progress = This pull request is marked as a work in progress. +pulls.still_in_progress = Still in progress? +pulls.add_prefix = Add %s prefix +pulls.remove_prefix = Remove %s prefix pulls.data_broken = This pull request is broken due to missing fork information. pulls.files_conflicted = This pull request has changes conflicting with the target branch. pulls.is_checking = "Merge conflict checking is in progress. Try again in few moments." diff --git a/routers/repo/pull.go b/routers/repo/pull.go index e13ad0cc03..bb166c68a6 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -519,6 +519,8 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare return nil } + ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes + if pull.IsWorkInProgress() { ctx.Data["IsPullWorkInProgress"] = true ctx.Data["WorkInProgressPrefix"] = pull.GetWorkInProgressPrefix() diff --git a/templates/repo/issue/view_content/pull.tmpl b/templates/repo/issue/view_content/pull.tmpl index 69462797a2..3bdec4becb 100644 --- a/templates/repo/issue/view_content/pull.tmpl +++ b/templates/repo/issue/view_content/pull.tmpl @@ -13,7 +13,7 @@ {{avatar .User}} {{end}} - + {{if .User}} {{.User.GetDisplayName}} {{else if .Team}} @@ -39,7 +39,7 @@ {{end}} {{if (and $.Permission.IsAdmin (or (eq .Review.Type 1) (eq .Review.Type 3)) (not $.Issue.IsClosed))}} - + {{svg "octicon-x" 16}} {{else if .IsPullWorkInProgress}} -
- {{svg "octicon-x"}} - {{$.i18n.Tr "repo.pulls.cannot_merge_work_in_progress" (.WorkInProgressPrefix|Escape) | Str2html}} +
+
+ {{svg "octicon-x"}} + {{$.i18n.Tr "repo.pulls.cannot_merge_work_in_progress" }} +
+
+ {{if or .HasIssuesOrPullsWritePermission .IsIssuePoster}} + + {{end}} +
{{else if .Issue.PullRequest.IsChecking}}
@@ -182,7 +191,7 @@ {{$.i18n.Tr "repo.pulls.is_checking"}}
{{else if .Issue.PullRequest.IsEmpty}} -
+
{{svg "octicon-alert" 16}} {{$.i18n.Tr "repo.pulls.is_empty"}}
@@ -443,14 +452,14 @@ {{svg "octicon-x"}} {{$.i18n.Tr "repo.pulls.no_merge_desc"}}
-
+
{{svg "octicon-info"}} {{$.i18n.Tr "repo.pulls.no_merge_helper"}}
{{end}} {{else}}
-
+
{{svg "octicon-info"}} {{$.i18n.Tr "repo.pulls.no_merge_access"}}
@@ -503,7 +512,7 @@ {{svg "octicon-x"}} {{$.i18n.Tr "repo.pulls.cannot_auto_merge_desc"}}
-
+
{{svg "octicon-info"}} {{$.i18n.Tr "repo.pulls.cannot_auto_merge_helper"}}
@@ -511,17 +520,21 @@ {{end}} {{if and (gt .Issue.PullRequest.CommitsBehind 0) (not .Issue.IsClosed) (not .Issue.PullRequest.IsChecking) (not .IsPullFilesConflicted) (not .IsPullRequestBroken) (not $canAutoMerge)}} -
- {{svg "octicon-alert"}} - {{$.i18n.Tr "repo.pulls.outdated_with_base_branch"}} - {{if .UpdateAllowed}} -
- {{.CsrfTokenHtml}} - -
- {{end}} +
+
+ {{svg "octicon-alert"}} + {{$.i18n.Tr "repo.pulls.outdated_with_base_branch"}} +
+
+ {{if .UpdateAllowed}} +
+ {{.CsrfTokenHtml}} + +
+ {{end}} +
{{end}} diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index e3530fc45b..2f42957266 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -91,6 +91,13 @@ {{end}}
+ {{if and (or .HasIssuesOrPullsWritePermission .IsIssuePoster) (not .HasMerged) (not .Issue.IsClosed) (not .IsPullWorkInProgress)}} + + {{end}}
{{end}} diff --git a/web_src/js/index.js b/web_src/js/index.js index 5ba2662ea4..9f016ca84a 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -909,6 +909,17 @@ async function initRepository() { return false; }); + // Toggle WIP + $('.toggle-wip a, .toggle-wip button').on('click', async (e) => { + e.preventDefault(); + const {title, wipPrefix, updateUrl} = e.currentTarget.closest('.toggle-wip').dataset; + await $.post(updateUrl, { + _csrf: csrf, + title: title?.startsWith(wipPrefix) ? title.substr(wipPrefix.length).trim() : `${wipPrefix.trim()} ${title}`, + }); + reload(); + }); + // Issue Comments initIssueComments();