summaryrefslogtreecommitdiff
path: root/tagWindow.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-02-22 15:29:22 -0600
committerJeff Carr <[email protected]>2024-02-22 15:29:22 -0600
commitcd5f1d9d0f52196d6ea07684a4307369893911bd (patch)
tree7338ba80799ad96b25eae2fa55bcbca211c48fc7 /tagWindow.go
parent5aaf02ee3aeafc17a70ddc32619a17ae19a6f1ed (diff)
add NewestTag() and Tag.Age()
Diffstat (limited to 'tagWindow.go')
-rw-r--r--tagWindow.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/tagWindow.go b/tagWindow.go
index 05d9087..c630af7 100644
--- a/tagWindow.go
+++ b/tagWindow.go
@@ -5,6 +5,8 @@ import (
"regexp"
"slices"
"strings"
+ "sync"
+ "time"
"go.wit.com/gui"
"go.wit.com/log"
@@ -312,3 +314,59 @@ func (rs *RepoStatus) LocalTagExists(findname string) bool {
}
return false
}
+
+func (t *Tag) Age() time.Duration {
+ const gitLayout = "Mon Jan 2 15:04:05 2006 -0700"
+ tagTime, _ := time.Parse(gitLayout, t.date.String())
+ return time.Since(tagTime)
+}
+
+func (t *Tag) Name() string {
+ return t.tag.String()
+}
+
+func (t *Tag) getDate() (time.Time, error) {
+ const gitLayout = "Mon Jan 2 15:04:05 2006 -0700"
+ tagTime, err := time.Parse(gitLayout, t.date.String())
+
+ if err != nil {
+ log.Log(REPOWARN, "tag date err", t.ref.String(), t.tag.String(), err)
+ return time.Now(), err
+ }
+ return tagTime, nil
+}
+
+func (rs *RepoStatus) NewestTag() *Tag {
+ var newest *Tag
+ var newestTime time.Time
+ var tagTime time.Time
+ var err error
+ var allTags []*Tag
+ var mu sync.Mutex
+
+ allTags = make([]*Tag, 0, 0)
+ junk := rs.Tags.ListAll()
+ allTags = append(allTags, junk...)
+ for _, t := range allTags {
+ mu.Lock()
+ if tagTime, err = t.getDate(); err != nil {
+ mu.Unlock()
+ continue
+ }
+
+ // log.Log(REPOWARN, "tag", t.ref.String(), t.date.String(), t.tag.String())
+ // if this is the first tag, use it
+ if newest == nil {
+ newestTime = tagTime
+ newest = t
+ }
+
+ // if the tag date is after the newest date, it's newer so use this tag
+ if tagTime.After(newestTime) {
+ newestTime = tagTime
+ newest = t
+ }
+ mu.Unlock()
+ }
+ return newest
+}