aboutsummaryrefslogtreecommitdiff
path: root/pkg/handler/git/handler.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/handler/git/handler.go')
-rw-r--r--pkg/handler/git/handler.go33
1 files changed, 29 insertions, 4 deletions
diff --git a/pkg/handler/git/handler.go b/pkg/handler/git/handler.go
index d090f22..b77bcfc 100644
--- a/pkg/handler/git/handler.go
+++ b/pkg/handler/git/handler.go
@@ -18,9 +18,10 @@ type (
gitService interface {
ListRepositories() ([]*service.Repository, error)
- ListCommits(string) ([]*object.Commit, error)
- ListTags(string) ([]*object.Tag, error)
- ListBranches(string) ([]*plumbing.Reference, error)
+ ListCommits(name string, ref string) ([]*object.Commit, error)
+ GetHead(name string) (*plumbing.Reference, error)
+ ListTags(name string) ([]*object.Tag, error)
+ ListBranches(name string) ([]*plumbing.Reference, error)
}
)
@@ -43,8 +44,15 @@ func (g *GitHandler) List(w http.ResponseWriter, _ *http.Request) {
func (g *GitHandler) Summary(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
+ ref, err := g.gitService.GetHead(name)
+ if err != nil {
+ slog.Error("Error loading head", "error", err)
+ return
+ }
+
gitList := &templates.GitItemPage{
Name: name,
+ Ref: ref.Name().Short(),
GitItemBase: &templates.GitItemSummaryPage{},
}
templates.WritePageTemplate(w, gitList)
@@ -52,8 +60,14 @@ func (g *GitHandler) Summary(w http.ResponseWriter, r *http.Request) {
func (g *GitHandler) About(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
+ ref, err := g.gitService.GetHead(name)
+ if err != nil {
+ slog.Error("Error loading head", "error", err)
+ return
+ }
gitList := &templates.GitItemPage{
Name: name,
+ Ref: ref.Name().Short(),
GitItemBase: &templates.GitItemAboutPage{},
}
templates.WritePageTemplate(w, gitList)
@@ -74,8 +88,15 @@ func (g *GitHandler) Refs(w http.ResponseWriter, r *http.Request) {
return
}
+ ref, err := g.gitService.GetHead(name)
+ if err != nil {
+ slog.Error("Error loading head", "error", err)
+ return
+ }
+
gitList := &templates.GitItemPage{
Name: name,
+ Ref: ref.Name().Short(),
GitItemBase: &templates.GitItemRefsPage{
Tags: tags,
Branches: branches,
@@ -86,8 +107,10 @@ func (g *GitHandler) Refs(w http.ResponseWriter, r *http.Request) {
func (g *GitHandler) Tree(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
+ ref := mux.Vars(r)["ref"]
gitList := &templates.GitItemPage{
Name: name,
+ Ref: ref,
GitItemBase: &templates.GitItemTreePage{},
}
templates.WritePageTemplate(w, gitList)
@@ -95,8 +118,9 @@ func (g *GitHandler) Tree(w http.ResponseWriter, r *http.Request) {
func (g *GitHandler) Log(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
+ ref := mux.Vars(r)["ref"]
- commits, err := g.gitService.ListCommits(name)
+ commits, err := g.gitService.ListCommits(name, ref)
if err != nil {
slog.Error("Error loading commits", "error", err)
return
@@ -104,6 +128,7 @@ func (g *GitHandler) Log(w http.ResponseWriter, r *http.Request) {
gitList := &templates.GitItemPage{
Name: name,
+ Ref: ref,
GitItemBase: &templates.GitItemLogPage{
Commits: commits,
},