Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim spaces in repo description, print error when repo not managed by ogit #68

Merged
merged 3 commits into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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