finish PR UI
This commit is contained in:
parent
65e73c4ac6
commit
37e0cee877
16 changed files with 302 additions and 111 deletions
|
@ -204,25 +204,6 @@ func Diff(ctx *middleware.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
isImageFile := func(name string) bool {
|
||||
blob, err := ctx.Repo.Commit.GetBlobByPath(name)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
dataRc, err := blob.Data()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
buf := make([]byte, 1024)
|
||||
n, _ := dataRc.Read(buf)
|
||||
if n > 0 {
|
||||
buf = buf[:n]
|
||||
}
|
||||
_, isImage := base.IsImageFile(buf)
|
||||
return isImage
|
||||
}
|
||||
|
||||
parents := make([]string, commit.ParentCount())
|
||||
for i := 0; i < commit.ParentCount(); i++ {
|
||||
sha, err := commit.ParentId(i)
|
||||
|
@ -235,7 +216,7 @@ func Diff(ctx *middleware.Context) {
|
|||
|
||||
ctx.Data["Username"] = userName
|
||||
ctx.Data["Reponame"] = repoName
|
||||
ctx.Data["IsImageFile"] = isImageFile
|
||||
ctx.Data["IsImageFile"] = commit.IsImageFile
|
||||
ctx.Data["Title"] = commit.Summary() + " · " + base.ShortSha(commitID)
|
||||
ctx.Data["Commit"] = commit
|
||||
ctx.Data["Author"] = models.ValidateCommitWithEmail(commit)
|
||||
|
@ -271,25 +252,6 @@ func CompareDiff(ctx *middleware.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
isImageFile := func(name string) bool {
|
||||
blob, err := commit.GetBlobByPath(name)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
dataRc, err := blob.Data()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
buf := make([]byte, 1024)
|
||||
n, _ := dataRc.Read(buf)
|
||||
if n > 0 {
|
||||
buf = buf[:n]
|
||||
}
|
||||
_, isImage := base.IsImageFile(buf)
|
||||
return isImage
|
||||
}
|
||||
|
||||
commits, err := commit.CommitsBeforeUntil(beforeCommitID)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "CommitsBeforeUntil", err)
|
||||
|
@ -304,7 +266,7 @@ func CompareDiff(ctx *middleware.Context) {
|
|||
ctx.Data["AfterCommitID"] = afterCommitID
|
||||
ctx.Data["Username"] = userName
|
||||
ctx.Data["Reponame"] = repoName
|
||||
ctx.Data["IsImageFile"] = isImageFile
|
||||
ctx.Data["IsImageFile"] = commit.IsImageFile
|
||||
ctx.Data["Title"] = "Comparing " + base.ShortSha(beforeCommitID) + "..." + base.ShortSha(afterCommitID) + " · " + userName + "/" + repoName
|
||||
ctx.Data["Commit"] = commit
|
||||
ctx.Data["Diff"] = diff
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/auth"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/git"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/mailer"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
|
@ -427,7 +426,6 @@ func UploadIssueAttachment(ctx *middleware.Context) {
|
|||
}
|
||||
|
||||
func ViewIssue(ctx *middleware.Context) {
|
||||
ctx.Data["PageIsIssueList"] = true
|
||||
ctx.Data["RequireDropzone"] = true
|
||||
renderAttachmentSettings(ctx)
|
||||
|
||||
|
@ -451,6 +449,13 @@ func ViewIssue(ctx *middleware.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
if issue.IsPull {
|
||||
ctx.Data["PageIsPullList"] = true
|
||||
ctx.Data["PageIsPullConversation"] = true
|
||||
} else {
|
||||
ctx.Data["PageIsIssueList"] = true
|
||||
}
|
||||
|
||||
if err = issue.GetPoster(); err != nil {
|
||||
ctx.Handle(500, "GetPoster", err)
|
||||
return
|
||||
|
@ -461,29 +466,10 @@ func ViewIssue(ctx *middleware.Context) {
|
|||
|
||||
// Get more information if it's a pull request.
|
||||
if issue.IsPull {
|
||||
ctx.Data["HeadTarget"] = issue.PullRepo.HeadUserName + "/" + issue.PullRepo.HeadBarcnh
|
||||
ctx.Data["BaseTarget"] = ctx.Repo.Owner.Name + "/" + issue.PullRepo.BaseBranch
|
||||
|
||||
headRepoPath, err := issue.PullRepo.HeadRepo.RepoPath()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "PullRepo.HeadRepo.RepoPath", err)
|
||||
PrepareViewPullInfo(ctx, issue)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
headGitRepo, err := git.OpenRepository(headRepoPath)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "OpenRepository", err)
|
||||
return
|
||||
}
|
||||
|
||||
prInfo, err := headGitRepo.GetPullRequestInfo(models.RepoPath(repo.Owner.Name, repo.Name),
|
||||
issue.PullRepo.BaseBranch, issue.PullRepo.HeadBarcnh)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetPullRequestInfo", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["NumCommits"] = prInfo.Commits.Len()
|
||||
ctx.Data["NumFiles"] = prInfo.NumFiles
|
||||
}
|
||||
|
||||
// Metas.
|
||||
|
|
|
@ -23,6 +23,8 @@ const (
|
|||
FORK base.TplName = "repo/pulls/fork"
|
||||
COMPARE_PULL base.TplName = "repo/pulls/compare"
|
||||
PULLS base.TplName = "repo/pulls"
|
||||
PULL_COMMITS base.TplName = "repo/pulls/commits"
|
||||
PULL_FILES base.TplName = "repo/pulls/files"
|
||||
)
|
||||
|
||||
func getForkRepository(ctx *middleware.Context) *models.Repository {
|
||||
|
@ -131,7 +133,140 @@ func Pulls(ctx *middleware.Context) {
|
|||
ctx.HTML(200, PULLS)
|
||||
}
|
||||
|
||||
// func ViewPull
|
||||
func checkPullInfo(ctx *middleware.Context) *models.Issue {
|
||||
pull, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
if models.IsErrIssueNotExist(err) {
|
||||
ctx.Handle(404, "GetIssueByIndex", err)
|
||||
} else {
|
||||
ctx.Handle(500, "GetIssueByIndex", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
ctx.Data["Title"] = pull.Name
|
||||
ctx.Data["Issue"] = pull
|
||||
|
||||
if !pull.IsPull {
|
||||
ctx.Handle(404, "ViewPullCommits", nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
if err = pull.GetPoster(); err != nil {
|
||||
ctx.Handle(500, "GetPoster", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
if ctx.IsSigned {
|
||||
// Update issue-user.
|
||||
if err = pull.ReadBy(ctx.User.Id); err != nil {
|
||||
ctx.Handle(500, "ReadBy", err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return pull
|
||||
}
|
||||
|
||||
func PrepareViewPullInfo(ctx *middleware.Context, pull *models.Issue) *git.PullRequestInfo {
|
||||
repo := ctx.Repo.Repository
|
||||
|
||||
ctx.Data["HeadTarget"] = pull.PullRepo.HeadUserName + "/" + pull.PullRepo.HeadBarcnh
|
||||
ctx.Data["BaseTarget"] = ctx.Repo.Owner.Name + "/" + pull.PullRepo.BaseBranch
|
||||
|
||||
headRepoPath, err := pull.PullRepo.HeadRepo.RepoPath()
|
||||
if err != nil {
|
||||
ctx.Handle(500, "PullRepo.HeadRepo.RepoPath", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
headGitRepo, err := git.OpenRepository(headRepoPath)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "OpenRepository", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
prInfo, err := headGitRepo.GetPullRequestInfo(models.RepoPath(repo.Owner.Name, repo.Name),
|
||||
pull.PullRepo.BaseBranch, pull.PullRepo.HeadBarcnh)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetPullRequestInfo", err)
|
||||
return nil
|
||||
}
|
||||
ctx.Data["NumCommits"] = prInfo.Commits.Len()
|
||||
ctx.Data["NumFiles"] = prInfo.NumFiles
|
||||
return prInfo
|
||||
}
|
||||
|
||||
func ViewPullCommits(ctx *middleware.Context) {
|
||||
ctx.Data["PageIsPullCommits"] = true
|
||||
|
||||
pull := checkPullInfo(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
prInfo := PrepareViewPullInfo(ctx, pull)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
prInfo.Commits = models.ValidateCommitsWithEmails(prInfo.Commits)
|
||||
ctx.Data["Commits"] = prInfo.Commits
|
||||
|
||||
ctx.HTML(200, PULL_COMMITS)
|
||||
}
|
||||
|
||||
func ViewPullFiles(ctx *middleware.Context) {
|
||||
ctx.Data["PageIsPullFiles"] = true
|
||||
|
||||
pull := checkPullInfo(ctx)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
prInfo := PrepareViewPullInfo(ctx, pull)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
_ = prInfo
|
||||
|
||||
headRepoPath := models.RepoPath(pull.PullRepo.HeadUserName, pull.PullRepo.HeadRepo.Name)
|
||||
|
||||
headGitRepo, err := git.OpenRepository(headRepoPath)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "OpenRepository", err)
|
||||
return
|
||||
}
|
||||
|
||||
headCommitID, err := headGitRepo.GetCommitIdOfBranch(pull.PullRepo.HeadBarcnh)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetCommitIdOfBranch", err)
|
||||
return
|
||||
}
|
||||
|
||||
diff, err := models.GetDiffRange(headRepoPath,
|
||||
prInfo.MergeBase, headCommitID, setting.Git.MaxGitDiffLines)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetDiffRange", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Diff"] = diff
|
||||
ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
|
||||
|
||||
headCommit, err := headGitRepo.GetCommit(headCommitID)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "GetCommit", err)
|
||||
return
|
||||
}
|
||||
|
||||
headTarget := path.Join(pull.PullRepo.HeadUserName, pull.PullRepo.HeadRepo.Name)
|
||||
ctx.Data["Username"] = pull.PullRepo.HeadUserName
|
||||
ctx.Data["Reponame"] = pull.PullRepo.HeadRepo.Name
|
||||
ctx.Data["IsImageFile"] = headCommit.IsImageFile
|
||||
ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", headCommitID)
|
||||
ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", prInfo.MergeBase)
|
||||
ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "raw", headCommitID)
|
||||
|
||||
ctx.HTML(200, PULL_FILES)
|
||||
}
|
||||
|
||||
func ParseCompareInfo(ctx *middleware.Context) (*models.User, *models.Repository, *git.Repository, *git.PullRequestInfo, string, string) {
|
||||
// Get compare branch information.
|
||||
|
@ -248,34 +383,18 @@ func PrepareCompareDiff(
|
|||
ctx.Handle(500, "GetCommit", err)
|
||||
return
|
||||
}
|
||||
isImageFile := func(name string) bool {
|
||||
blob, err := headCommit.GetBlobByPath(name)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
dataRc, err := blob.Data()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
buf := make([]byte, 1024)
|
||||
n, _ := dataRc.Read(buf)
|
||||
if n > 0 {
|
||||
buf = buf[:n]
|
||||
}
|
||||
_, isImage := base.IsImageFile(buf)
|
||||
return isImage
|
||||
}
|
||||
|
||||
prInfo.Commits = models.ValidateCommitsWithEmails(prInfo.Commits)
|
||||
ctx.Data["Commits"] = prInfo.Commits
|
||||
ctx.Data["CommitCount"] = prInfo.Commits.Len()
|
||||
ctx.Data["Username"] = headUser.Name
|
||||
ctx.Data["Reponame"] = headRepo.Name
|
||||
ctx.Data["IsImageFile"] = isImageFile
|
||||
ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(headUser.Name, repo.Name, "src", headCommitID)
|
||||
ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(headUser.Name, repo.Name, "src", prInfo.MergeBase)
|
||||
ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(headUser.Name, repo.Name, "raw", headCommitID)
|
||||
ctx.Data["IsImageFile"] = headCommit.IsImageFile
|
||||
|
||||
headTarget := path.Join(headUser.Name, repo.Name)
|
||||
ctx.Data["SourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", headCommitID)
|
||||
ctx.Data["BeforeSourcePath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "src", prInfo.MergeBase)
|
||||
ctx.Data["RawPath"] = setting.AppSubUrl + "/" + path.Join(headTarget, "raw", headCommitID)
|
||||
}
|
||||
|
||||
func CompareAndPullRequest(ctx *middleware.Context) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue