Skip to content

Commit bf76828

Browse files
committed
Add route and router for graph
1 parent a8a9cf5 commit bf76828

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

cmd/web.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ func runWeb(ctx *cli.Context) error {
537537
m.Get("/src/*", repo.SetEditorconfigIfExists, repo.Home)
538538
m.Get("/raw/*", repo.SingleDownload)
539539
m.Get("/commits/*", repo.RefCommits)
540+
m.Get("/graph", repo.Graph)
540541
m.Get("/commit/:sha([a-f0-9]{7,40})$", repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.Diff)
541542
m.Get("/forks", repo.Forks)
542543
}, context.RepoRef())

routers/repo/commit.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
const (
2020
tplCommits base.TplName = "repo/commits"
21+
tplGraph base.TplName = "repo/graph"
2122
tplDiff base.TplName = "repo/diff/page"
2223
)
2324

@@ -75,6 +76,32 @@ func Commits(ctx *context.Context) {
7576
ctx.HTML(200, tplCommits)
7677
}
7778

79+
// Graph render commit graph - show commits from all branches.
80+
func Graph(ctx *context.Context) {
81+
ctx.Data["PageIsCommits"] = true
82+
83+
commitsCount, err := ctx.Repo.Commit.CommitsCount()
84+
if err != nil {
85+
ctx.Handle(500, "GetCommitsCount", err)
86+
return
87+
}
88+
89+
graph, err := models.GetCommitGraph(ctx.Repo.GitRepo)
90+
if err != nil {
91+
ctx.Handle(500, "GetCommitGraph", err)
92+
return
93+
}
94+
95+
ctx.Data["Graph"] = graph
96+
ctx.Data["Username"] = ctx.Repo.Owner.Name
97+
ctx.Data["Reponame"] = ctx.Repo.Repository.Name
98+
ctx.Data["CommitCount"] = commitsCount
99+
ctx.Data["Branch"] = ctx.Repo.BranchName
100+
ctx.Data["RequireGitGraph"] = true
101+
ctx.HTML(200, tplGraph)
102+
103+
}
104+
78105
// SearchCommits render commits filtered by keyword
79106
func SearchCommits(ctx *context.Context) {
80107
ctx.Data["PageIsCommits"] = true

0 commit comments

Comments
 (0)