Allow/fix review (approve/reject) of empty PRs (#25690)

gitea allows to create empty PRs.

Currently when you need approvals for a merge, you have to manually add
/files to the url to get to the files tab to approve / reject the PR.

This PR allows to open the files tab via the normal tab / link and then
fixes the layout of the files tab.

**Screenshots:**

Before:

![image](https://github.com/go-gitea/gitea/assets/1135157/b5082e5e-8c32-4412-993e-b854905e96d3)

After:

![image](https://github.com/go-gitea/gitea/assets/1135157/1f5e056e-396f-4dfb-8d14-e17a2f6495d9)

---------

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
sebastian-sauer 2023-07-06 17:33:04 +02:00 committed by GitHub
parent 5b7b7c4f3c
commit f03d95f0a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 171 additions and 177 deletions

View file

@ -1,20 +1,7 @@
{{if .DiffNotAvailable}} <div>
<div>
<div class="diff-detail-box diff-box sticky">
<div class="ui right">
{{template "repo/diff/whitespace_dropdown" .}}
{{template "repo/diff/options_dropdown" .}}
{{if and .PageIsPullFiles $.SignedUserID (not .IsArchived)}}
{{template "repo/diff/new_review" .}}
{{end}}
</div>
</div>
</div>
<h4>{{.locale.Tr "repo.diff.data_not_available"}}</h4>
{{else}}
<div>
<div class="diff-detail-box diff-box sticky gt-df gt-sb gt-ac gt-fw"> <div class="diff-detail-box diff-box sticky gt-df gt-sb gt-ac gt-fw">
<div class="gt-df gt-ac gt-fw"> <div class="gt-df gt-ac gt-fw">
{{if not .DiffNotAvailable}}
<button class="diff-toggle-file-tree-button gt-df gt-ac not-mobile" data-show-text="{{.locale.Tr "repo.diff.show_file_tree"}}" data-hide-text="{{.locale.Tr "repo.diff.hide_file_tree"}}"> <button class="diff-toggle-file-tree-button gt-df gt-ac not-mobile" data-show-text="{{.locale.Tr "repo.diff.show_file_tree"}}" data-hide-text="{{.locale.Tr "repo.diff.hide_file_tree"}}">
{{/* the icon meaning is reversed here, "octicon-sidebar-collapse" means show the file tree */}} {{/* the icon meaning is reversed here, "octicon-sidebar-collapse" means show the file tree */}}
{{svg "octicon-sidebar-collapse" 20 "icon gt-hidden"}} {{svg "octicon-sidebar-collapse" 20 "icon gt-hidden"}}
@ -31,9 +18,10 @@
<div class="diff-detail-stats gt-df gt-ac gt-fw"> <div class="diff-detail-stats gt-df gt-ac gt-fw">
{{svg "octicon-diff" 16 "gt-mr-2"}}{{.locale.Tr "repo.diff.stats_desc" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion | Str2html}} {{svg "octicon-diff" 16 "gt-mr-2"}}{{.locale.Tr "repo.diff.stats_desc" .Diff.NumFiles .Diff.TotalAddition .Diff.TotalDeletion | Str2html}}
</div> </div>
{{end}}
</div> </div>
<div class="diff-detail-actions gt-df gt-ac gt-gap-2 gt-fw"> <div class="diff-detail-actions gt-df gt-ac gt-gap-2 gt-fw">
{{if and .PageIsPullFiles $.SignedUserID (not .IsArchived)}} {{if and .PageIsPullFiles $.SignedUserID (not .IsArchived) (not .DiffNotAvailable)}}
<div class="gt-df gt-ac gt-fc gt-whitespace-nowrap gt-mr-2"> <div class="gt-df gt-ac gt-fc gt-whitespace-nowrap gt-mr-2">
<label for="viewed-files-summary" id="viewed-files-summary-label" data-text-changed-template="{{.locale.Tr "repo.pulls.viewed_files_label"}}"> <label for="viewed-files-summary" id="viewed-files-summary-label" data-text-changed-template="{{.locale.Tr "repo.pulls.viewed_files_label"}}">
{{.locale.Tr "repo.pulls.viewed_files_label" .Diff.NumViewedFiles .Diff.NumFiles}} {{.locale.Tr "repo.pulls.viewed_files_label" .Diff.NumViewedFiles .Diff.NumFiles}}
@ -48,6 +36,7 @@
{{end}} {{end}}
</div> </div>
</div> </div>
{{if not .DiffNotAvailable}}
<script id="diff-data-script" type="module"> <script id="diff-data-script" type="module">
const diffDataFiles = [{{range $i, $file := .Diff.Files}}{Name:"{{$file.Name}}",NameHash:"{{$file.NameHash}}",Type:{{$file.Type}},IsBin:{{$file.IsBin}},Addition:{{$file.Addition}},Deletion:{{$file.Deletion}},IsViewed:{{$file.IsViewed}}},{{end}}]; const diffDataFiles = [{{range $i, $file := .Diff.Files}}{Name:"{{$file.Name}}",NameHash:"{{$file.NameHash}}",Type:{{$file.Type}},IsBin:{{$file.IsBin}},Addition:{{$file.Addition}},Deletion:{{$file.Deletion}},IsViewed:{{$file.IsViewed}}},{{end}}];
const diffData = { const diffData = {
@ -74,7 +63,11 @@
window.config.pageData.diffFileInfo = diffFileInfo; window.config.pageData.diffFileInfo = diffFileInfo;
</script> </script>
<div id="diff-file-list"></div> <div id="diff-file-list"></div>
{{end}}
<div id="diff-container"> <div id="diff-container">
{{if .DiffNotAvailable}}
<h4>{{.locale.Tr "repo.diff.data_not_available"}}</h4>
{{else}}
<div id="diff-file-tree" class="gt-hidden"></div> <div id="diff-file-tree" class="gt-hidden"></div>
<script> <script>
if (diffTreeVisible) document.getElementById('diff-file-tree').classList.remove('gt-hidden'); if (diffTreeVisible) document.getElementById('diff-file-tree').classList.remove('gt-hidden');
@ -203,9 +196,10 @@
</div> </div>
{{end}} {{end}}
</div> </div>
{{end}}
</div> </div>
{{if not $.Repository.IsArchived}} {{if and (not $.Repository.IsArchived) (not .DiffNotAvailable)}}
<template id="issue-comment-editor-template"> <template id="issue-comment-editor-template">
<div class="ui comment form"> <div class="ui comment form">
{{template "shared/combomarkdowneditor" (dict {{template "shared/combomarkdowneditor" (dict
@ -222,7 +216,7 @@
</div> </div>
</template> </template>
{{end}} {{end}}
{{if (not .DiffNotAvailable)}}
{{template "repo/issue/view_content/reference_issue_dialog" .}} {{template "repo/issue/view_content/reference_issue_dialog" .}}
</div> {{end}}
{{end}} </div>

View file

@ -9,7 +9,7 @@
{{$.locale.Tr "repo.pulls.tab_commits"}} {{$.locale.Tr "repo.pulls.tab_commits"}}
<span class="ui small label">{{if .NumCommits}}{{.NumCommits}}{{else}}-{{end}}</span> <span class="ui small label">{{if .NumCommits}}{{.NumCommits}}{{else}}-{{end}}</span>
</a> </a>
<a class="item {{if .PageIsPullFiles}}active{{end}}" {{if .NumFiles}}href="{{.Issue.Link}}/files"{{end}}> <a class="item {{if .PageIsPullFiles}}active{{end}}" href="{{.Issue.Link}}/files">
{{svg "octicon-diff"}} {{svg "octicon-diff"}}
{{$.locale.Tr "repo.pulls.tab_files"}} {{$.locale.Tr "repo.pulls.tab_files"}}
<span class="ui small label">{{if .NumFiles}}{{.NumFiles}}{{else}}-{{end}}</span> <span class="ui small label">{{if .NumFiles}}{{.NumFiles}}{{else}}-{{end}}</span>