Skip to content

Commit

Permalink
Feat: Show commit count in repo info
Browse files Browse the repository at this point in the history
  • Loading branch information
torbratsberg committed Mar 2, 2022
1 parent b44c084 commit 204ba12
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
48 changes: 29 additions & 19 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ type ClientConfig struct {
}

type Repo struct {
Name string
Branches []string
Remotes []string
Tags []map[string]string
Name string
Branches []string
Remotes []string
Tags []map[string]string
CommitCount int
}

type Parameter struct {
Expand Down Expand Up @@ -77,33 +78,42 @@ func getConfig() (cfg *ClientConfig) {
var gitorConfig ClientConfig = *getConfig()

func printRepoInfo(repo Repo) {
res := ""

// Print repo name
fmt.Println(repo.Name)
res += repo.Name + "\n"

// Print commit count
res += fmt.Sprintf("\n Commit count: %d\n", repo.CommitCount)

// Print branches
fmt.Printf("\n Branches:\n")
res += "\n Branches:\n"
for i := range repo.Branches {
fmt.Printf(" ")
fmt.Println(repo.Branches[i])
res += " "
res += repo.Branches[i] + "\n"
}

// Print remotes
fmt.Printf("\n Remotes:\n")
res += "\n Remotes:\n"
for i := range repo.Remotes {
fmt.Printf(" ")
fmt.Println(repo.Remotes[i])
res += " "
res += repo.Remotes[i] + "\n"
}

// Print tags
fmt.Printf("\n Tags:\n")
for i := range repo.Tags {
fmt.Printf(" ")
fmt.Printf(
"%s: %s\n",
repo.Tags[i]["hash"],
repo.Tags[i]["name"],
)
if len(repo.Tags) > 0 {
res += "\n Tags:\n"
for i := range repo.Tags {
res += " "
res += fmt.Sprintf(
"%s: %s\n",
repo.Tags[i]["hash"],
repo.Tags[i]["name"],
)
}
}

fmt.Println(res)
}

func encodeToken() string {
Expand Down
17 changes: 13 additions & 4 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ import (
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-yaml/yaml"
)

type Repo struct {
Name string
Branches []string
Remotes []string
Tags []map[string]string
Name string
Branches []string
Remotes []string
Tags []map[string]string
CommitCount int
}

type ServerConfig struct {
Expand Down Expand Up @@ -172,6 +174,13 @@ func getRepository(res http.ResponseWriter, req *http.Request) {
return nil
})

// Get the commit count
commits, err := repo.CommitObjects()
commits.ForEach(func(obj *object.Commit) error {
repoRes.CommitCount++
return nil
})

encode := json.NewEncoder(res)
encode.Encode(repoRes)
}
Expand Down

0 comments on commit 204ba12

Please sign in to comment.