Skip to content

Commit

Permalink
Merge pull request #68 from wmalik/trim_spaces_desc
Browse files Browse the repository at this point in the history
Trim spaces in repo description, print error when repo not managed by ogit
  • Loading branch information
wmalik committed Mar 15, 2022
2 parents ec41bca + fbaa621 commit 2206373
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion internal/browser/repolistitem.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"log"
"path"
"strings"

"github.com/wmalik/ogit/internal/db"
"github.com/wmalik/ogit/internal/gitutils"
Expand All @@ -23,7 +24,7 @@ func newRepoItem(repo *db.Repository, storageBasePath string) repoItem {
}

func (i repoItem) Title() string { return i.Repository.Title }
func (i repoItem) Description() string { return i.Repository.Description }
func (i repoItem) Description() string { return strings.TrimSpace(i.Repository.Description) }
func (i repoItem) FilterValue() string { return i.Repository.Title + i.Repository.Description }
func (i repoItem) StoragePath() string {
return i.repoStoragePath
Expand Down
2 changes: 1 addition & 1 deletion internal/browser/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func listItemDelegate(storagePath string) list.DefaultDelegate {
d.SetSpacing(0)
d.UpdateFunc = func(msg tea.Msg, m *list.Model) tea.Cmd {
if selected, ok := m.SelectedItem().(repoItem); ok {
return m.NewStatusMessage(selected.Repository.Description)
return m.NewStatusMessage(selected.Description())
}
return nil
}
Expand Down
5 changes: 4 additions & 1 deletion internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/logger"
)

type Database struct {
DB *gorm.DB
}

func NewDB(dbPath string) (*Database, error) {
db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
})
if err != nil {
return nil, err
}
Expand Down
4 changes: 4 additions & 0 deletions internal/repocommands/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const (
func HandleURLCommands(ctx context.Context, command Command) error {
repo, err := findRepositoryCWD(ctx)
if err != nil {
if err.Error() == "record not found" {
fmt.Println("error: repository not managed by ogit")
return nil
}
return err
}

Expand Down

0 comments on commit 2206373

Please sign in to comment.