Skip to content

Commit

Permalink
fix(ui): show repo update time for new repos
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed May 2, 2023
1 parent 3dfecd9 commit d32879a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
5 changes: 5 additions & 0 deletions server/backend/repo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package backend

import (
"time"

"github.com/charmbracelet/soft-serve/git"
)

Expand Down Expand Up @@ -78,6 +80,9 @@ type Repository interface {
IsMirror() bool
// IsHidden returns whether the repository is hidden.
IsHidden() bool
// UpdatedAt returns the time the repository was last updated.
// If the repository has never been updated, it returns the time it was created.
UpdatedAt() time.Time
// Open returns the underlying git.Repository.
Open() (*git.Repository, error)
}
21 changes: 21 additions & 0 deletions server/backend/sqlite/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sqlite

import (
"context"
"time"

"github.com/charmbracelet/soft-serve/git"
"github.com/charmbracelet/soft-serve/server/backend"
Expand Down Expand Up @@ -100,3 +101,23 @@ func (r *Repo) IsHidden() bool {

return hidden
}

// UpdatedAt returns the repository's last update time.
func (r *Repo) UpdatedAt() time.Time {
rr, err := git.Open(r.path)
if err == nil {
t, err := rr.LatestCommitTime()
if err == nil {
return t
}
}

var updatedAt time.Time
if err := wrapTx(r.db, context.Background(), func(tx *sqlx.Tx) error {
return tx.Get(&updatedAt, "SELECT updated_at FROM repo WHERE name = ?", r.name)
}); err != nil {
return time.Time{}
}

return updatedAt
}
8 changes: 2 additions & 6 deletions ui/pages/selection/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,9 @@ type Item struct {

// New creates a new Item.
func NewItem(repo backend.Repository, cfg *config.Config) (Item, error) {
r, err := repo.Open()
if err != nil {
return Item{}, err
}
var lastUpdate *time.Time
lu, err := r.LatestCommitTime()
if err == nil {
lu := repo.UpdatedAt()
if !lu.IsZero() {
lastUpdate = &lu
}
return Item{
Expand Down

0 comments on commit d32879a

Please sign in to comment.