This is an automated email from the ASF dual-hosted git repository.

likyh pushed a commit to branch release-v0.14
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 36e9d99da13698f3b032950a6335f205a57afb93
Author: linyh <[email protected]>
AuthorDate: Wed Oct 19 20:51:25 2022 +0800

    fix: set username/id to empty when github user is nil
---
 plugins/github/tasks/comment_extractor.go          | 22 ++++++++-----
 plugins/github/tasks/event_extractor.go            | 36 +++++++++++-----------
 .../github/tasks/pr_review_comment_extractor.go    | 11 +++++--
 plugins/github/tasks/pr_review_extractor.go        | 24 +++++++++------
 plugins/github_graphql/tasks/pr_collector.go       | 25 +++++++++------
 5 files changed, 69 insertions(+), 49 deletions(-)

diff --git a/plugins/github/tasks/comment_extractor.go 
b/plugins/github/tasks/comment_extractor.go
index ffcef550..b237d53a 100644
--- a/plugins/github/tasks/comment_extractor.go
+++ b/plugins/github/tasks/comment_extractor.go
@@ -95,12 +95,14 @@ func ExtractApiComments(taskCtx core.SubTaskContext) 
errors.Error {
                                        GithubId:        apiComment.GithubId,
                                        PullRequestId:   pr.GithubId,
                                        Body:            
string(apiComment.Body),
-                                       AuthorUsername:  apiComment.User.Login,
-                                       AuthorUserId:    apiComment.User.Id,
                                        GithubCreatedAt: 
apiComment.GithubCreatedAt.ToTime(),
                                        GithubUpdatedAt: 
apiComment.GithubUpdatedAt.ToTime(),
                                        Type:            "NORMAL",
                                }
+                               if apiComment.User != nil {
+                                       githubPrComment.AuthorUsername = 
apiComment.User.Login
+                                       githubPrComment.AuthorUserId = 
apiComment.User.Id
+                               }
                                results = append(results, githubPrComment)
                        } else {
                                githubIssueComment := 
&models.GithubIssueComment{
@@ -108,18 +110,22 @@ func ExtractApiComments(taskCtx core.SubTaskContext) 
errors.Error {
                                        GithubId:        apiComment.GithubId,
                                        IssueId:         issue.GithubId,
                                        Body:            
string(apiComment.Body),
-                                       AuthorUsername:  apiComment.User.Login,
-                                       AuthorUserId:    apiComment.User.Id,
                                        GithubCreatedAt: 
apiComment.GithubCreatedAt.ToTime(),
                                        GithubUpdatedAt: 
apiComment.GithubUpdatedAt.ToTime(),
                                }
+                               if apiComment.User != nil {
+                                       githubIssueComment.AuthorUsername = 
apiComment.User.Login
+                                       githubIssueComment.AuthorUserId = 
apiComment.User.Id
+                               }
                                results = append(results, githubIssueComment)
                        }
-                       githubAccount, err := convertAccount(apiComment.User, 
data.Repo.GithubId, data.Options.ConnectionId)
-                       if err != nil {
-                               return nil, err
+                       if apiComment.User != nil {
+                               githubAccount, err := 
convertAccount(apiComment.User, data.Repo.GithubId, data.Options.ConnectionId)
+                               if err != nil {
+                                       return nil, err
+                               }
+                               results = append(results, githubAccount)
                        }
-                       results = append(results, githubAccount)
                        return results, nil
                },
        })
diff --git a/plugins/github/tasks/event_extractor.go 
b/plugins/github/tasks/event_extractor.go
index a130271f..1cb6a106 100644
--- a/plugins/github/tasks/event_extractor.go
+++ b/plugins/github/tasks/event_extractor.go
@@ -66,16 +66,28 @@ func ExtractApiEvents(taskCtx core.SubTaskContext) 
errors.Error {
                        if body.GithubId == 0 || body.Actor == nil {
                                return nil, nil
                        }
-                       githubIssueEvent, err := convertGithubEvent(body, 
data.Options.ConnectionId)
-                       if err != nil {
-                               return nil, err
+                       githubIssueEvent := &models.GithubIssueEvent{
+                               ConnectionId:    data.Options.ConnectionId,
+                               GithubId:        body.GithubId,
+                               IssueId:         body.Issue.Id,
+                               Type:            body.Event,
+                               GithubCreatedAt: body.GithubCreatedAt.ToTime(),
                        }
-                       results = append(results, githubIssueEvent)
-                       githubAccount, err := convertAccount(body.Actor, 
data.Repo.GithubId, data.Options.ConnectionId)
+
+                       if body.Actor != nil {
+                               githubIssueEvent.AuthorUsername = 
body.Actor.Login
+
+                               githubAccount, err := 
convertAccount(body.Actor, data.Repo.GithubId, data.Options.ConnectionId)
+                               if err != nil {
+                                       return nil, err
+                               }
+                               results = append(results, githubAccount)
+                       }
+
                        if err != nil {
                                return nil, err
                        }
-                       results = append(results, githubAccount)
+                       results = append(results, githubIssueEvent)
 
                        return results, nil
                },
@@ -87,15 +99,3 @@ func ExtractApiEvents(taskCtx core.SubTaskContext) 
errors.Error {
 
        return extractor.Execute()
 }
-
-func convertGithubEvent(event *IssueEvent, connId uint64) 
(*models.GithubIssueEvent, errors.Error) {
-       githubEvent := &models.GithubIssueEvent{
-               ConnectionId:    connId,
-               GithubId:        event.GithubId,
-               IssueId:         event.Issue.Id,
-               Type:            event.Event,
-               AuthorUsername:  event.Actor.Login,
-               GithubCreatedAt: event.GithubCreatedAt.ToTime(),
-       }
-       return githubEvent, nil
-}
diff --git a/plugins/github/tasks/pr_review_comment_extractor.go 
b/plugins/github/tasks/pr_review_comment_extractor.go
index 3ef12736..fae44a83 100644
--- a/plugins/github/tasks/pr_review_comment_extractor.go
+++ b/plugins/github/tasks/pr_review_comment_extractor.go
@@ -78,8 +78,6 @@ func ExtractApiPrReviewComments(taskCtx core.SubTaskContext) 
errors.Error {
                                Body:            string(prReviewComment.Body),
                                CommitSha:       prReviewComment.CommitId,
                                ReviewId:        prReviewComment.PrReviewId,
-                               AuthorUsername:  prReviewComment.User.Login,
-                               AuthorUserId:    prReviewComment.User.Id,
                                GithubCreatedAt: 
prReviewComment.GithubCreatedAt.ToTime(),
                                GithubUpdatedAt: 
prReviewComment.GithubUpdatedAt.ToTime(),
                                Type:            "DIFF",
@@ -96,12 +94,19 @@ func ExtractApiPrReviewComments(taskCtx 
core.SubTaskContext) errors.Error {
                        if prId != 0 {
                                githubPrComment.PullRequestId = prId
                        }
-                       results = append(results, githubPrComment)
+
+                       if prReviewComment.User != nil {
+                               githubPrComment.AuthorUserId = 
prReviewComment.User.Id
+                               githubPrComment.AuthorUsername = 
prReviewComment.User.Login
+
                        githubAccount, err := 
convertAccount(prReviewComment.User, data.Repo.GithubId, 
data.Options.ConnectionId)
                        if err != nil {
                                return nil, err
                        }
                        results = append(results, githubAccount)
+                       }
+
+                       results = append(results, githubPrComment)
                        return results, nil
                },
        })
diff --git a/plugins/github/tasks/pr_review_extractor.go 
b/plugins/github/tasks/pr_review_extractor.go
index c8de960b..f199c4a4 100644
--- a/plugins/github/tasks/pr_review_extractor.go
+++ b/plugins/github/tasks/pr_review_extractor.go
@@ -85,8 +85,6 @@ func ExtractApiPullRequestReviews(taskCtx 
core.SubTaskContext) errors.Error {
 
                        githubReviewer := &models.GithubReviewer{
                                ConnectionId:  data.Options.ConnectionId,
-                               GithubId:      apiPullRequestReview.User.Id,
-                               Login:         apiPullRequestReview.User.Login,
                                PullRequestId: pull.GithubId,
                        }
 
@@ -97,19 +95,25 @@ func ExtractApiPullRequestReviews(taskCtx 
core.SubTaskContext) errors.Error {
                                State:          apiPullRequestReview.State,
                                CommitSha:      apiPullRequestReview.CommitId,
                                GithubSubmitAt: 
apiPullRequestReview.SubmittedAt.ToNullableTime(),
-
                                PullRequestId:  pull.GithubId,
-                               AuthorUsername: apiPullRequestReview.User.Login,
-                               AuthorUserId:   apiPullRequestReview.User.Id,
+                       }
+
+                       if apiPullRequestReview.User != nil {
+                               githubReviewer.GithubId = 
apiPullRequestReview.User.Id
+                               githubReviewer.Login = 
apiPullRequestReview.User.Login
+
+                               githubPrReview.AuthorUserId = 
apiPullRequestReview.User.Id
+                               githubPrReview.AuthorUsername = 
apiPullRequestReview.User.Login
+
+                               githubUser, err := 
convertAccount(apiPullRequestReview.User, data.Repo.GithubId, 
data.Options.ConnectionId)
+                               if err != nil {
+                                       return nil, err
+                               }
+                               results = append(results, githubUser)
                        }
 
                        results = append(results, githubReviewer)
                        results = append(results, githubPrReview)
-                       githubUser, err := 
convertAccount(apiPullRequestReview.User, data.Repo.GithubId, 
data.Options.ConnectionId)
-                       if err != nil {
-                               return nil, err
-                       }
-                       results = append(results, githubUser)
 
                        return results, nil
                },
diff --git a/plugins/github_graphql/tasks/pr_collector.go 
b/plugins/github_graphql/tasks/pr_collector.go
index fd0a3b35..a56a33bc 100644
--- a/plugins/github_graphql/tasks/pr_collector.go
+++ b/plugins/github_graphql/tasks/pr_collector.go
@@ -218,8 +218,6 @@ func CollectPr(taskCtx core.SubTaskContext) errors.Error {
                                        if apiPullRequestReview.State != 
"PENDING" {
                                                githubReviewer := 
&models.GithubReviewer{
                                                        ConnectionId:  
data.Options.ConnectionId,
-                                                       GithubId:      
apiPullRequestReview.Author.Id,
-                                                       Login:         
apiPullRequestReview.Author.Login,
                                                        PullRequestId: 
githubPr.GithubId,
                                                }
 
@@ -231,18 +229,25 @@ func CollectPr(taskCtx core.SubTaskContext) errors.Error {
                                                        CommitSha:      
apiPullRequestReview.Commit.Oid,
                                                        GithubSubmitAt: 
apiPullRequestReview.SubmittedAt,
 
-                                                       PullRequestId:  
githubPr.GithubId,
-                                                       AuthorUsername: 
apiPullRequestReview.Author.Login,
-                                                       AuthorUserId:   
apiPullRequestReview.Author.Id,
+                                                       PullRequestId: 
githubPr.GithubId,
+                                               }
+
+                                               if apiPullRequestReview.Author 
!= nil {
+                                                       githubReviewer.GithubId 
= apiPullRequestReview.Author.Id
+                                                       githubReviewer.Login = 
apiPullRequestReview.Author.Login
+
+                                                       
githubPrReview.AuthorUserId = apiPullRequestReview.Author.Id
+                                                       
githubPrReview.AuthorUsername = apiPullRequestReview.Author.Login
+
+                                                       githubUser, err := 
convertGraphqlPreAccount(*apiPullRequestReview.Author, data.Repo.GithubId, 
data.Options.ConnectionId)
+                                                       if err != nil {
+                                                               return nil, err
+                                                       }
+                                                       results = 
append(results, githubUser)
                                                }
 
                                                results = append(results, 
githubReviewer)
                                                results = append(results, 
githubPrReview)
-                                               githubUser, err := 
convertGraphqlPreAccount(*apiPullRequestReview.Author, data.Repo.GithubId, 
data.Options.ConnectionId)
-                                               if err != nil {
-                                                       return nil, err
-                                               }
-                                               results = append(results, 
githubUser)
                                        }
                                }
 

Reply via email to