Skip to content

Commit 0208ea0

Browse files
saithowxiaoguangsilverwindzeripath
authored
"Copy branch name" button in pull request (#17323)
* Drop data-original from clipboard data-original attribute was removed. Instead, the original value from data-content is set after success/fail message was displayed. Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * "Copy branch name" button in pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update templates/repo/issue/view_title.tmpl Co-authored-by: silverwind <me@silverwind.io> * Apply suggestions from code review Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: zeripath <art27@cantab.net>
1 parent de61816 commit 0208ea0

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

options/locale/locale_en-US.ini

+3
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,9 @@ star_guest_user = Sign in to star this repository.
927927
copy_link = Copy
928928
copy_link_success = Link has been copied
929929
copy_link_error = Use ⌘C or Ctrl-C to copy
930+
copy_branch = Copy
931+
copy_branch_success = Branch name has been copied
932+
copy_branch_error = Use ⌘C or Ctrl-C to copy
930933
copied = Copied OK
931934
unwatch = Unwatch
932935
watch = Watch

templates/repo/clone_buttons.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<input id="repo-clone-url" value="{{if $.PageIsWiki}}{{$.WikiCloneLink.SSH}}{{else}}{{$.CloneLink.SSH}}{{end}}" readonly>
1515
{{end}}
1616
{{if or (not $.DisableHTTP) (and (not $.DisableSSH) (or $.IsSigned $.ExposeAnonSSH))}}
17-
<button class="ui basic icon button poping up" id="clipboard-btn" data-original="{{.i18n.Tr "repo.copy_link"}}" data-success="{{.i18n.Tr "repo.copy_link_success"}}" data-error="{{.i18n.Tr "repo.copy_link_error"}}" data-content="{{.i18n.Tr "repo.copy_link"}}" data-variation="inverted tiny" data-clipboard-target="#repo-clone-url">
17+
<button class="ui basic icon button poping up" id="clipboard-btn" data-success="{{.i18n.Tr "repo.copy_link_success"}}" data-error="{{.i18n.Tr "repo.copy_link_error"}}" data-content="{{.i18n.Tr "repo.copy_link"}}" data-variation="inverted tiny" data-clipboard-target="#repo-clone-url">
1818
{{svg "octicon-paste"}}
1919
</button>
2020
{{end}}

templates/repo/issue/view_title.tmpl

+7-6
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,29 @@
3232
{{if .Issue.IsPull}}
3333
{{$headHref := .HeadTarget|Escape}}
3434
{{if .HeadBranchHTMLURL}}
35-
{{$headHref = printf "<a href=\"%s\">%s</a>" .HeadBranchHTMLURL $headHref}}
35+
{{$headHref = printf "<a href=\"%s\">%s</a>" (.HeadBranchHTMLURL | Escape) $headHref}}
3636
{{end}}
37+
{{$headHref = printf "%s <a class=\"poping up\" data-content=\"%s\" data-success=\"%s\" data-error=\"%s\" data-clipboard-text=\"%s\" data-variation=\"inverted tiny\">%s</a>" $headHref (.i18n.Tr "repo.copy_branch") (.i18n.Tr "repo.copy_branch_success") (.i18n.Tr "repo.copy_branch_error") (.HeadTarget | Escape) (svg "octicon-copy" 14)}}
3738
{{$baseHref := .BaseTarget|Escape}}
3839
{{if .BaseBranchHTMLURL}}
39-
{{$baseHref = printf "<a href=\"%s\">%s</a>" .BaseBranchHTMLURL $baseHref}}
40+
{{$baseHref = printf "<a href=\"%s\">%s</a>" (.BaseBranchHTMLURL | Escape) $baseHref}}
4041
{{end}}
4142
{{if .Issue.PullRequest.HasMerged}}
4243
{{ $mergedStr:= TimeSinceUnix .Issue.PullRequest.MergedUnix $.Lang }}
4344
{{if .Issue.OriginalAuthor }}
4445
{{.Issue.OriginalAuthor}}
45-
<span class="pull-desc">{{$.i18n.Tr "repo.pulls.merged_title_desc" .NumCommits $headHref $baseHref $mergedStr | Str2html}}</span>
46+
<span class="pull-desc">{{$.i18n.Tr "repo.pulls.merged_title_desc" .NumCommits $headHref $baseHref $mergedStr | Safe}}</span>
4647
{{else}}
4748
<a {{if gt .Issue.PullRequest.Merger.ID 0}}href="{{.Issue.PullRequest.Merger.HomeLink}}"{{end}}>{{.Issue.PullRequest.Merger.GetDisplayName}}</a>
48-
<span class="pull-desc">{{$.i18n.Tr "repo.pulls.merged_title_desc" .NumCommits $headHref $baseHref $mergedStr | Str2html}}</span>
49+
<span class="pull-desc">{{$.i18n.Tr "repo.pulls.merged_title_desc" .NumCommits $headHref $baseHref $mergedStr | Safe}}</span>
4950
{{end}}
5051
{{else}}
5152
{{if .Issue.OriginalAuthor }}
52-
<span id="pull-desc" class="pull-desc">{{.Issue.OriginalAuthor}} {{$.i18n.Tr "repo.pulls.title_desc" .NumCommits $headHref $baseHref | Str2html}}</span>
53+
<span id="pull-desc" class="pull-desc">{{.Issue.OriginalAuthor}} {{$.i18n.Tr "repo.pulls.title_desc" .NumCommits $headHref $baseHref | Safe}}</span>
5354
{{else}}
5455
<span id="pull-desc" class="pull-desc">
5556
<a {{if gt .Issue.Poster.ID 0}}href="{{.Issue.Poster.HomeLink}}"{{end}}>{{.Issue.Poster.GetDisplayName}}</a>
56-
{{$.i18n.Tr "repo.pulls.title_desc" .NumCommits $headHref $baseHref | Str2html}}
57+
{{$.i18n.Tr "repo.pulls.title_desc" .NumCommits $headHref $baseHref | Safe}}
5758
</span>
5859
{{end}}
5960
<span id="pull-desc-edit" style="display: none">

web_src/js/features/clipboard.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
function onSuccess(btn) {
55
if (!btn.dataset.content) return;
66
$(btn).popup('destroy');
7+
const oldContent = btn.dataset.content;
78
btn.dataset.content = btn.dataset.success;
89
$(btn).popup('show');
9-
btn.dataset.content = btn.dataset.original;
10+
btn.dataset.content = oldContent;
1011
}
1112
function onError(btn) {
1213
if (!btn.dataset.content) return;
14+
const oldContent = btn.dataset.content;
1315
$(btn).popup('destroy');
1416
btn.dataset.content = btn.dataset.error;
1517
$(btn).popup('show');
16-
btn.dataset.content = btn.dataset.original;
18+
btn.dataset.content = oldContent;
1719
}
1820

1921
/**

web_src/less/_repository.less

+9
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,15 @@
686686
code {
687687
color: var(--color-primary);
688688
}
689+
a[data-clipboard-text] {
690+
cursor: pointer;
691+
svg {
692+
vertical-align: middle;
693+
position: relative;
694+
top: -2px;
695+
right: 1px;
696+
}
697+
}
689698
}
690699

691700
.pull {

0 commit comments

Comments
 (0)