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 commits dropdown in PR files view and allow commit by commit review #25528

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
acbd8dd
Add commits dropdown in PR files view
sebastian-sauer Jun 26, 2023
bd1551c
Disable File-Viewed when reviewing a single commit
sebastian-sauer Jun 26, 2023
862ffc8
Add ellipsis and divider
sebastian-sauer Jun 26, 2023
836ee9b
Add styles and ellipsis
sebastian-sauer Jun 26, 2023
77a81bb
Add max-height and scroll for list of commits
sebastian-sauer Jun 28, 2023
45b7567
Update web_src/css/repo.css
silverwind Jun 28, 2023
a763afe
Reduce padding of commit-menu
sebastian-sauer Jun 28, 2023
a63c7b9
ui enhancements
silverwind Jun 28, 2023
eaa02c7
add jump class to correctly hide tippy
silverwind Jun 28, 2023
bfab42b
tweak locale
silverwind Jun 28, 2023
b390786
remove unnecessary display
silverwind Jun 28, 2023
d439c1f
reduce height some more for small screens
silverwind Jun 28, 2023
2f275a6
calculate len only once
silverwind Jun 28, 2023
9653f1a
Check if given commit sha exists on this PR
sebastian-sauer Jun 28, 2023
7049c71
Improve code
sebastian-sauer Jul 3, 2023
f45980b
Merge remote-tracking branch 'origin/main' into feature/allow_review_…
sebastian-sauer Jul 3, 2023
5b8b4cb
Support three github urls
sebastian-sauer Jul 3, 2023
971d0a0
Make uris behave like github
sebastian-sauer Jul 3, 2023
059c55b
Make commit selector a vue component
sebastian-sauer Jul 3, 2023
1991bf8
Merge remote-tracking branch 'origin/main' into feature/allow_review_…
sebastian-sauer Jul 4, 2023
4d1a4bf
Improve var naming and add comments
sebastian-sauer Jul 4, 2023
451f644
Fix displayed commit for single commits
sebastian-sauer Jul 4, 2023
2d4accf
Disable submitting review when not viewing the full diff
sebastian-sauer Jul 4, 2023
c60b78f
Merge remote-tracking branch 'origin/main' into feature/allow_review_…
sebastian-sauer Jul 4, 2023
0e105bb
Add integration tests for different PR diff endpoints
sebastian-sauer Jul 4, 2023
563d371
fix fmt
sebastian-sauer Jul 5, 2023
0328434
Merge branch 'main' into feature/allow_review_commit_by_commit
sebastian-sauer Jul 5, 2023
6d6d846
Merge remote-tracking branch 'origin/main' into feature/allow_review_…
sebastian-sauer Jul 6, 2023
8588935
Add integration test with more commits
sebastian-sauer Jul 6, 2023
36f3af2
Remove button loading artifacts until vue component is loaded
sebastian-sauer Jul 6, 2023
91217eb
Add comment explaining why the svg is available
sebastian-sauer Jul 6, 2023
43a8a15
Fix integration tests
sebastian-sauer Jul 6, 2023
6828bfd
Add "Show changes since your last review" functionality
sebastian-sauer Jul 6, 2023
863edf6
Add missing divider
sebastian-sauer Jul 6, 2023
076c5ee
Merge remote-tracking branch 'origin/main' into feature/allow_review_…
sebastian-sauer Jul 6, 2023
ea83620
Fix lint
sebastian-sauer Jul 6, 2023
2b37ae4
Fix more tests
sebastian-sauer Jul 6, 2023
1824329
Fix fixture
sebastian-sauer Jul 6, 2023
9dde031
Merge branch 'main' into feature/allow_review_commit_by_commit
sebastian-sauer Jul 7, 2023
ad226d7
Update web_src/js/components/DiffCommitSelector.vue
silverwind Jul 7, 2023
60e1e53
Fix ci error
sebastian-sauer Jul 7, 2023
9a3fe9c
lowercase json keys
sebastian-sauer Jul 7, 2023
5cf8473
Merge branch 'feature/allow_review_commit_by_commit' of https://githu…
sebastian-sauer Jul 7, 2023
1590ad5
Use frontend fetch to get the data
sebastian-sauer Jul 7, 2023
d2b065a
Fix changes since last review url
sebastian-sauer Jul 7, 2023
109394c
Fix order of commits
sebastian-sauer Jul 7, 2023
bcb7c09
Refactors and add hint for commit range
sebastian-sauer Jul 9, 2023
429e41f
Add missing translation
sebastian-sauer Jul 9, 2023
0aef59c
Merge remote-tracking branch 'origin/main' into feature/allow_review_…
sebastian-sauer Jul 9, 2023
5fc1492
Merge branch 'main' into feature/allow_review_commit_by_commit
sebastian-sauer Jul 11, 2023
08094a0
Apply suggestions from code review
sebastian-sauer Jul 11, 2023
333ae56
Merge remote-tracking branch 'origin/main' into feature/allow_review_…
sebastian-sauer Jul 11, 2023
ec0f21c
Add loading animation
sebastian-sauer Jul 12, 2023
ba32e3d
Merge branch 'main' into feature/allow_review_commit_by_commit
silverwind Jul 12, 2023
fea2a66
Use ShortSha for UI
sebastian-sauer Jul 12, 2023
7518ec1
Add max-width and fix double border-top
sebastian-sauer Jul 12, 2023
91a6d0d
Merge branch 'feature/allow_review_commit_by_commit' of https://githu…
sebastian-sauer Jul 12, 2023
f3895a1
Merge branch 'main' into feature/allow_review_commit_by_commit
silverwind Jul 13, 2023
bbf9676
css tweaks
silverwind Jul 13, 2023
dcbdb2e
Fix committer display in vue component
sebastian-sauer Jul 14, 2023
34c9154
Merge branch 'main' into feature/allow_review_commit_by_commit
sebastian-sauer Jul 17, 2023
8307701
Merge remote-tracking branch 'origin/main' into feature/allow_review_…
sebastian-sauer Jul 18, 2023
8a7c4a1
Merge branch 'feature/allow_review_commit_by_commit' of https://githu…
sebastian-sauer Jul 18, 2023
fe0e4c9
Merge remote-tracking branch 'origin/main' into feature/allow_review_…
sebastian-sauer Jul 25, 2023
e005ee3
Fix case of PR
sebastian-sauer Jul 25, 2023
243ade4
Remove div selector
sebastian-sauer Jul 25, 2023
1018cfd
Improve check for empty last review commit ha
sebastian-sauer Jul 25, 2023
78b1006
Improve check for empty commit sha
sebastian-sauer Jul 25, 2023
21f9407
Improve routes
sebastian-sauer Jul 25, 2023
92e9a47
Show all changes in PR if all commits are selected
sebastian-sauer Jul 25, 2023
feba85a
Fix opening the popup when pressing enter
sebastian-sauer Jul 25, 2023
754d242
Extract logic to services
sebastian-sauer Jul 25, 2023
bf424e3
Fix lint
sebastian-sauer Jul 25, 2023
c57289e
Fix relative-time in Firefox
sebastian-sauer Jul 26, 2023
9d025f4
Use light color for show all commits message
sebastian-sauer Jul 26, 2023
2d6c974
Disable Changes since last review if no new commits are available
sebastian-sauer Jul 26, 2023
359a3df
Merge remote-tracking branch 'origin/main' into feature/allow_review_…
sebastian-sauer Jul 27, 2023
985d9de
Make dropdown usable with keyboard
sebastian-sauer Jul 27, 2023
1724181
Add "Show All commits" link
sebastian-sauer Jul 27, 2023
f7acf4a
Add improved range selection
sebastian-sauer Jul 27, 2023
3f9749f
fix XORM bug
wxiaoguang Jul 28, 2023
5e3df0e
fine tune
wxiaoguang Jul 28, 2023
e352233
fine tune
wxiaoguang Jul 28, 2023
57f4864
refactor dom event listener
wxiaoguang Jul 28, 2023
39b4d0c
Merge branch 'main' into feature/allow_review_commit_by_commit
GiteaBot Jul 28, 2023
59588a5
Merge branch 'main' into feature/allow_review_commit_by_commit
GiteaBot Jul 28, 2023
275750e
Merge branch 'main' into feature/allow_review_commit_by_commit
delvh Jul 28, 2023
f4438d1
Fix indentation
sebastian-sauer Jul 28, 2023
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
4 changes: 4 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1654,6 +1654,10 @@ pulls.switch_comparison_type = Switch comparison type
pulls.switch_head_and_base = Switch head and base
pulls.filter_branch = Filter branch
pulls.no_results = No results found.
pulls.show_all_commits = Show all commits
pulls.show_all_commits.description = Show all commits of this PR
pulls.showing_only_single_commit = Showing only changes of commit %[1]s
pulls.select_commits = Filter commit
pulls.nothing_to_compare = These branches are equal. There is no need to create a pull request.
pulls.nothing_to_compare_and_allow_empty_pr = These branches are equal. This PR will be empty.
pulls.has_pull_request = `A pull request between these branches already exists: <a href="%[1]s">%[2]s#%[3]d</a>`
Expand Down
46 changes: 36 additions & 10 deletions routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,8 @@ func ViewPullCommits(ctx *context.Context) {

// ViewPullFiles render pull request changed files list page
func ViewPullFiles(ctx *context.Context) {
commitToShow := ctx.Params("sha")
willShowSingleCommit := len(commitToShow) > 0
ctx.Data["PageIsPullList"] = true
ctx.Data["PageIsPullFiles"] = true

Expand Down Expand Up @@ -719,8 +721,16 @@ func ViewPullFiles(ctx *context.Context) {
}

startCommitID = prInfo.MergeBase
endCommitID = headCommitID

if willShowSingleCommit {
endCommitID = commitToShow
ctx.Data["IsShowingAllCommits"] = false
} else {
endCommitID = headCommitID
ctx.Data["IsShowingAllCommits"] = true
}

ctx.Data["Commits"] = prInfo.Commits
ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
ctx.Data["AfterCommitID"] = endCommitID
Expand All @@ -732,19 +742,35 @@ func ViewPullFiles(ctx *context.Context) {
if fileOnly && (len(files) == 2 || len(files) == 1) {
maxLines, maxFiles = -1, -1
}
diffOptions := &gitdiff.DiffOptions{
BeforeCommitID: startCommitID,
AfterCommitID: endCommitID,
SkipTo: ctx.FormString("skip-to"),
MaxLines: maxLines,
MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters,
MaxFiles: maxFiles,
WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)),

var diffOptions *gitdiff.DiffOptions

// show only a single commit for this pr
if willShowSingleCommit {
diffOptions = &gitdiff.DiffOptions{
AfterCommitID: endCommitID,
SkipTo: ctx.FormString("skip-to"),
MaxLines: maxLines,
MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters,
MaxFiles: maxFiles,
WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)),
}
} else {
// show full PR diff
diffOptions = &gitdiff.DiffOptions{
sebastian-sauer marked this conversation as resolved.
Show resolved Hide resolved
BeforeCommitID: startCommitID,
AfterCommitID: endCommitID,
SkipTo: ctx.FormString("skip-to"),
MaxLines: maxLines,
MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters,
MaxFiles: maxFiles,
WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)),
}
}

var methodWithError string
var diff *gitdiff.Diff
if !ctx.IsSigned {
if !ctx.IsSigned || willShowSingleCommit {
sebastian-sauer marked this conversation as resolved.
Show resolved Hide resolved
diff, err = gitdiff.GetDiff(gitRepo, diffOptions, files...)
methodWithError = "GetDiff"
} else {
Expand Down
1 change: 1 addition & 0 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -1286,6 +1286,7 @@ func registerRoutes(m *web.Route) {
m.Post("/cleanup", context.RepoMustNotBeArchived(), context.RepoRef(), repo.CleanUpPullRequest)
m.Group("/files", func() {
m.Get("", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFiles)
m.Get("/{sha}", context.RepoRef(), repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.SetShowOutdatedComments, repo.ViewPullFiles)
sebastian-sauer marked this conversation as resolved.
Show resolved Hide resolved
m.Group("/reviews", func() {
m.Get("/new_comment", repo.RenderNewCodeCommentForm)
m.Post("/comments", web.Bind(forms.CodeCommentForm{}), repo.SetShowOutdatedComments, repo.CreateCodeComment)
Expand Down
12 changes: 10 additions & 2 deletions templates/repo/diff/box.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,19 @@
{{end}}
{{template "repo/diff/whitespace_dropdown" .}}
{{template "repo/diff/options_dropdown" .}}
{{if .PageIsPullFiles}}
{{template "repo/diff/commits_dropdown" .}}
{{end}}
{{if and .PageIsPullFiles $.SignedUserID (not .IsArchived)}}
{{template "repo/diff/new_review" .}}
{{end}}
</div>
</div>
{{if and (not .IsShowingAllCommits) .PageIsPullFiles}}
<div class="ui info message">
<div class="text gt-whitespace-pre">{{.locale.Tr "repo.pulls.showing_only_single_commit" (ShortSha .AfterCommitID)}}</div>
</div>
{{end}}
<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 diffData = {
Expand Down Expand Up @@ -88,7 +96,7 @@
{{$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)}}
{{$isReviewFile := and $.IsSigned $.PageIsPullFiles (not $.IsArchived) $.IsShowingAllCommits}}
<div class="diff-file-box diff-box file-content {{TabSizeClass $.Editorconfig $file.Name}} gt-mt-3" id="diff-{{$file.NameHash}}" data-old-filename="{{$file.OldName}}" data-new-filename="{{$file.Name}}" {{if or ($file.ShouldBeHidden) (not $isExpandable)}}data-folded="true"{{end}}>
<h4 class="diff-file-header sticky-2nd-row ui top attached normal header gt-df gt-ac gt-sb gt-fw">
<div class="diff-file-name gt-df gt-ac gt-gap-2 gt-fw">
Expand Down Expand Up @@ -153,7 +161,7 @@
{{end}}
</div>
</h4>
<div class="diff-file-body ui attached unstackable table segment" {{if $file.IsViewed}}data-folded="true"{{end}}>
<div class="diff-file-body ui attached unstackable table segment" {{if and $file.IsViewed $.IsShowingAllCommits}}data-folded="true"{{end}}>
<div id="diff-source-{{$file.NameHash}}" class="file-body file-code unicode-escaped code-diff{{if $.IsSplitStyle}} code-diff-split{{else}} code-diff-unified{{end}}{{if $showFileViewToggle}} gt-hidden{{end}}">
{{if or $file.IsIncomplete $file.IsBin}}
<div class="diff-file-body binary" style="padding: 5px 10px;">
Expand Down
32 changes: 32 additions & 0 deletions templates/repo/diff/commits_dropdown.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="ui dropdown tiny basic button" data-tooltip-content="{{.locale.Tr "repo.pulls.select_commits"}}">
{{svg "octicon-git-commit"}}
<div class="menu commit-selector-menu">
<a class="vertical item" href="{{$.Issue.Link}}/files?style={{if $.IsSplitStyle}}split{{else}}unified{{end}}&whitespace={{$.WhitespaceBehavior}}&show-outdated={{$.ShowOutdatedComments}}">
<span class="description gt-ellipsis">
{{.locale.Tr "repo.pulls.show_all_commits.description"}}
</span>
<span class="text gt-ellipsis">
{{.locale.Tr "repo.pulls.show_all_commits"}}
</span>
</a>

{{range .Commits}}
<div class="divider"></div>
<a class="vertical item" href="{{$.Issue.Link}}/files/{{.ID.String}}?style={{if $.IsSplitStyle}}split{{else}}unified{{end}}&whitespace={{$.WhitespaceBehavior}}&show-outdated={{$.ShowOutdatedComments}}">
<span class="description gt-ellipsis">
{{if .Committer}}
{{.Committer.Name}}
<span class="text right">{{TimeSince .Committer.When $.locale}}</span>
{{else}}
{{.Author.Name}}
<span class="text right">{{TimeSince .Author.When $.locale}}</span>
{{end}}
</span>
<div class="text">
<div class="ui compact gt-ellipsis commit-list-summary">{{.Summary}}</div>
<code class="ui right">{{ShortSha .ID.String}}</code>
</div>
</a>
{{end}}
</div>
</div>
10 changes: 10 additions & 0 deletions web_src/css/repo.css
Original file line number Diff line number Diff line change
Expand Up @@ -3340,3 +3340,13 @@ tbody.commit-list {
font-size: 18px;
margin-left: 4px;
}

.commit-list-summary {
max-width: calc(100% - 10ch);
display: inline-block;
}

.commit-selector-menu {
max-height: 60vh;
overflow-y: auto;
}
silverwind marked this conversation as resolved.
Show resolved Hide resolved