Skip to content

Commit a1a20ad

Browse files
authored
removes row restriction for boostrap load (#25)
Fixes #24
2 parents f5cad86 + 13e17d3 commit a1a20ad

File tree

4 files changed

+88
-16
lines changed

4 files changed

+88
-16
lines changed

cmd/bootstrap/main.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ const (
1818
apiTokenEnvVar = "FOSSA_API_TOKEN"
1919
spreadsheetEnvVar = "MD_WORKSHEET"
2020
googleWorkspaceCredentials = "WORKSPACE_CREDENTIALS_FILE"
21-
defaultReadRange = "Active!A1:J2100"
2221
defaultDBPath = "maintainers.db"
2322
defaultMaxBackups = 5
2423
backupFileExt = ".bak"
2524
)
2625

2726
func main() {
28-
var readRange string
2927
var dbPath string
3028
var seed bool
3129
var doBackup bool
@@ -64,15 +62,14 @@ func main() {
6462
pruneOldBackups(dbPath, maxBackups)
6563
}
6664
}
67-
_, err := db.BootstrapSQLite(dbPath, spreadsheetID, readRange, credentialsPath, fossaToken, seed)
65+
_, err := db.BootstrapSQLite(dbPath, spreadsheetID, credentialsPath, fossaToken, seed)
6866
if err != nil {
6967
log.Fatalf("bootstrap failed: %v", err)
7068
}
7169

7270
},
7371
}
7472

75-
rootCmd.Flags().StringVar(&readRange, "range", defaultReadRange, "Google Sheet read range")
7673
rootCmd.Flags().StringVar(&dbPath, "db", defaultDBPath, "Path to SQLite database file")
7774
rootCmd.Flags().BoolVar(&seed, "seed", true, "Whether to load seed data into the database")
7875
rootCmd.Flags().BoolVar(&doBackup, "backup", true, "Whether to create a backup of the database if it exists")

db/bootstrap.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const (
3232
MailingListAddrHdr string = "Mailing List Address"
3333
)
3434

35-
func BootstrapSQLite(dbPath, spreadsheetID, readRange, worksheetCredentialsPath, fossaToken string, seed bool) (*gorm.DB, error) {
35+
func BootstrapSQLite(dbPath, spreadsheetID, worksheetCredentialsPath, fossaToken string, seed bool) (*gorm.DB, error) {
3636
newLogger := logger.New(
3737
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
3838
logger.Config{
@@ -87,7 +87,7 @@ func BootstrapSQLite(dbPath, spreadsheetID, readRange, worksheetCredentialsPath,
8787
return nil, err
8888
}
8989

90-
if err := loadMaintainersAndProjects(db, spreadsheetID, readRange, worksheetCredentialsPath); err != nil {
90+
if err := loadMaintainersAndProjects(db, spreadsheetID, worksheetCredentialsPath); err != nil {
9191
return nil, fmt.Errorf("bootstrap: failed to load maintainers and projects: %w", err)
9292
}
9393

@@ -102,7 +102,7 @@ func BootstrapSQLite(dbPath, spreadsheetID, readRange, worksheetCredentialsPath,
102102

103103
// Reads the readRange data from spreadsheetID inserts it into db
104104
// The readRange from the worksheet MUST include the header row
105-
func loadMaintainersAndProjects(db *gorm.DB, spreadsheetID, readRange, credentialsPath string) error {
105+
func loadMaintainersAndProjects(db *gorm.DB, spreadsheetID, credentialsPath string) error {
106106
ctx := context.Background()
107107

108108
srv, err := sheets.NewService(
@@ -115,7 +115,7 @@ func loadMaintainersAndProjects(db *gorm.DB, spreadsheetID, readRange, credentia
115115
log.Fatalf("maintainerd: backend: loadMaintainersAndProjects: unable to retrieve Sheets client: %v", err)
116116
}
117117

118-
rows, err := readSheetRows(ctx, srv, spreadsheetID, readRange)
118+
rows, err := readSheetRows(ctx, srv, spreadsheetID)
119119

120120
if err != nil {
121121
log.Fatalf("maintainerd-backend: loadMaintainersAndProjects - readSheetRows: %v", err)
@@ -211,16 +211,18 @@ func loadMaintainersAndProjects(db *gorm.DB, spreadsheetID, readRange, credentia
211211

212212
// readSheetRows returns every row as a map keyed by the header row and carries forward the last non‐empty Project and
213213
// Status values when those cells are blank or missing.
214-
func readSheetRows(ctx context.Context, srv *sheets.Service, spreadsheetID, readRange string) ([]map[string]string, error) {
214+
// The readRange must include the header row.
215+
// The
216+
func readSheetRows(ctx context.Context, srv *sheets.Service, spreadsheetID string) ([]map[string]string, error) {
215217
resp, err := srv.Spreadsheets.Values.
216-
Get(spreadsheetID, readRange).
218+
Get(spreadsheetID, "Active!A:J").
217219
Context(ctx).
218220
Do()
219221
if err != nil {
220-
return nil, fmt.Errorf("db: Using %s:%s unable to retrieve worksheet data: %w", spreadsheetID, readRange, err)
222+
return nil, fmt.Errorf("db: Using %s unable to retrieve worksheet data: %w", spreadsheetID, err)
221223
}
222224
if len(resp.Values) == 0 {
223-
return nil, fmt.Errorf("db: %s:%s worksheet is empty", spreadsheetID, readRange)
225+
return nil, fmt.Errorf("db: %s worksheet is empty", spreadsheetID)
224226
}
225227

226228
// First row → headers
@@ -540,7 +542,7 @@ func FirstOrCreateServiceUser(db *gorm.DB, user fossa.User) (*model.ServiceUser,
540542
ServiceEmail: user.Email,
541543
}
542544

543-
// find a service user with fields in lookup, and if not found, create it with these values"
545+
// find a service user with fields in lookup, and if not found, create it with these values
544546
if err := db.Where(&lookup).Attrs(&create).FirstOrCreate(&su).Error; err != nil {
545547
return nil, fmt.Errorf("loadFossa FirstOrCreateServiceUser failed for %v, err : %w", lookup, err)
546548
}

go.mod

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
module maintainerd
22

3-
go 1.24
3+
go 1.24.0
4+
5+
toolchain go1.24.6
46

57
require (
68
github.com/google/go-github/v55 v55.0.0
@@ -12,6 +14,7 @@ require (
1214
google.golang.org/api v0.238.0
1315
gorm.io/driver/sqlite v1.6.0
1416
gorm.io/gorm v1.30.0
17+
k8s.io/apimachinery v0.34.1
1518
)
1619

1720
require (
@@ -23,9 +26,11 @@ require (
2326
github.com/davecgh/go-spew v1.1.1 // indirect
2427
github.com/felixge/httpsnoop v1.0.4 // indirect
2528
github.com/fsnotify/fsnotify v1.8.0 // indirect
29+
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
2630
github.com/go-logr/logr v1.4.2 // indirect
2731
github.com/go-logr/stdr v1.2.2 // indirect
2832
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
33+
github.com/gogo/protobuf v1.3.2 // indirect
2934
github.com/google/go-querystring v1.1.0 // indirect
3035
github.com/google/s2a-go v0.1.9 // indirect
3136
github.com/google/uuid v1.6.0 // indirect
@@ -34,7 +39,10 @@ require (
3439
github.com/inconshreveable/mousetrap v1.1.0 // indirect
3540
github.com/jinzhu/inflection v1.0.0 // indirect
3641
github.com/jinzhu/now v1.1.5 // indirect
42+
github.com/json-iterator/go v1.1.12 // indirect
3743
github.com/mattn/go-sqlite3 v1.14.22 // indirect
44+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
45+
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
3846
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
3947
github.com/pmezard/go-difflib v1.0.0 // indirect
4048
github.com/sagikazarmark/locafero v0.7.0 // indirect
@@ -43,12 +51,14 @@ require (
4351
github.com/spf13/cast v1.7.1 // indirect
4452
github.com/spf13/pflag v1.0.6 // indirect
4553
github.com/subosito/gotenv v1.6.0 // indirect
54+
github.com/x448/float16 v0.8.4 // indirect
4655
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
4756
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
4857
go.opentelemetry.io/otel v1.36.0 // indirect
4958
go.opentelemetry.io/otel/metric v1.36.0 // indirect
5059
go.opentelemetry.io/otel/trace v1.36.0 // indirect
5160
go.uber.org/multierr v1.10.0 // indirect
61+
go.yaml.in/yaml/v2 v2.4.2 // indirect
5262
golang.org/x/crypto v0.39.0 // indirect
5363
golang.org/x/net v0.41.0 // indirect
5464
golang.org/x/sys v0.33.0 // indirect
@@ -57,4 +67,7 @@ require (
5767
google.golang.org/grpc v1.73.0 // indirect
5868
google.golang.org/protobuf v1.36.6 // indirect
5969
gopkg.in/yaml.v3 v3.0.1 // indirect
70+
k8s.io/klog/v2 v2.130.1 // indirect
71+
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
72+
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
6073
)

0 commit comments

Comments
 (0)