github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/table/builds/helpers.go (about) 1 package buildsTable 2 3 import ( 4 "fmt" 5 "strings" 6 "time" 7 8 "github.com/jedib0t/go-pretty/v6/table" 9 "github.com/taubyte/go-interfaces/services/patrick" 10 authHttp "github.com/taubyte/tau/clients/http/auth" 11 "golang.org/x/text/cases" 12 "golang.org/x/text/language" 13 ) 14 15 func row(authClient *authHttp.Client, job *patrick.Job, timeZone *time.Location, showCommit bool) (table.Row, error) { 16 unixTime := time.Unix(job.Timestamp, 0).In(timeZone) 17 date := unixTime.Format("01/02/06") 18 time := unixTime.Format("3:04 PM") 19 20 repo, err := authClient.GetRepositoryById(fmt.Sprintf("%d", job.Meta.Repository.ID)) 21 if err != nil { 22 return nil, err 23 } 24 25 repoType := "Unknown" 26 name := repo.Get().Name() 27 nameSplit := strings.SplitN(name, "_", 3) 28 if nameSplit[0] == "tb" { 29 switch nameSplit[1] { 30 case "library", "website", "code": 31 repoType = cases.Title(language.English).String(nameSplit[1]) 32 default: 33 repoType = "Config" 34 } 35 } 36 37 var lastColumn interface{} 38 if showCommit { 39 lastColumn = job.Meta.HeadCommit.ID 40 } else { 41 lastColumn = job.Id 42 } 43 44 return table.Row{ 45 job.Status.Unicode(), 46 date + "\n" + time, 47 repoType, 48 lastColumn, 49 }, nil 50 } 51 52 type jobArray []*patrick.Job 53 54 func (a jobArray) Len() int { return len(a) } 55 func (a jobArray) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 56 func (a jobArray) Less(i, j int) bool { return a[i].Timestamp > a[j].Timestamp } 57 func (a jobArray) String() (s string) { 58 sep := "" // for printing separating commas 59 for _, el := range a { 60 s += sep 61 sep = ", " 62 s += fmt.Sprintf("%d", el.Timestamp) 63 } 64 return 65 }