Multiple GitGraph improvements: Exclude PR heads, Add branch/PR links, Show only certain branches, (#12766)
* Multiple GitGraph improvements. Add backend support for excluding PRs, selecting branches and files. Fix #10327 Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @silverwind Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @silverwind Signed-off-by: Andrew Thornton <art27@cantab.net> * Only show refs in dropdown we display on the graph Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @silverwind Signed-off-by: Andrew Thornton <art27@cantab.net> * use flexbox for ui header Signed-off-by: Andrew Thornton <art27@cantab.net> * Move Hide Pull Request button to the dropdown Signed-off-by: Andrew Thornton <art27@cantab.net> * Add SHA and user pictures Signed-off-by: Andrew Thornton <art27@cantab.net> * fix test Signed-off-by: Andrew Thornton <art27@cantab.net> * fix test 2 Signed-off-by: Andrew Thornton <art27@cantab.net> * fixes * async * more tweaks * use tabs in tmpl Signed-off-by: Andrew Thornton <art27@cantab.net> * remove commented thing Signed-off-by: Andrew Thornton <art27@cantab.net> * fix linting Signed-off-by: Andrew Thornton <art27@cantab.net> * Update web_src/js/features/gitgraph.js Co-authored-by: silverwind <me@silverwind.io> * graph tweaks * more tweaks * add title Signed-off-by: Andrew Thornton <art27@cantab.net> * fix loading indicator z-index and position Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
parent
d4e0b28655
commit
c05a8abc76
21 changed files with 588 additions and 126 deletions
|
@ -23,6 +23,7 @@ import (
|
|||
const (
|
||||
tplCommits base.TplName = "repo/commits"
|
||||
tplGraph base.TplName = "repo/graph"
|
||||
tplGraphDiv base.TplName = "repo/graph/div"
|
||||
tplCommitPage base.TplName = "repo/commit_page"
|
||||
)
|
||||
|
||||
|
@ -88,6 +89,7 @@ func Commits(ctx *context.Context) {
|
|||
|
||||
// Graph render commit graph - show commits from all branches.
|
||||
func Graph(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("repo.commit_graph")
|
||||
ctx.Data["PageIsCommits"] = true
|
||||
ctx.Data["PageIsViewCode"] = true
|
||||
mode := strings.ToLower(ctx.QueryTrim("mode"))
|
||||
|
@ -95,6 +97,18 @@ func Graph(ctx *context.Context) {
|
|||
mode = "color"
|
||||
}
|
||||
ctx.Data["Mode"] = mode
|
||||
hidePRRefs := ctx.QueryBool("hide-pr-refs")
|
||||
ctx.Data["HidePRRefs"] = hidePRRefs
|
||||
branches := ctx.QueryStrings("branch")
|
||||
realBranches := make([]string, len(branches))
|
||||
copy(realBranches, branches)
|
||||
for i, branch := range realBranches {
|
||||
if strings.HasPrefix(branch, "--") {
|
||||
realBranches[i] = "refs/heads/" + branch
|
||||
}
|
||||
}
|
||||
ctx.Data["SelectedBranches"] = realBranches
|
||||
files := ctx.QueryStrings("file")
|
||||
|
||||
commitsCount, err := ctx.Repo.GetCommitsCount()
|
||||
if err != nil {
|
||||
|
@ -102,28 +116,60 @@ func Graph(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
allCommitsCount, err := ctx.Repo.GitRepo.GetAllCommitsCount()
|
||||
graphCommitsCount, err := ctx.Repo.GetCommitGraphsCount(hidePRRefs, realBranches, files)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetAllCommitsCount", err)
|
||||
return
|
||||
log.Warn("GetCommitGraphsCount error for generate graph exclude prs: %t branches: %s in %-v, Will Ignore branches and try again. Underlying Error: %v", hidePRRefs, branches, ctx.Repo.Repository, err)
|
||||
realBranches = []string{}
|
||||
branches = []string{}
|
||||
graphCommitsCount, err = ctx.Repo.GetCommitGraphsCount(hidePRRefs, realBranches, files)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetCommitGraphsCount", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
page := ctx.QueryInt("page")
|
||||
|
||||
graph, err := gitgraph.GetCommitGraph(ctx.Repo.GitRepo, page, 0)
|
||||
graph, err := gitgraph.GetCommitGraph(ctx.Repo.GitRepo, page, 0, hidePRRefs, realBranches, files)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetCommitGraph", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := graph.LoadAndProcessCommits(ctx.Repo.Repository, ctx.Repo.GitRepo); err != nil {
|
||||
ctx.ServerError("LoadAndProcessCommits", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Graph"] = graph
|
||||
|
||||
gitRefs, err := ctx.Repo.GitRepo.GetRefs()
|
||||
if err != nil {
|
||||
ctx.ServerError("GitRepo.GetRefs", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["AllRefs"] = gitRefs
|
||||
|
||||
ctx.Data["Username"] = ctx.Repo.Owner.Name
|
||||
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
|
||||
ctx.Data["CommitCount"] = commitsCount
|
||||
ctx.Data["Branch"] = ctx.Repo.BranchName
|
||||
paginator := context.NewPagination(int(allCommitsCount), setting.UI.GraphMaxCommitNum, page, 5)
|
||||
paginator := context.NewPagination(int(graphCommitsCount), setting.UI.GraphMaxCommitNum, page, 5)
|
||||
paginator.AddParam(ctx, "mode", "Mode")
|
||||
paginator.AddParam(ctx, "hide-pr-refs", "HidePRRefs")
|
||||
for _, branch := range branches {
|
||||
paginator.AddParamString("branch", branch)
|
||||
}
|
||||
for _, file := range files {
|
||||
paginator.AddParamString("file", file)
|
||||
}
|
||||
ctx.Data["Page"] = paginator
|
||||
if ctx.QueryBool("div-only") {
|
||||
ctx.HTML(200, tplGraphDiv)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.HTML(200, tplGraph)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue