From 46159f9e02242f7abf877a4a41c122222e3b0538 Mon Sep 17 00:00:00 2001 From: ahh Date: Fri, 7 Dec 2018 16:09:52 -0500 Subject: [PATCH] refactor: rename airtableDB to airtabledb --- cmd/cmd_airtable.go | 114 +++++++++--------- .../airtabledb.go} | 2 +- pkg/repo/models.go | 26 ++-- 3 files changed, 71 insertions(+), 71 deletions(-) rename pkg/{airtableDB/airtableDB.go => airtabledb/airtabledb.go} (99%) diff --git a/cmd/cmd_airtable.go b/cmd/cmd_airtable.go index 85431d4c6..d05ca07c7 100644 --- a/cmd/cmd_airtable.go +++ b/cmd/cmd_airtable.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/pflag" "github.com/spf13/viper" "go.uber.org/zap" - "moul.io/depviz/pkg/airtableDB" + "moul.io/depviz/pkg/airtabledb" "moul.io/depviz/pkg/repo" ) @@ -151,7 +151,7 @@ func airtableSync(opts *airtableOptions) error { } // fetch remote data - cache := airtableDB.DB{} + cache := airtabledb.DB{} table := at.Table(opts.ProvidersTableName) if err := table.List(&cache.Providers, &airtable.Options{}); err != nil { return err @@ -177,13 +177,13 @@ func airtableSync(opts *airtableOptions) error { return err } - unmatched := airtableDB.DB{ - Providers: airtableDB.ProviderRecords{}, - Labels: airtableDB.LabelRecords{}, - Accounts: airtableDB.AccountRecords{}, - Repositories: airtableDB.RepositoryRecords{}, - Milestones: airtableDB.MilestoneRecords{}, - Issues: airtableDB.IssueRecords{}, + unmatched := airtabledb.DB{ + Providers: airtabledb.ProviderRecords{}, + Labels: airtabledb.LabelRecords{}, + Accounts: airtabledb.AccountRecords{}, + Repositories: airtabledb.RepositoryRecords{}, + Milestones: airtabledb.MilestoneRecords{}, + Issues: airtabledb.IssueRecords{}, } // @@ -197,10 +197,10 @@ func airtableSync(opts *airtableOptions) error { for idx, atEntry := range cache.Providers { if atEntry.Fields.ID == dbEntry.ID { if atEntry.Equals(dbRecord) { - cache.Providers[idx].State = airtableDB.StateUnchanged + cache.Providers[idx].State = airtabledb.StateUnchanged } else { cache.Providers[idx].Fields = dbRecord.Fields - cache.Providers[idx].State = airtableDB.StateChanged + cache.Providers[idx].State = airtabledb.StateChanged } matched = true break @@ -218,10 +218,10 @@ func airtableSync(opts *airtableOptions) error { for idx, atEntry := range cache.Labels { if atEntry.Fields.ID == dbEntry.ID { if atEntry.Equals(dbRecord) { - cache.Labels[idx].State = airtableDB.StateUnchanged + cache.Labels[idx].State = airtabledb.StateUnchanged } else { cache.Labels[idx].Fields = dbRecord.Fields - cache.Labels[idx].State = airtableDB.StateChanged + cache.Labels[idx].State = airtabledb.StateChanged } matched = true break @@ -239,10 +239,10 @@ func airtableSync(opts *airtableOptions) error { for idx, atEntry := range cache.Accounts { if atEntry.Fields.ID == dbEntry.ID { if atEntry.Equals(dbRecord) { - cache.Accounts[idx].State = airtableDB.StateUnchanged + cache.Accounts[idx].State = airtabledb.StateUnchanged } else { cache.Accounts[idx].Fields = dbRecord.Fields - cache.Accounts[idx].State = airtableDB.StateChanged + cache.Accounts[idx].State = airtabledb.StateChanged } matched = true break @@ -260,10 +260,10 @@ func airtableSync(opts *airtableOptions) error { for idx, atEntry := range cache.Repositories { if atEntry.Fields.ID == dbEntry.ID { if atEntry.Equals(dbRecord) { - cache.Repositories[idx].State = airtableDB.StateUnchanged + cache.Repositories[idx].State = airtabledb.StateUnchanged } else { cache.Repositories[idx].Fields = dbRecord.Fields - cache.Repositories[idx].State = airtableDB.StateChanged + cache.Repositories[idx].State = airtabledb.StateChanged } matched = true break @@ -281,10 +281,10 @@ func airtableSync(opts *airtableOptions) error { for idx, atEntry := range cache.Milestones { if atEntry.Fields.ID == dbEntry.ID { if atEntry.Equals(dbRecord) { - cache.Milestones[idx].State = airtableDB.StateUnchanged + cache.Milestones[idx].State = airtabledb.StateUnchanged } else { cache.Milestones[idx].Fields = dbRecord.Fields - cache.Milestones[idx].State = airtableDB.StateChanged + cache.Milestones[idx].State = airtabledb.StateChanged } matched = true break @@ -302,10 +302,10 @@ func airtableSync(opts *airtableOptions) error { for idx, atEntry := range cache.Issues { if atEntry.Fields.ID == dbEntry.ID { if atEntry.Equals(dbRecord) { - cache.Issues[idx].State = airtableDB.StateUnchanged + cache.Issues[idx].State = airtabledb.StateUnchanged } else { cache.Issues[idx].Fields = dbRecord.Fields - cache.Issues[idx].State = airtableDB.StateChanged + cache.Issues[idx].State = airtabledb.StateChanged } matched = true break @@ -327,22 +327,22 @@ func airtableSync(opts *airtableOptions) error { if err := table.Create(&entry); err != nil { return err } - entry.State = airtableDB.StateNew + entry.State = airtabledb.StateNew cache.Providers = append(cache.Providers, entry) } for _, entry := range cache.Providers { var err error switch entry.State { - case airtableDB.StateUnknown: + case airtabledb.StateUnknown: err = table.Delete(&entry) zap.L().Debug("delete airtable entry", zap.String("type", "provider"), zap.Stringer("entry", entry), zap.Error(err)) - case airtableDB.StateChanged: + case airtabledb.StateChanged: err = table.Update(&entry) zap.L().Debug("update airtable entry", zap.String("type", "provider"), zap.Stringer("entry", entry), zap.Error(err)) - case airtableDB.StateUnchanged: + case airtabledb.StateUnchanged: zap.L().Debug("unchanged airtable entry", zap.String("type", "provider"), zap.Stringer("entry", entry), zap.Error(err)) // do nothing - case airtableDB.StateNew: + case airtabledb.StateNew: zap.L().Debug("new airtable entry", zap.String("type", "provider"), zap.Stringer("entry", entry), zap.Error(err)) // do nothing } @@ -355,22 +355,22 @@ func airtableSync(opts *airtableOptions) error { if err := table.Create(&entry); err != nil { return err } - entry.State = airtableDB.StateNew + entry.State = airtabledb.StateNew cache.Labels = append(cache.Labels, entry) } for _, entry := range cache.Labels { var err error switch entry.State { - case airtableDB.StateUnknown: + case airtabledb.StateUnknown: err = table.Delete(&entry) zap.L().Debug("delete airtable entry", zap.String("type", "label"), zap.Stringer("entry", entry), zap.Error(err)) - case airtableDB.StateChanged: + case airtabledb.StateChanged: err = table.Update(&entry) zap.L().Debug("update airtable entry", zap.String("type", "label"), zap.Stringer("entry", entry), zap.Error(err)) - case airtableDB.StateUnchanged: + case airtabledb.StateUnchanged: zap.L().Debug("unchanged airtable entry", zap.String("type", "label"), zap.Stringer("entry", entry), zap.Error(err)) // do nothing - case airtableDB.StateNew: + case airtabledb.StateNew: zap.L().Debug("new airtable entry", zap.String("type", "label"), zap.Stringer("entry", entry), zap.Error(err)) // do nothing } @@ -383,22 +383,22 @@ func airtableSync(opts *airtableOptions) error { if err := table.Create(&entry); err != nil { return err } - entry.State = airtableDB.StateNew + entry.State = airtabledb.StateNew cache.Accounts = append(cache.Accounts, entry) } for _, entry := range cache.Accounts { var err error switch entry.State { - case airtableDB.StateUnknown: + case airtabledb.StateUnknown: err = table.Delete(&entry) zap.L().Debug("delete airtable entry", zap.String("type", "account"), zap.Stringer("entry", entry), zap.Error(err)) - case airtableDB.StateChanged: + case airtabledb.StateChanged: err = table.Update(&entry) zap.L().Debug("update airtable entry", zap.String("type", "account"), zap.Stringer("entry", entry), zap.Error(err)) - case airtableDB.StateUnchanged: + case airtabledb.StateUnchanged: zap.L().Debug("unchanged airtable entry", zap.String("type", "account"), zap.Stringer("entry", entry), zap.Error(err)) // do nothing - case airtableDB.StateNew: + case airtabledb.StateNew: zap.L().Debug("new airtable entry", zap.String("type", "account"), zap.Stringer("entry", entry), zap.Error(err)) // do nothing } @@ -411,22 +411,22 @@ func airtableSync(opts *airtableOptions) error { if err := table.Create(&entry); err != nil { return err } - entry.State = airtableDB.StateNew + entry.State = airtabledb.StateNew cache.Repositories = append(cache.Repositories, entry) } for _, entry := range cache.Repositories { var err error switch entry.State { - case airtableDB.StateUnknown: + case airtabledb.StateUnknown: err = table.Delete(&entry) zap.L().Debug("delete airtable entry", zap.String("type", "repository"), zap.Stringer("entry", entry), zap.Error(err)) - case airtableDB.StateChanged: + case airtabledb.StateChanged: err = table.Update(&entry) zap.L().Debug("update airtable entry", zap.String("type", "repository"), zap.Stringer("entry", entry), zap.Error(err)) - case airtableDB.StateUnchanged: + case airtabledb.StateUnchanged: zap.L().Debug("unchanged airtable entry", zap.String("type", "repository"), zap.Stringer("entry", entry), zap.Error(err)) // do nothing - case airtableDB.StateNew: + case airtabledb.StateNew: zap.L().Debug("new airtable entry", zap.String("type", "repository"), zap.Stringer("entry", entry), zap.Error(err)) // do nothing } @@ -439,22 +439,22 @@ func airtableSync(opts *airtableOptions) error { if err := table.Create(&entry); err != nil { return err } - entry.State = airtableDB.StateNew + entry.State = airtabledb.StateNew cache.Milestones = append(cache.Milestones, entry) } for _, entry := range cache.Milestones { var err error switch entry.State { - case airtableDB.StateUnknown: + case airtabledb.StateUnknown: err = table.Delete(&entry) zap.L().Debug("delete airtable entry", zap.String("type", "milestone"), zap.Stringer("entry", entry), zap.Error(err)) - case airtableDB.StateChanged: + case airtabledb.StateChanged: err = table.Update(&entry) zap.L().Debug("update airtable entry", zap.String("type", "milestone"), zap.Stringer("entry", entry), zap.Error(err)) - case airtableDB.StateUnchanged: + case airtabledb.StateUnchanged: zap.L().Debug("unchanged airtable entry", zap.String("type", "milestone"), zap.Stringer("entry", entry), zap.Error(err)) // do nothing - case airtableDB.StateNew: + case airtabledb.StateNew: zap.L().Debug("new airtable entry", zap.String("type", "milestone"), zap.Stringer("entry", entry), zap.Error(err)) // do nothing } @@ -467,22 +467,22 @@ func airtableSync(opts *airtableOptions) error { if err := table.Create(&entry); err != nil { return err } - entry.State = airtableDB.StateNew + entry.State = airtabledb.StateNew cache.Issues = append(cache.Issues, entry) } for _, entry := range cache.Issues { var err error switch entry.State { - case airtableDB.StateUnknown: + case airtabledb.StateUnknown: err = table.Delete(&entry) zap.L().Debug("delete airtable entry", zap.String("type", "issue"), zap.Stringer("entry", entry), zap.Error(err)) - case airtableDB.StateChanged: + case airtabledb.StateChanged: err = table.Update(&entry) zap.L().Debug("update airtable entry", zap.String("type", "issue"), zap.Stringer("entry", entry), zap.Error(err)) - case airtableDB.StateUnchanged: + case airtabledb.StateUnchanged: zap.L().Debug("unchanged airtable entry", zap.String("type", "issue"), zap.Stringer("entry", entry), zap.Error(err)) // do nothing - case airtableDB.StateNew: + case airtabledb.StateNew: zap.L().Debug("new airtable entry", zap.String("type", "issue"), zap.Stringer("entry", entry), zap.Error(err)) // do nothing } @@ -493,27 +493,27 @@ func airtableSync(opts *airtableOptions) error { // fmt.Println("------- providers") for _, entry := range cache.Providers { - fmt.Println(entry.ID, airtableDB.StateString[entry.State], entry.Fields.ID) + fmt.Println(entry.ID, airtabledb.StateString[entry.State], entry.Fields.ID) } fmt.Println("------- labels") for _, entry := range cache.Labels { - fmt.Println(entry.ID, airtableDB.StateString[entry.State], entry.Fields.ID) + fmt.Println(entry.ID, airtabledb.StateString[entry.State], entry.Fields.ID) } fmt.Println("------- accounts") for _, entry := range cache.Accounts { - fmt.Println(entry.ID, airtableDB.StateString[entry.State], entry.Fields.ID) + fmt.Println(entry.ID, airtabledb.StateString[entry.State], entry.Fields.ID) } fmt.Println("------- repositories") for _, entry := range cache.Repositories { - fmt.Println(entry.ID, airtableDB.StateString[entry.State], entry.Fields.ID) + fmt.Println(entry.ID, airtabledb.StateString[entry.State], entry.Fields.ID) } fmt.Println("------- milestones") for _, entry := range cache.Milestones { - fmt.Println(entry.ID, airtableDB.StateString[entry.State], entry.Fields.ID) + fmt.Println(entry.ID, airtabledb.StateString[entry.State], entry.Fields.ID) } fmt.Println("------- issues") for _, entry := range cache.Issues { - fmt.Println(entry.ID, airtableDB.StateString[entry.State], entry.Fields.ID) + fmt.Println(entry.ID, airtabledb.StateString[entry.State], entry.Fields.ID) } fmt.Println("-------") diff --git a/pkg/airtableDB/airtableDB.go b/pkg/airtabledb/airtabledb.go similarity index 99% rename from pkg/airtableDB/airtableDB.go rename to pkg/airtabledb/airtabledb.go index 566767538..942c07df2 100644 --- a/pkg/airtableDB/airtableDB.go +++ b/pkg/airtabledb/airtabledb.go @@ -1,4 +1,4 @@ -package airtableDB +package airtabledb import ( "encoding/json" diff --git a/pkg/repo/models.go b/pkg/repo/models.go index 6cbf18d8f..3f2fe6017 100644 --- a/pkg/repo/models.go +++ b/pkg/repo/models.go @@ -6,7 +6,7 @@ import ( "time" "github.com/lib/pq" - "moul.io/depviz/pkg/airtableDB" + "moul.io/depviz/pkg/airtabledb" ) // @@ -42,8 +42,8 @@ type Repository struct { OwnerID string `json:"owner-id"` } -func (p Repository) ToRecord(cache airtableDB.DB) *airtableDB.RepositoryRecord { - record := airtableDB.RepositoryRecord{} +func (p Repository) ToRecord(cache airtabledb.DB) *airtabledb.RepositoryRecord { + record := airtabledb.RepositoryRecord{} // base record.Fields.ID = p.ID @@ -88,8 +88,8 @@ type Provider struct { Driver string `json:"driver"` // github, gitlab, unknown } -func (p Provider) ToRecord(cache airtableDB.DB) *airtableDB.ProviderRecord { - record := airtableDB.ProviderRecord{} +func (p Provider) ToRecord(cache airtabledb.DB) *airtabledb.ProviderRecord { + record := airtabledb.ProviderRecord{} // base record.Fields.ID = p.ID @@ -130,8 +130,8 @@ type Milestone struct { RepositoryID string `json:"repository-id"` } -func (p Milestone) ToRecord(cache airtableDB.DB) *airtableDB.MilestoneRecord { - record := airtableDB.MilestoneRecord{} +func (p Milestone) ToRecord(cache airtabledb.DB) *airtabledb.MilestoneRecord { + record := airtabledb.MilestoneRecord{} // base record.Fields.ID = p.ID record.Fields.CreatedAt = p.CreatedAt @@ -204,8 +204,8 @@ func (i Issue) String() string { return string(out) } -func (p Issue) ToRecord(cache airtableDB.DB) *airtableDB.IssueRecord { - record := airtableDB.IssueRecord{} +func (p Issue) ToRecord(cache airtabledb.DB) *airtabledb.IssueRecord { + record := airtabledb.IssueRecord{} // base record.Fields.ID = p.ID record.Fields.CreatedAt = p.CreatedAt @@ -261,8 +261,8 @@ type Label struct { Description string `json:"description"` } -func (p Label) ToRecord(cache airtableDB.DB) *airtableDB.LabelRecord { - record := airtableDB.LabelRecord{} +func (p Label) ToRecord(cache airtabledb.DB) *airtabledb.LabelRecord { + record := airtabledb.LabelRecord{} // base record.Fields.ID = p.ID @@ -306,8 +306,8 @@ type Account struct { ProviderID string `json:"provider-id"` } -func (p Account) ToRecord(cache airtableDB.DB) *airtableDB.AccountRecord { - record := airtableDB.AccountRecord{} +func (p Account) ToRecord(cache airtabledb.DB) *airtabledb.AccountRecord { + record := airtabledb.AccountRecord{} // base record.Fields.ID = p.ID record.Fields.CreatedAt = p.CreatedAt