Skip to content

Commit ed30a1c

Browse files
authored
Merge branch 'open-sauced:beta' into pull-org
2 parents 6c7a286 + d2fe2d3 commit ed30a1c

File tree

8 files changed

+144
-5
lines changed

8 files changed

+144
-5
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@open-sauced/engineering
2+

.github/workflows/compliance.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: Compliance
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
10+
permissions:
11+
pull-requests: write
12+
13+
jobs:
14+
compliance:
15+
uses: open-sauced/hot/.github/workflows/compliance.yml@main

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# 📦 open-sauced/pizza changelog
2+
3+
[![conventional commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
4+
[![semantic versioning](https://img.shields.io/badge/semantic%20versioning-2.0.0-green.svg)](https://semver.org)
5+
6+
> All notable changes to this project will be documented in this file
7+
8+
## [1.1.0-beta.2](https://github.com/open-sauced/pizza/compare/v1.1.0-beta.1...v1.1.0-beta.2) (2023-10-09)
9+
10+
11+
### 🍕 Features
12+
13+
* Ability to turn off sslmode ([#58](https://github.com/open-sauced/pizza/issues/58)) ([b026289](https://github.com/open-sauced/pizza/commit/b0262890b6d74ef85e2d5f57daa73e9ac7f81879))
14+
15+
## [1.1.0-beta.1](https://github.com/open-sauced/pizza/compare/v1.0.1-beta.1...v1.1.0-beta.1) (2023-10-07)
16+
17+
18+
### 🍕 Features
19+
20+
* Add our compliance GitHub workflow ([#59](https://github.com/open-sauced/pizza/issues/59)) ([8196306](https://github.com/open-sauced/pizza/commit/819630638474591340c4b5cbb973cca172b30791))
21+
22+
## [1.0.1-beta.1](https://github.com/open-sauced/pizza/compare/v1.0.0...v1.0.1-beta.1) (2023-09-28)
23+
24+
25+
### 🐛 Bug Fixes
26+
27+
* Add missing "pizza.sql" file ([#57](https://github.com/open-sauced/pizza/issues/57)) ([66dc680](https://github.com/open-sauced/pizza/commit/66dc6800925da3cf9c8d9c0329b50a05e3f360fe))

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all lint test run local build setup-test-env teardown-test-env
1+
.PHONY: all lint test run dev local build setup-test-env teardown-test-env
22

33
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
44

@@ -19,6 +19,9 @@ test:
1919
run:
2020
go run main.go
2121

22+
dev:
23+
go run main.go -ssl-disable
24+
2225
local:
2326
go build -o build/pizza-oven main.go
2427

hack/pizza.sql

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
-- This file is sourced from https://github.com/open-sauced/api/tree/beta/migrations
2+
-- and is used only for local development convenience
3+
4+
------------------------------------
5+
-- Pizza oven "baked" repos table --
6+
-------------------------------------
7+
create table if not exists public.baked_repos
8+
(
9+
id bigint not null generated by default as identity ( increment 1 start 1 minvalue 1 maxvalue 9223372036854775807 cache 1 ),
10+
clone_url character varying(255) collate pg_catalog."default" not null,
11+
12+
-- elastic columns
13+
14+
-- the repo_id field is used to loosely reference an id from the repos table
15+
-- but since git repos may have their commits indexed that have not yet been
16+
-- indexed into the repos table, there is not direct correlation.
17+
-- Joins can happen across the "clone_url" to find repos that have not yet
18+
-- synced to baked_repos.
19+
repo_id bigint default null,
20+
21+
-- dynamic columns
22+
constraint baked_repos_pkey primary key (id)
23+
)
24+
25+
tablespace pg_default;
26+
27+
-- indexes for baked repos
28+
create index if not exists baked_repos_idx_clone_url on baked_repos (clone_url);
29+
30+
-------------------------------------
31+
-- Pizza oven commit authors table --
32+
-------------------------------------
33+
create table if not exists public.commit_authors
34+
(
35+
id bigint not null generated by default as identity ( increment 1 start 1 minvalue 1 maxvalue 9223372036854775807 cache 1 ),
36+
commit_author_email character varying(255) collate pg_catalog."default" not null,
37+
38+
-- dynamic columns
39+
constraint commit_authors_pkey primary key (id)
40+
)
41+
42+
tablespace pg_default;
43+
44+
-- indexes for baked repos
45+
create index if not exists commit_authors_idx_commit_author_email on commit_authors (commit_author_email);
46+
47+
--------------------------------
48+
-- Pizza oven indexed commits --
49+
--------------------------------
50+
51+
create table if not exists public.commits (
52+
id bigint not null generated by default as identity ( increment 1 start 1 minvalue 1 maxvalue 9223372036854775807 cache 1 ),
53+
baked_repo_id bigint not null references public.baked_repos (id) on delete cascade on update cascade,
54+
commit_author_id bigint not null references public.commit_authors(id) on delete cascade on update cascade,
55+
commit_hash character varying(255) collate pg_catalog."default" not null,
56+
commit_date timestamp with time zone not null default now(),
57+
58+
-- dynamic columns
59+
constraint commits_pkey primary key (id)
60+
)
61+
62+
tablespace pg_default;
63+
64+
-- psql indexes for commits
65+
create index if not exists commit_idx_hash on commits (commit_hash);
66+
create index if not exists commit_idx_date on commits (commit_date);
67+

main.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ func main() {
2020
var err error
2121

2222
// Initialize & parse flags
23-
var configPath string
23+
var (
24+
configPath string
25+
sslmode = "require"
26+
)
2427
flag.StringVar(&configPath, "config", "", "path to .yaml file config")
2528
debugMode := flag.Bool("debug", false, "run in debug mode")
29+
disableSSL := flag.Bool("ssl-disable", false, "set 'disable' ssl mode")
2630
flag.Parse()
2731

2832
if *debugMode {
@@ -40,6 +44,11 @@ func main() {
4044
sugarLogger := logger.Sugar()
4145
sugarLogger.Infof("initiated zap logger with level: %d", sugarLogger.Level())
4246

47+
if *disableSSL {
48+
sslmode = "disable"
49+
sugarLogger.Warn("SSL mode is disabled")
50+
}
51+
4352
// Load the environment variables from the .env file
4453
err = godotenv.Load()
4554
if err != nil {
@@ -60,7 +69,7 @@ func main() {
6069
gitProvider := os.Getenv("GIT_PROVIDER")
6170

6271
// Initialize the database handler
63-
pizzaOven := database.NewPizzaOvenDbHandler(databaseHost, databasePort, databaseUser, databasePwd, databaseDbName)
72+
pizzaOven := database.NewPizzaOvenDbHandler(databaseHost, databasePort, databaseUser, databasePwd, databaseDbName, sslmode)
6473

6574
// Initializes configuration using a provided yaml file
6675
config := &server.Config{NeverEvictRepos: make(map[string]bool)}

pkg/database/handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ type PizzaOvenDbHandler struct {
2424

2525
// NewPizzaOvenDbHandler builds a PizzaOvenDbHandler based on the provided
2626
// database connection parameters
27-
func NewPizzaOvenDbHandler(host, port, user, pwd, dbName string) *PizzaOvenDbHandler {
28-
connectString := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=require", host, port, user, pwd, dbName)
27+
func NewPizzaOvenDbHandler(host, port, user, pwd, dbName, sslmode string) *PizzaOvenDbHandler {
28+
connectString := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=%s", host, port, user, pwd, dbName, sslmode)
2929

3030
// Acquire the *sql.DB instance
3131
dbPool, err := sql.Open("postgres", connectString)

pkg/server/server.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,11 @@ func (p PizzaOvenServer) processRepository(repoURL string) error {
289289
p.Logger.Debugf("No repo found in db. Inserting repo: %s", insight.RepoURLSource)
290290
repoID, err = p.PizzaOven.InsertRepository(insight)
291291
if err != nil {
292+
p.Logger.Errorf("Failed to insert repository %s: %s", insight.RepoURLSource, err.Error())
292293
return err
293294
}
294295
} else {
296+
p.Logger.Errorf("Failed to fetch repository ID: %s", err.Error())
295297
return err
296298
}
297299
}
@@ -301,6 +303,7 @@ func (p PizzaOvenServer) processRepository(repoURL string) error {
301303
// Use the configured git provider to get the repo
302304
providedRepo, err := p.PizzaGitProvider.FetchRepo(insight.RepoURLSource)
303305
if err != nil {
306+
p.Logger.Error("Failed to fetch repository %s: %s", insight.RepoURLSource, err.Error())
304307
return err
305308
}
306309
defer providedRepo.Done()
@@ -310,12 +313,14 @@ func (p PizzaOvenServer) processRepository(repoURL string) error {
310313
p.Logger.Debugf("Inspecting the head of the git repo: %s", insight.RepoURLSource)
311314
ref, err := gitRepo.Head()
312315
if err != nil {
316+
p.Logger.Errorf("Could not find head of the git repo %s: %s", insight.RepoURLSource, err.Error())
313317
return err
314318
}
315319

316320
p.Logger.Debugf("Getting last commit in DB: %s", insight.RepoURLSource)
317321
latestCommitDate, err := p.PizzaOven.GetLastCommit(repoID)
318322
if err != nil {
323+
p.Logger.Errorf("Could not fetch the latest commit date in %s: %s", insight.RepoURLSource, err.Error())
319324
return err
320325
}
321326

@@ -334,6 +339,7 @@ func (p PizzaOvenServer) processRepository(repoURL string) error {
334339
p.Logger.Debugf("Getting commit iterator with git log options: %v", gitLogOptions)
335340
authorIter, err := gitRepo.Log(&gitLogOptions)
336341
if err != nil {
342+
p.Logger.Errorf("Failed to retrieve commit iterator: %s", err.Error())
337343
return err
338344
}
339345

@@ -346,6 +352,7 @@ func (p PizzaOvenServer) processRepository(repoURL string) error {
346352
p.Logger.Debugf("Using temporary db table for commit authors: %s", tmpTableName)
347353
authorTxn, authorStmt, err := p.PizzaOven.PrepareBulkAuthorInsert(tmpTableName)
348354
if err != nil {
355+
p.Logger.Errorf("Failed to prepare the bulk author insert process: %s", err.Error())
349356
return err
350357
}
351358

@@ -381,36 +388,42 @@ func (p PizzaOvenServer) processRepository(repoURL string) error {
381388
})
382389
})
383390
if err != nil {
391+
p.Logger.Errorf("Failed to insert author: %s", err.Error())
384392
return err
385393
}
386394

387395
// Resolve, execute, and pivot the bulk author transaction
388396
err = p.PizzaOven.ResolveTransaction(authorTxn, authorStmt)
389397
if err != nil {
398+
p.Logger.Errorf("Failed to resolve bulk author transaction: %s", err.Error())
390399
return err
391400
}
392401

393402
err = p.PizzaOven.PivotTmpTableToAuthorsTable(tmpTableName)
394403
if err != nil {
404+
p.Logger.Errorf("Failed to pivot the temporary authors table: %s", err.Error())
395405
return err
396406
}
397407

398408
// Re-query the database for author email ids based on the unique list of
399409
// author emails that have just been committed
400410
authorEmailIDMap, err := p.PizzaOven.GetAuthorIDs(uniqueAuthorEmails)
401411
if err != nil {
412+
p.Logger.Errorf("Failed to create the author-email/id map: %s", err.Error())
402413
return err
403414
}
404415

405416
// Rebuild the iterator from the start using the same options
406417
commitIter, err := gitRepo.Log(&gitLogOptions)
407418
if err != nil {
419+
p.Logger.Errorf("Failed to rebuild the commit iterator: %s", err.Error())
408420
return err
409421
}
410422

411423
// Get ready for the commit bulk action
412424
commitTxn, commitStmt, err := p.PizzaOven.PrepareBulkCommitInsert()
413425
if err != nil {
426+
p.Logger.Errorf("Failed to prepare bulk commit insert process: %s", err.Error())
414427
return err
415428
}
416429

@@ -426,18 +439,21 @@ func (p PizzaOvenServer) processRepository(repoURL string) error {
426439
p.Logger.Debugf("Inspecting commit: %s %s %s", i.AuthorEmail, i.Hash, i.Date)
427440
err = p.PizzaOven.InsertCommit(commitStmt, i, authorEmailIDMap[i.AuthorEmail], repoID)
428441
if err != nil {
442+
p.Logger.Errorf("Failed to insert commit: %s", err.Error())
429443
return err
430444
}
431445

432446
return nil
433447
})
434448
if err != nil {
449+
p.Logger.Errorf("Failed to insert commit: %s", err.Error())
435450
return err
436451
}
437452

438453
// Execute and resolve the bulk commit insert
439454
err = p.PizzaOven.ResolveTransaction(commitTxn, commitStmt)
440455
if err != nil {
456+
p.Logger.Errorf("Could not resolve bulk commit insert transaction %v", err.Error())
441457
return err
442458
}
443459

0 commit comments

Comments
 (0)