2024-01-15 20:39:35 +00:00
|
|
|
package projects
|
2024-01-14 15:33:15 +00:00
|
|
|
|
|
|
|
import "github.com/pterm/pterm"
|
|
|
|
|
|
|
|
func (p *Project) GetGitInfo() string {
|
|
|
|
repo := p.GetRepo()
|
|
|
|
if repo == nil {
|
|
|
|
return "No Repo"
|
|
|
|
}
|
|
|
|
|
|
|
|
var str string
|
|
|
|
str += "\n" + pterm.LightRed("Project: ") + pterm.Bold.Sprint(p.Name) + "\n"
|
|
|
|
|
|
|
|
head, _ := repo.Head()
|
|
|
|
branch := head.Name().String()[11:]
|
|
|
|
b, _ := repo.Branch(branch)
|
|
|
|
if b != nil {
|
|
|
|
str += pterm.LightCyan("Branch: ") + pterm.Bold.Sprint(b.Name) + "\n"
|
|
|
|
} else {
|
|
|
|
str += pterm.LightCyan("NEW Branch: ") + pterm.Bold.Sprint(branch) + "\n"
|
|
|
|
}
|
|
|
|
|
|
|
|
commit, _ := repo.CommitObject(head.Hash())
|
|
|
|
str += "\n" + commit.String()
|
|
|
|
|
2024-12-27 22:42:44 +00:00
|
|
|
str += pterm.LightMagenta("Git: ") + pterm.Bold.Sprint(p.HTTPURLToRepo) + "\n"
|
2024-01-14 15:33:15 +00:00
|
|
|
|
|
|
|
if remotes, _ := repo.Remotes(); len(remotes) > 0 {
|
|
|
|
str += pterm.LightBlue("Remote: ") + pterm.Bold.Sprint(remotes[0].Config().URLs[0])
|
|
|
|
}
|
|
|
|
|
|
|
|
return pterm.DefaultBox.
|
|
|
|
WithLeftPadding(5).WithRightPadding(5).
|
|
|
|
WithBoxStyle(&pterm.Style{pterm.FgLightBlue}).
|
|
|
|
WithTitle(pterm.Bold.Sprint(pterm.LightGreen("Project Git Status"))).
|
|
|
|
Sprint(str)
|
|
|
|
}
|