44 "fmt"
55 "net/http"
66
7- "github.com/merico-dev/lake/logger"
87 lakeModels "github.com/merico-dev/lake/models"
98 "github.com/merico-dev/lake/plugins/core"
109 "github.com/merico-dev/lake/plugins/github/models"
@@ -42,7 +41,6 @@ func CollectCommits(owner string, repositoryName string, repositoryId int, sched
4241 githubApiResponse := & ApiCommitsResponse {}
4342 err := core .UnmarshalResponse (res , githubApiResponse )
4443 if err != nil || res .StatusCode == 401 {
45- logger .Error ("Error: " , err )
4644 return err
4745 }
4846 repoCommit := & models.GithubRepoCommit {GithubRepoId : repositoryId }
@@ -51,37 +49,39 @@ func CollectCommits(owner string, repositoryName string, repositoryId int, sched
5149 if err != nil {
5250 return err
5351 }
54- err = lakeModels .Db .Clauses (clause.OnConflict {
55- UpdateAll : true ,
56- }).Create (& githubCommit ).Error
57- if err != nil {
58- logger .Error ("Could not upsert: " , err )
59- }
60- // save repo / commit relationship
61- repoCommit .CommitSha = commit .Sha
62- err = lakeModels .Db .Clauses (clause.OnConflict {
63- DoNothing : true ,
64- }).Create (repoCommit ).Error
65- if err != nil {
66- logger .Error ("Could not upsert: " , err )
67- }
6852 // save author and committer
6953 if commit .Author != nil {
54+ githubCommit .AuthorId = commit .Author .Id
7055 err = lakeModels .Db .Clauses (clause.OnConflict {
7156 UpdateAll : true ,
7257 }).Create (& commit .Author ).Error
7358 if err != nil {
74- logger . Error ( "Could not upsert: " , err )
59+ return err
7560 }
7661 }
7762 if commit .Committer != nil {
63+ githubCommit .CommitterId = commit .Committer .Id
7864 err = lakeModels .Db .Clauses (clause.OnConflict {
7965 UpdateAll : true ,
8066 }).Create (& commit .Committer ).Error
8167 if err != nil {
82- logger . Error ( "Could not upsert: " , err )
68+ return err
8369 }
8470 }
71+ err = lakeModels .Db .Clauses (clause.OnConflict {
72+ UpdateAll : true ,
73+ }).Create (& githubCommit ).Error
74+ if err != nil {
75+ return err
76+ }
77+ // save repo / commit relationship
78+ repoCommit .CommitSha = commit .Sha
79+ err = lakeModels .Db .Clauses (clause.OnConflict {
80+ DoNothing : true ,
81+ }).Create (repoCommit ).Error
82+ if err != nil {
83+ return err
84+ }
8585 }
8686 return nil
8787 })
@@ -90,11 +90,9 @@ func convertGithubCommit(commit *CommitsResponse) (*models.GithubCommit, error)
9090 githubCommit := & models.GithubCommit {
9191 Sha : commit .Sha ,
9292 Message : commit .Commit .Message ,
93- AuthorId : commit .Author .Id ,
9493 AuthorName : commit .Commit .Author .Name ,
9594 AuthorEmail : commit .Commit .Author .Email ,
9695 AuthoredDate : commit .Commit .Author .Date .ToTime (),
97- CommitterId : commit .Committer .Id ,
9896 CommitterName : commit .Commit .Committer .Name ,
9997 CommitterEmail : commit .Commit .Committer .Email ,
10098 CommittedDate : commit .Commit .Committer .Date .ToTime (),
0 commit comments