52 lines
1.2 KiB
Go
52 lines
1.2 KiB
Go
// Copyright 2023 Michael Amann and contributors
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package shared
|
|
|
|
import (
|
|
"strconv"
|
|
|
|
"go.kle.li/tools/go-meta/internal/utils"
|
|
)
|
|
|
|
type PackageMetadata struct {
|
|
IsTag bool
|
|
Branch string
|
|
DefaultBranch string
|
|
Version string
|
|
CommitSha string
|
|
CommitTime string
|
|
GoCommitVersion string
|
|
}
|
|
|
|
func (p *PackageMetadata) GetCommitShaSlug(length int) (bool, string) {
|
|
if utils.IsDefault(p.CommitSha, NoCommit) {
|
|
return false, ""
|
|
}
|
|
return utils.StringSlug(p.CommitSha, length)
|
|
}
|
|
|
|
func (p *PackageMetadata) IsDefaultBranch() bool {
|
|
if !utils.IsDefault(p.Branch, NoBranch) && !utils.IsDefault(p.DefaultBranch, NoDefaultBranch) && p.Branch == p.DefaultBranch {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (p *PackageMetadata) GetHumanCommit() string {
|
|
return utils.QuickStringBuilderDirect("Git", [][3]string{
|
|
{"SHA", p.CommitSha, NoCommit},
|
|
{"Time", p.CommitTime, NoTime},
|
|
{"Branch", p.Branch, NoBranch},
|
|
}, nil)
|
|
}
|
|
|
|
func (p *PackageMetadata) GetHumanVersion() string {
|
|
return utils.QuickStringBuilderDirect("Versions", [][3]string{
|
|
{"Version", p.Version, NoVersion},
|
|
{"GoCommitVersion", p.GoCommitVersion, NoVersion},
|
|
}, []string{
|
|
"IsTag: " + strconv.FormatBool(p.IsTag),
|
|
})
|
|
}
|