Skip to content

Commit a9ad2dc

Browse files
jpraetnoerwsilverwind
authored andcommitted
Add links to toggle WIP status (go-gitea#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 <noerw@users.noreply.github.com> Co-authored-by: silverwind <me@silverwind.io>
1 parent ac6ce36 commit a9ad2dc

File tree

6 files changed

+59
-25
lines changed

6 files changed

+59
-25
lines changed

Diff for: integrations/pull_merge_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,8 @@ func TestCantMergeWorkInProgress(t *testing.T) {
197197
text := strings.TrimSpace(htmlDoc.doc.Find(".merge-section > .item").Last().Text())
198198
assert.NotEmpty(t, text, "Can't find WIP text")
199199

200-
// remove <strong /> from lang
201-
expected := i18n.Tr("en", "repo.pulls.cannot_merge_work_in_progress", "[wip]")
202-
replacer := strings.NewReplacer("<strong>", "", "</strong>", "")
203-
assert.Equal(t, replacer.Replace(expected), text, "Unable to find WIP text")
200+
assert.Contains(t, text, i18n.Tr("en", "repo.pulls.cannot_merge_work_in_progress"), "Unable to find WIP text")
201+
assert.Contains(t, text, "[wip]", "Unable to find WIP text")
204202
})
205203
}
206204

Diff for: options/locale/locale_en-US.ini

+4-1
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,10 @@ pulls.manually_merged_as = The pull request has been manually merged as <a rel="
13161316
pulls.is_closed = The pull request has been closed.
13171317
pulls.has_merged = The pull request has been merged.
13181318
pulls.title_wip_desc = `<a href="#">Start the title with <strong>%s</strong></a> to prevent the pull request from being merged accidentally.`
1319-
pulls.cannot_merge_work_in_progress = This pull request is marked as a work in progress. Remove the <strong>%s</strong> prefix from the title when it's ready
1319+
pulls.cannot_merge_work_in_progress = This pull request is marked as a work in progress.
1320+
pulls.still_in_progress = Still in progress?
1321+
pulls.add_prefix = Add <strong>%s</strong> prefix
1322+
pulls.remove_prefix = Remove <strong>%s</strong> prefix
13201323
pulls.data_broken = This pull request is broken due to missing fork information.
13211324
pulls.files_conflicted = This pull request has changes conflicting with the target branch.
13221325
pulls.is_checking = "Merge conflict checking is in progress. Try again in few moments."

Diff for: routers/repo/pull.go

+2
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,8 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
519519
return nil
520520
}
521521

522+
ctx.Data["PullRequestWorkInProgressPrefixes"] = setting.Repository.PullRequest.WorkInProgressPrefixes
523+
522524
if pull.IsWorkInProgress() {
523525
ctx.Data["IsPullWorkInProgress"] = true
524526
ctx.Data["WorkInProgressPrefix"] = pull.GetWorkInProgressPrefix()

Diff for: templates/repo/issue/view_content/pull.tmpl

+33-20
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
{{avatar .User}}
1414
</a>
1515
{{end}}
16-
<span class="text grey">
16+
<span>
1717
{{if .User}}
1818
<a href="{{.User.HomeLink}}">{{.User.GetDisplayName}}</a>
1919
{{else if .Team}}
@@ -39,7 +39,7 @@
3939
</span>
4040
{{end}}
4141
{{if (and $.Permission.IsAdmin (or (eq .Review.Type 1) (eq .Review.Type 3)) (not $.Issue.IsClosed))}}
42-
<a href="#" class="ui grey poping up icon dismiss-review-btn" data-review-id="dismiss-review-{{.Review.ID}}" data-content="{{$.i18n.Tr "repo.issues.dismiss_review"}}">
42+
<a href="#" class="ui muted poping up icon dismiss-review-btn" data-review-id="dismiss-review-{{.Review.ID}}" data-content="{{$.i18n.Tr "repo.issues.dismiss_review"}}">
4343
{{svg "octicon-x" 16}}
4444
</a>
4545
<div class="ui small modal" id="dismiss-review-modal">
@@ -172,17 +172,26 @@
172172
{{$.i18n.Tr "repo.pulls.data_broken"}}
173173
</div>
174174
{{else if .IsPullWorkInProgress}}
175-
<div class="item">
176-
<i class="icon icon-octicon">{{svg "octicon-x"}}</i>
177-
{{$.i18n.Tr "repo.pulls.cannot_merge_work_in_progress" (.WorkInProgressPrefix|Escape) | Str2html}}
175+
<div class="item toggle-wip df ac sb" data-title="{{.Issue.Title}}" data-wip-prefix="{{(.WorkInProgressPrefix|Escape)}}" data-update-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/title">
176+
<div>
177+
<i class="icon icon-octicon">{{svg "octicon-x"}}</i>
178+
{{$.i18n.Tr "repo.pulls.cannot_merge_work_in_progress" }}
179+
</div>
180+
<div>
181+
{{if or .HasIssuesOrPullsWritePermission .IsIssuePoster}}
182+
<button class="ui compact button">
183+
{{$.i18n.Tr "repo.pulls.remove_prefix" (.WorkInProgressPrefix|Escape) | Safe}}
184+
</button>
185+
{{end}}
186+
</div>
178187
</div>
179188
{{else if .Issue.PullRequest.IsChecking}}
180189
<div class="item">
181190
<i class="icon icon-octicon">{{svg "octicon-sync"}}</i>
182191
{{$.i18n.Tr "repo.pulls.is_checking"}}
183192
</div>
184193
{{else if .Issue.PullRequest.IsEmpty}}
185-
<div class="item text grey">
194+
<div class="item">
186195
<i class="icon icon-octicon">{{svg "octicon-alert" 16}}</i>
187196
{{$.i18n.Tr "repo.pulls.is_empty"}}
188197
</div>
@@ -443,14 +452,14 @@
443452
{{svg "octicon-x"}}
444453
{{$.i18n.Tr "repo.pulls.no_merge_desc"}}
445454
</div>
446-
<div class="item text grey">
455+
<div class="item">
447456
{{svg "octicon-info"}}
448457
{{$.i18n.Tr "repo.pulls.no_merge_helper"}}
449458
</div>
450459
{{end}}
451460
{{else}}
452461
<div class="ui divider"></div>
453-
<div class="item text grey">
462+
<div class="item">
454463
{{svg "octicon-info"}}
455464
{{$.i18n.Tr "repo.pulls.no_merge_access"}}
456465
</div>
@@ -503,25 +512,29 @@
503512
{{svg "octicon-x"}}
504513
{{$.i18n.Tr "repo.pulls.cannot_auto_merge_desc"}}
505514
</div>
506-
<div class="item text grey">
515+
<div class="item">
507516
{{svg "octicon-info"}}
508517
{{$.i18n.Tr "repo.pulls.cannot_auto_merge_helper"}}
509518
</div>
510519
{{end}}
511520
{{end}}
512521

513522
{{if and (gt .Issue.PullRequest.CommitsBehind 0) (not .Issue.IsClosed) (not .Issue.PullRequest.IsChecking) (not .IsPullFilesConflicted) (not .IsPullRequestBroken) (not $canAutoMerge)}}
514-
<div class="item text grey">
515-
<i class="icon icon-octicon">{{svg "octicon-alert"}}</i>
516-
{{$.i18n.Tr "repo.pulls.outdated_with_base_branch"}}
517-
{{if .UpdateAllowed}}
518-
<form action="{{.Link}}/update" method="post" class="ui floating right">
519-
{{.CsrfTokenHtml}}
520-
<button class="ui compact button" data-do="update">
521-
<span class="ui text">{{$.i18n.Tr "repo.pulls.update_branch"}}</span>
522-
</button>
523-
</form>
524-
{{end}}
523+
<div class="item df ac sb">
524+
<div>
525+
<i class="icon icon-octicon">{{svg "octicon-alert"}}</i>
526+
{{$.i18n.Tr "repo.pulls.outdated_with_base_branch"}}
527+
</div>
528+
<div>
529+
{{if .UpdateAllowed}}
530+
<form action="{{.Link}}/update" method="post">
531+
{{.CsrfTokenHtml}}
532+
<button class="ui compact button" data-do="update">
533+
<span class="ui text">{{$.i18n.Tr "repo.pulls.update_branch"}}</span>
534+
</button>
535+
</form>
536+
{{end}}
537+
</div>
525538
</div>
526539
{{end}}
527540

Diff for: templates/repo/issue/view_content/sidebar.tmpl

+7
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@
9191
{{end}}
9292
</div>
9393
</div>
94+
{{if and (or .HasIssuesOrPullsWritePermission .IsIssuePoster) (not .HasMerged) (not .Issue.IsClosed) (not .IsPullWorkInProgress)}}
95+
<div class="toggle-wip" data-title="{{.Issue.Title}}" data-wip-prefix="{{(index .PullRequestWorkInProgressPrefixes 0| Escape)}}" data-update-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/title">
96+
<a class="muted">
97+
{{.i18n.Tr "repo.pulls.still_in_progress"}} {{.i18n.Tr "repo.pulls.add_prefix" (index .PullRequestWorkInProgressPrefixes 0| Escape) | Safe}}
98+
</a>
99+
</div>
100+
{{end}}
94101
<div class="ui divider"></div>
95102
{{end}}
96103

Diff for: web_src/js/index.js

+11
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,17 @@ async function initRepository() {
909909
return false;
910910
});
911911

912+
// Toggle WIP
913+
$('.toggle-wip a, .toggle-wip button').on('click', async (e) => {
914+
e.preventDefault();
915+
const {title, wipPrefix, updateUrl} = e.currentTarget.closest('.toggle-wip').dataset;
916+
await $.post(updateUrl, {
917+
_csrf: csrf,
918+
title: title?.startsWith(wipPrefix) ? title.substr(wipPrefix.length).trim() : `${wipPrefix.trim()} ${title}`,
919+
});
920+
reload();
921+
});
922+
912923
// Issue Comments
913924
initIssueComments();
914925

0 commit comments

Comments
 (0)