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

Introduce pull request commit view files page #26197

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
73 changes: 61 additions & 12 deletions routers/web/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,24 +738,59 @@ func ViewPullCommits(ctx *context.Context) {
ctx.HTML(http.StatusOK, tplPullCommits)
}

func ViewPullCommitFiles(ctx *context.Context) {
ctx.Data["PageIsPullCommits"] = true
issue := checkPullInfo(ctx)
if ctx.Written() {
return
}
var prInfo *git.CompareInfo
if issue.PullRequest.HasMerged {
prInfo = PrepareMergedViewPullInfo(ctx, issue)
} else {
prInfo = PrepareViewPullInfo(ctx, issue)
}

if ctx.Written() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. But it's still necessary because PrepareViewPullInfo is invoked.

return
} else if prInfo == nil {
ctx.NotFound("ViewPullCommits", nil)
return
}

index := -1
for i, commit := range prInfo.Commits {
if commit.ID.String() == ctx.Params("sha") {
index = i
break
}
}
if index == -1 {
ctx.NotFound("ViewPullCommitFiles", nil)
return
}

var startCommitID string
if index == len(prInfo.Commits)-1 {
startCommitID = issue.PullRequest.MergeBase
} else {
startCommitID = prInfo.Commits[index+1].ID.String()
}

baseViewPullCommitFiles(ctx, issue.PullRequest, startCommitID, ctx.Params("sha"))
}

// ViewPullFiles render pull request changed files list page
func ViewPullFiles(ctx *context.Context) {
ctx.Data["PageIsPullList"] = true
ctx.Data["PageIsPullFiles"] = true

var startCommitID string
var endCommitID string
var prInfo *git.CompareInfo
issue := checkPullInfo(ctx)
if ctx.Written() {
return
}
pull := issue.PullRequest

var (
startCommitID string
endCommitID string
gitRepo = ctx.Repo.GitRepo
)

var prInfo *git.CompareInfo
if pull.HasMerged {
prInfo = PrepareMergedViewPullInfo(ctx, issue)
} else {
Expand All @@ -769,14 +804,26 @@ func ViewPullFiles(ctx *context.Context) {
return
}

headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitRefName())
headCommitID, err := ctx.Repo.GitRepo.GetRefCommitID(pull.GetGitRefName())
if err != nil {
ctx.ServerError("GetRefCommitID", err)
return
}

startCommitID = prInfo.MergeBase
endCommitID = headCommitID
baseViewPullCommitFiles(ctx, pull, startCommitID, endCommitID)
}

func showOutdatedComments(ctx *context.Context) bool {
show, ok := ctx.Data["ShowOutdatedComments"].(bool)
return ok && show
}

func baseViewPullCommitFiles(ctx *context.Context, pull *issues_model.PullRequest, startCommitID, endCommitID string) {
ctx.Data["PageIsPullList"] = true

gitRepo := ctx.Repo.GitRepo

ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
Expand All @@ -801,6 +848,8 @@ func ViewPullFiles(ctx *context.Context) {

var methodWithError string
var diff *gitdiff.Diff
var err error
issue := pull.Issue
if !ctx.IsSigned {
diff, err = gitdiff.GetDiff(gitRepo, diffOptions, files...)
methodWithError = "GetDiff"
Expand All @@ -818,7 +867,7 @@ func ViewPullFiles(ctx *context.Context) {
"numberOfViewedFiles": diff.NumViewedFiles,
}

if err = diff.LoadComments(ctx, issue, ctx.Doer, ctx.Data["ShowOutdatedComments"].(bool)); err != nil {
if err = diff.LoadComments(ctx, issue, ctx.Doer, showOutdatedComments(ctx)); err != nil {
ctx.ServerError("LoadComments", err)
return
}
Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/pull_review.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func UpdateResolveConversation(ctx *context.Context) {
}

func renderConversation(ctx *context.Context, comment *issues_model.Comment) {
comments, err := issues_model.FetchCodeCommentsByLine(ctx, comment.Issue, ctx.Doer, comment.TreePath, comment.Line, ctx.Data["ShowOutdatedComments"].(bool))
comments, err := issues_model.FetchCodeCommentsByLine(ctx, comment.Issue, ctx.Doer, comment.TreePath, comment.Line, showOutdatedComments(ctx))
if err != nil {
ctx.ServerError("FetchCodeCommentsByLine", err)
return
Expand Down
1 change: 1 addition & 0 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,7 @@ func registerRoutes(m *web.Route) {
m.Get(".diff", repo.DownloadPullDiff)
m.Get(".patch", repo.DownloadPullPatch)
m.Get("/commits", context.RepoRef(), repo.SetWhitespaceBehavior, repo.GetPullDiffStats, repo.ViewPullCommits)
m.Get("/commits/{sha}", context.RepoRef(), repo.SetWhitespaceBehavior, repo.GetPullDiffStats, repo.ViewPullCommitFiles)
m.Post("/merge", context.RepoMustNotBeArchived(), web.Bind(forms.MergePullRequestForm{}), repo.MergePullRequest)
m.Post("/cancel_auto_merge", context.RepoMustNotBeArchived(), repo.CancelAutoMergePullRequest)
m.Post("/update", repo.UpdatePullRequest)
Expand Down
2 changes: 2 additions & 0 deletions templates/repo/commits_list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
{{end}}
{{if $.PageIsWiki}}
<a href="{{$commitRepoLink}}/wiki/commit/{{.ID}}" rel="nofollow" class="{{$class}}">
{{else if $.PageIsPullCommits}}
<a href="{{$commitRepoLink}}/pulls/{{$.Issue.Index}}/commits/{{.ID}}" rel="nofollow" class="{{$class}}">
{{else if $.Reponame}}
<a href="{{$commitRepoLink}}/commit/{{.ID}}" rel="nofollow" class="{{$class}}">
{{else}}
Expand Down
Loading