summaryrefslogtreecommitdiff
path: root/dumpVersions.go
blob: ff67c751369f9f4713be9e2854931206d480c38a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package gowit

import (
	"fmt"
	"os"
	"strconv"
	"strings"
	"time"

	"go.wit.com/lib/gui/repolist"
	"go.wit.com/log"
)

func DumpVersions(view *repolist.RepoList) {
	f, _ := os.OpenFile("/tmp/go.wit.com.versions", os.O_WRONLY|os.O_CREATE, 0600)
	defer f.Close()
	for _, sec := range allsections {
		for _, wrepo := range sec.witRepos {
			var r *repolist.RepoRow
			r = view.FindRepo(wrepo.path.String())
			if r == nil {
				log.Info("repo not scanned for some reason", wrepo.path.String())
				continue
			}
			lastTag := r.LastTag()
			result := r.Status.Run([]string{"git", "log", "-1", "--format=%at", lastTag})
			out := strings.Join(result.Stdout, "\n")
			out = strings.TrimSpace(out)

			// Convert the string to an integer
			gitTagTimestampInt, err := strconv.ParseInt(out, 10, 64)
			if err != nil {
				fmt.Println("Error converting timestamp:", err)
				return
			}

			// Parse the Unix timestamp into a time.Time object
			gitTagDate := time.Unix(gitTagTimestampInt, 0)

			// Get the current time
			currentTime := time.Now()

			// Calculate the duration between the git tag date and the current time
			duration := currentTime.Sub(gitTagDate)

			// s := fmt.Sprint(duration)
			// fmt.Println("Duration since the git tag date:", s)

			// fmt.Println("Default formatting:", duration.String())
			// fmt.Println("Custom formatting:", formatDuration(duration))
			log.Warn("found:", wrepo.path.String(), lastTag, out, formatDuration(duration))
			fmt.Fprintln(f, wrepo.path.String(), lastTag, out)
			//wrepo.path.Show()
		}
	}
}