Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add links to toggle WIP status #14677

Merged
merged 21 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions integrations/pull_merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <strong /> from lang
expected := i18n.Tr("en", "repo.pulls.cannot_merge_work_in_progress", "[wip]")
replacer := strings.NewReplacer("<strong>", "", "</strong>", "")
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")
})
}

Expand Down
4 changes: 3 additions & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,9 @@ pulls.manually_merged_as = The pull request has been manually merged as <a rel="
pulls.is_closed = The pull request has been closed.
pulls.has_merged = The pull request has been merged.
pulls.title_wip_desc = `<a href="#">Start the title with <strong>%s</strong></a> 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 <strong>%s</strong> 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.remove_wip_prefix = `<a href="#">Remove the <strong>%s</strong> prefix</a> from the title when it's ready`
pulls.add_wip_prefix = `Still in progress? <a href="#">Add <strong>%s</strong> prefix</a>`
jpraet marked this conversation as resolved.
Show resolved Hide resolved
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."
Expand Down
2 changes: 2 additions & 0 deletions routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions templates/repo/issue/view_content/pull.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,12 @@
{{$.i18n.Tr "repo.pulls.data_broken"}}
</div>
{{else if .IsPullWorkInProgress}}
<div class="item">
<div class="item toggle-wip" data-title="{{.Issue.Title}}" data-wip-prefix="{{(.WorkInProgressPrefix|Escape)}}" data-update-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/title">
<i class="icon icon-octicon">{{svg "octicon-x"}}</i>
{{$.i18n.Tr "repo.pulls.cannot_merge_work_in_progress" (.WorkInProgressPrefix|Escape) | Str2html}}
{{$.i18n.Tr "repo.pulls.cannot_merge_work_in_progress" }}
{{if .HasIssuesOrPullsWritePermission}}
{{$.i18n.Tr "repo.pulls.remove_wip_prefix" (.WorkInProgressPrefix|Escape) | Safe}}
{{end}}
</div>
{{else if .Issue.PullRequest.IsChecking}}
<div class="item">
Expand Down
3 changes: 3 additions & 0 deletions templates/repo/issue/view_content/sidebar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
{{end}}
</div>
</div>
{{if and .HasIssuesOrPullsWritePermission (not .HasMerged) (not .Issue.IsClosed) (not .IsPullWorkInProgress)}}
jpraet marked this conversation as resolved.
Show resolved Hide resolved
<div class="toggle-wip" data-title="{{.Issue.Title}}" data-wip-prefix="{{(index .PullRequestWorkInProgressPrefixes 0| Escape)}}" data-update-url="{{$.RepoLink}}/issues/{{.Issue.Index}}/title">{{.i18n.Tr "repo.pulls.add_wip_prefix" (index .PullRequestWorkInProgressPrefixes 0| Escape) | Safe}}</div>
{{end}}
<div class="ui divider"></div>
{{end}}

Expand Down
14 changes: 14 additions & 0 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,20 @@ async function initRepository() {
return false;
});

// Toggle WIP
$('.toggle-wip a').on('click', (e) => {
e.preventDefault();
const $toggle = $(e.target).closest('div');
const title = $toggle.data('title');
const prefix = $toggle.data('wip-prefix');
const newTitle = title.startsWith(prefix) ? title.substr(prefix.length).trim() : `${prefix.trim()} ${title}`;
$.post($toggle.data('update-url'), {
_csrf: csrf,
title: newTitle
}).done(reload);
return false;
});

// Issue Comments
initIssueComments();

Expand Down