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

feat: add error logs #52

Merged
merged 1 commit into from
Sep 27, 2023
Merged
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
16 changes: 16 additions & 0 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ func (p PizzaOvenServer) processRepository(repoURL string) error {
p.Logger.Debugf("No repo found in db. Inserting repo: %s", insight.RepoURLSource)
repoID, err = p.PizzaOven.InsertRepository(insight)
if err != nil {
p.Logger.Errorf("Failed to insert repository %s: %s", insight.RepoURLSource, err.Error())
return err
}
} else {
p.Logger.Errorf("Failed to fetch repository ID: %s", err.Error())
return err
}
}
Expand All @@ -167,6 +169,7 @@ func (p PizzaOvenServer) processRepository(repoURL string) error {
// Use the configured git provider to get the repo
providedRepo, err := p.PizzaGitProvider.FetchRepo(insight.RepoURLSource)
if err != nil {
p.Logger.Error("Failed to fetch repository %s: %s", insight.RepoURLSource, err.Error())
return err
}
defer providedRepo.Done()
Expand All @@ -176,12 +179,14 @@ func (p PizzaOvenServer) processRepository(repoURL string) error {
p.Logger.Debugf("Inspecting the head of the git repo: %s", insight.RepoURLSource)
ref, err := gitRepo.Head()
if err != nil {
p.Logger.Errorf("Could not find head of the git repo %s: %s", insight.RepoURLSource, err.Error())
return err
}

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

Expand All @@ -200,6 +205,7 @@ func (p PizzaOvenServer) processRepository(repoURL string) error {
p.Logger.Debugf("Getting commit iterator with git log options: %v", gitLogOptions)
authorIter, err := gitRepo.Log(&gitLogOptions)
if err != nil {
p.Logger.Errorf("Failed to retrieve commit iterator: %s", err.Error())
return err
}

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

Expand Down Expand Up @@ -247,36 +254,42 @@ func (p PizzaOvenServer) processRepository(repoURL string) error {
})
})
if err != nil {
p.Logger.Errorf("Failed to insert author: %s", err.Error())
return err
}

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

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

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

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

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

Expand All @@ -292,18 +305,21 @@ func (p PizzaOvenServer) processRepository(repoURL string) error {
p.Logger.Debugf("Inspecting commit: %s %s %s", i.AuthorEmail, i.Hash, i.Date)
err = p.PizzaOven.InsertCommit(commitStmt, i, authorEmailIDMap[i.AuthorEmail], repoID)
if err != nil {
p.Logger.Errorf("Failed to insert commit: %s", err.Error())
return err
}

return nil
})
if err != nil {
p.Logger.Errorf("Failed to insert commit: %s", err.Error())
return err
}

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

Expand Down