Skip to content

Commit

Permalink
refactor: rename airtableDB to airtabledb
Browse files Browse the repository at this point in the history
  • Loading branch information
ahamidullah committed Dec 7, 2018
1 parent 80cef1b commit 46159f9
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 71 deletions.
114 changes: 57 additions & 57 deletions cmd/cmd_airtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand All @@ -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{},
}

//
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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("-------")

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package airtableDB
package airtabledb

import (
"encoding/json"
Expand Down
26 changes: 13 additions & 13 deletions pkg/repo/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/lib/pq"
"moul.io/depviz/pkg/airtableDB"
"moul.io/depviz/pkg/airtabledb"
)

//
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 46159f9

Please sign in to comment.