Skip to content

Commit

Permalink
fix: github_commit_collector nil pointer dereference
Browse files Browse the repository at this point in the history
  Closes #1061
  • Loading branch information
klesh committed Jan 17, 2022
1 parent a5b15c6 commit b2762bf
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions plugins/github/tasks/github_commit_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"net/http"

"github.com/merico-dev/lake/logger"
lakeModels "github.com/merico-dev/lake/models"
"github.com/merico-dev/lake/plugins/core"
"github.com/merico-dev/lake/plugins/github/models"
Expand Down Expand Up @@ -42,7 +41,6 @@ func CollectCommits(owner string, repositoryName string, repositoryId int, sched
githubApiResponse := &ApiCommitsResponse{}
err := core.UnmarshalResponse(res, githubApiResponse)
if err != nil || res.StatusCode == 401 {
logger.Error("Error: ", err)
return err
}
repoCommit := &models.GithubRepoCommit{GithubRepoId: repositoryId}
Expand All @@ -51,37 +49,39 @@ func CollectCommits(owner string, repositoryName string, repositoryId int, sched
if err != nil {
return err
}
err = lakeModels.Db.Clauses(clause.OnConflict{
UpdateAll: true,
}).Create(&githubCommit).Error
if err != nil {
logger.Error("Could not upsert: ", err)
}
// save repo / commit relationship
repoCommit.CommitSha = commit.Sha
err = lakeModels.Db.Clauses(clause.OnConflict{
DoNothing: true,
}).Create(repoCommit).Error
if err != nil {
logger.Error("Could not upsert: ", err)
}
// save author and committer
if commit.Author != nil {
githubCommit.AuthorId = commit.Author.Id
err = lakeModels.Db.Clauses(clause.OnConflict{
UpdateAll: true,
}).Create(&commit.Author).Error
if err != nil {
logger.Error("Could not upsert: ", err)
return err
}
}
if commit.Committer != nil {
githubCommit.CommitterId = commit.Committer.Id
err = lakeModels.Db.Clauses(clause.OnConflict{
UpdateAll: true,
}).Create(&commit.Committer).Error
if err != nil {
logger.Error("Could not upsert: ", err)
return err
}
}
err = lakeModels.Db.Clauses(clause.OnConflict{
UpdateAll: true,
}).Create(&githubCommit).Error
if err != nil {
return err
}
// save repo / commit relationship
repoCommit.CommitSha = commit.Sha
err = lakeModels.Db.Clauses(clause.OnConflict{
DoNothing: true,
}).Create(repoCommit).Error
if err != nil {
return err
}
}
return nil
})
Expand All @@ -90,11 +90,9 @@ func convertGithubCommit(commit *CommitsResponse) (*models.GithubCommit, error)
githubCommit := &models.GithubCommit{
Sha: commit.Sha,
Message: commit.Commit.Message,
AuthorId: commit.Author.Id,
AuthorName: commit.Commit.Author.Name,
AuthorEmail: commit.Commit.Author.Email,
AuthoredDate: commit.Commit.Author.Date.ToTime(),
CommitterId: commit.Committer.Id,
CommitterName: commit.Commit.Committer.Name,
CommitterEmail: commit.Commit.Committer.Email,
CommittedDate: commit.Commit.Committer.Date.ToTime(),
Expand Down

0 comments on commit b2762bf

Please sign in to comment.