From e595dfeec7548693ed14778edb6b24726ac46e7e Mon Sep 17 00:00:00 2001 From: Giteabot Date: Thu, 6 Jul 2023 15:34:41 -0400 Subject: [PATCH] Allow/fix review (approve/reject) of empty PRs (#25690) (#25732) Backport #25690 by @sebastian-sauer 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: sebastian-sauer Co-authored-by: silverwind --- templates/repo/diff/box.tmpl | 346 ++++++++++++++--------------- templates/repo/pulls/tab_menu.tmpl | 2 +- 2 files changed, 171 insertions(+), 177 deletions(-) diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index b52115a007..7d2c03fe61 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -1,20 +1,7 @@ -{{if .DiffNotAvailable}} -
-
-
- {{template "repo/diff/whitespace_dropdown" .}} - {{template "repo/diff/options_dropdown" .}} - {{if and .PageIsPullFiles $.SignedUserID (not .IsArchived)}} - {{template "repo/diff/new_review" .}} - {{end}} -
-
-
-

{{.locale.Tr "repo.diff.data_not_available"}}

-{{else}} -
-
-
+
+
+
+ {{if not .DiffNotAvailable}}
-
- {{if and .PageIsPullFiles $.SignedUserID (not .IsArchived)}} -
- - -
- {{end}} - {{template "repo/diff/whitespace_dropdown" .}} - {{template "repo/diff/options_dropdown" .}} - {{if and .PageIsPullFiles $.SignedUserID (not .IsArchived)}} - {{template "repo/diff/new_review" .}} - {{end}} -
+ {{end}}
+
+ {{if and .PageIsPullFiles $.SignedUserID (not .IsArchived) (not .DiffNotAvailable)}} +
+ + +
+ {{end}} + {{template "repo/diff/whitespace_dropdown" .}} + {{template "repo/diff/options_dropdown" .}} + {{if and .PageIsPullFiles $.SignedUserID (not .IsArchived)}} + {{template "repo/diff/new_review" .}} + {{end}} +
+
+ {{if not .DiffNotAvailable}}
-
-
- -
- {{range $i, $file := .Diff.Files}} - {{/*notice: the index of Diff.Files should not be used for element ID, because the index will be restarted from 0 when doing load-more for PRs with a lot of files*/}} - {{$blobBase := call $.GetBlobByPathForCommit $.BeforeCommit $file.OldName}} - {{$blobHead := call $.GetBlobByPathForCommit $.HeadCommit $file.Name}} - {{$isImage := or (call $.IsBlobAnImage $blobBase) (call $.IsBlobAnImage $blobHead)}} - {{$isCsv := (call $.IsCsvFile $file)}} - {{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv)}} - {{$isExpandable := or (gt $file.Addition 0) (gt $file.Deletion 0) $file.IsBin}} - {{$isReviewFile := and $.IsSigned $.PageIsPullFiles (not $.IsArchived)}} -
-

-
- -
- {{if $file.IsBin}} - - {{$.locale.Tr "repo.diff.bin"}} - - {{else}} - {{template "repo/diff/stats" dict "file" . "root" $}} - {{end}} -
- {{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}}{{if .IsLFSFile}} ({{$.locale.Tr "repo.stored_lfs"}}){{end}} - - {{if $file.IsGenerated}} - {{$.locale.Tr "repo.diff.generated"}} - {{end}} - {{if $file.IsVendored}} - {{$.locale.Tr "repo.diff.vendored"}} - {{end}} - {{if and $file.Mode $file.OldMode}} - {{$file.OldMode}} → {{$file.Mode}} - {{else if $file.Mode}} - {{$file.Mode}} - {{end}} -
-
- {{if $showFileViewToggle}} -
- - -
- {{end}} - {{if $file.IsProtected}} - {{$.locale.Tr "repo.diff.protected"}} - {{end}} - {{if and $isReviewFile $file.HasChangedSinceLastReview}} - {{$.locale.Tr "repo.pulls.has_changed_since_last_review"}} - {{end}} - {{if not (or $file.IsIncomplete $file.IsBin $file.IsSubmodule)}} - - - {{end}} - {{if and (not $file.IsSubmodule) (not $.PageIsWiki)}} - {{if $file.IsDeleted}} - {{$.locale.Tr "repo.diff.view_file"}} - {{else}} - {{$.locale.Tr "repo.diff.view_file"}} - {{end}} - {{end}} - {{if $isReviewFile}} - - {{end}} -
-

-
-
- {{if or $file.IsIncomplete $file.IsBin}} -
- {{if $file.IsIncomplete}} - {{if $file.IsIncompleteLineTooLong}} - {{$.locale.Tr "repo.diff.file_suppressed_line_too_long"}} - {{else}} - {{$.locale.Tr "repo.diff.file_suppressed"}} - {{$.locale.Tr "repo.diff.load"}} - {{end}} - {{else}} - {{$.locale.Tr "repo.diff.bin_not_shown"}} - {{end}} -
+ {{end}} +
+ {{if .DiffNotAvailable}} +

{{.locale.Tr "repo.diff.data_not_available"}}

+ {{else}} +
+ +
+ {{range $i, $file := .Diff.Files}} + {{/*notice: the index of Diff.Files should not be used for element ID, because the index will be restarted from 0 when doing load-more for PRs with a lot of files*/}} + {{$blobBase := call $.GetBlobByPathForCommit $.BeforeCommit $file.OldName}} + {{$blobHead := call $.GetBlobByPathForCommit $.HeadCommit $file.Name}} + {{$isImage := or (call $.IsBlobAnImage $blobBase) (call $.IsBlobAnImage $blobHead)}} + {{$isCsv := (call $.IsCsvFile $file)}} + {{$showFileViewToggle := or $isImage (and (not $file.IsIncomplete) $isCsv)}} + {{$isExpandable := or (gt $file.Addition 0) (gt $file.Deletion 0) $file.IsBin}} + {{$isReviewFile := and $.IsSigned $.PageIsPullFiles (not $.IsArchived)}} +
+

+
+ +
+ {{if $file.IsBin}} + + {{$.locale.Tr "repo.diff.bin"}} + + {{else}} + {{template "repo/diff/stats" dict "file" . "root" $}} {{end}}
- {{if $showFileViewToggle}} - {{/* for image or CSV, it can have a horizontal scroll bar, there won't be review comment context menu (position absolute) which would be clipped by "overflow" */}} -
- - {{if $isImage}} - {{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}} - {{else}} - {{template "repo/diff/csv_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}} - {{end}} -
-
+ {{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}}{{if .IsLFSFile}} ({{$.locale.Tr "repo.stored_lfs"}}){{end}} + + {{if $file.IsGenerated}} + {{$.locale.Tr "repo.diff.generated"}} + {{end}} + {{if $file.IsVendored}} + {{$.locale.Tr "repo.diff.vendored"}} + {{end}} + {{if and $file.Mode $file.OldMode}} + {{$file.OldMode}} → {{$file.Mode}} + {{else if $file.Mode}} + {{$file.Mode}} {{end}}
+
+ {{if $showFileViewToggle}} +
+ + +
+ {{end}} + {{if $file.IsProtected}} + {{$.locale.Tr "repo.diff.protected"}} + {{end}} + {{if and $isReviewFile $file.HasChangedSinceLastReview}} + {{$.locale.Tr "repo.pulls.has_changed_since_last_review"}} + {{end}} + {{if not (or $file.IsIncomplete $file.IsBin $file.IsSubmodule)}} + + + {{end}} + {{if and (not $file.IsSubmodule) (not $.PageIsWiki)}} + {{if $file.IsDeleted}} + {{$.locale.Tr "repo.diff.view_file"}} + {{else}} + {{$.locale.Tr "repo.diff.view_file"}} + {{end}} + {{end}} + {{if $isReviewFile}} + + {{end}} +
+

+
+
+ {{if or $file.IsIncomplete $file.IsBin}} +
+ {{if $file.IsIncomplete}} + {{if $file.IsIncompleteLineTooLong}} + {{$.locale.Tr "repo.diff.file_suppressed_line_too_long"}} + {{else}} + {{$.locale.Tr "repo.diff.file_suppressed"}} + {{$.locale.Tr "repo.diff.load"}} + {{end}} + {{else}} + {{$.locale.Tr "repo.diff.bin_not_shown"}} + {{end}} +
+ {{else}} + + {{if $.IsSplitStyle}} + {{template "repo/diff/section_split" dict "file" . "root" $}} + {{else}} + {{template "repo/diff/section_unified" dict "file" . "root" $}} + {{end}} +
+ {{end}} +
+ {{if $showFileViewToggle}} + {{/* for image or CSV, it can have a horizontal scroll bar, there won't be review comment context menu (position absolute) which would be clipped by "overflow" */}} +
+ + {{if $isImage}} + {{template "repo/diff/image_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}} + {{else}} + {{template "repo/diff/csv_diff" dict "file" . "root" $ "blobBase" $blobBase "blobHead" $blobHead}} + {{end}} +
+
+ {{end}}
- {{end}} - - {{if .Diff.IsIncomplete}} -
-

- {{$.locale.Tr "repo.diff.too_many_files"}} - {{.locale.Tr "repo.diff.show_more"}} -

-
- {{end}} -
-
- - {{if not $.Repository.IsArchived}} - - {{end}} + {{end}} - {{template "repo/issue/view_content/reference_issue_dialog" .}} + {{if .Diff.IsIncomplete}} +
+

+ {{$.locale.Tr "repo.diff.too_many_files"}} + {{.locale.Tr "repo.diff.show_more"}} +

+
+ {{end}} +
+ {{end}}
-{{end}} + + {{if and (not $.Repository.IsArchived) (not .DiffNotAvailable)}} + + {{end}} + {{if (not .DiffNotAvailable)}} + {{template "repo/issue/view_content/reference_issue_dialog" .}} + {{end}} +
diff --git a/templates/repo/pulls/tab_menu.tmpl b/templates/repo/pulls/tab_menu.tmpl index f44968c775..b55b3b0040 100644 --- a/templates/repo/pulls/tab_menu.tmpl +++ b/templates/repo/pulls/tab_menu.tmpl @@ -9,7 +9,7 @@ {{$.locale.Tr "repo.pulls.tab_commits"}} {{if .NumCommits}}{{.NumCommits}}{{else}}-{{end}} - + {{svg "octicon-diff"}} {{$.locale.Tr "repo.pulls.tab_files"}} {{if .NumFiles}}{{.NumFiles}}{{else}}-{{end}}