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

cherry-pick #5900 fix: github account collection might fail with 404 to v0.18 (beta6) #5901

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ limitations under the License.
package tasks

import (
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/plugins/github/models"
)

Expand All @@ -36,13 +35,14 @@ type GraphqlInlineAccountQuery struct {
GithubAccountEdge `graphql:"... on User"`
}

func convertGraphqlPreAccount(res GraphqlInlineAccountQuery, repoId int, connId uint64) (*models.GithubRepoAccount, errors.Error) {
githubAccount := &models.GithubRepoAccount{
func extractGraphqlPreAccount(result *[]interface{}, res *GraphqlInlineAccountQuery, repoId int, connId uint64) {
if res == nil || res.Id == 0 {
return
}
*result = append(*result, &models.GithubRepoAccount{
ConnectionId: connId,
RepoGithubId: repoId,
Login: res.Login,
AccountId: res.Id,
}

return githubAccount, nil
})
}
16 changes: 3 additions & 13 deletions backend/plugins/github_graphql/tasks/issue_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,10 @@ func CollectIssue(taskCtx plugin.SubTaskContext) errors.Error {
}
results = append(results, githubLabels...)
results = append(results, githubIssue)
if issue.AssigneeList.Assignees != nil && len(issue.AssigneeList.Assignees) > 0 {
relatedUser, err := convertGraphqlPreAccount(issue.AssigneeList.Assignees[0], data.Options.GithubId, data.Options.ConnectionId)
if err != nil {
return nil, err
}
results = append(results, relatedUser)
}
if issue.Author != nil {
relatedUser, err := convertGraphqlPreAccount(*issue.Author, data.Options.GithubId, data.Options.ConnectionId)
if err != nil {
return nil, err
}
results = append(results, relatedUser)
if len(issue.AssigneeList.Assignees) > 0 {
extractGraphqlPreAccount(&results, &issue.AssigneeList.Assignees[0], data.Options.GithubId, data.Options.ConnectionId)
}
extractGraphqlPreAccount(&results, issue.Author, data.Options.GithubId, data.Options.ConnectionId)
for _, assignee := range issue.AssigneeList.Assignees {
issueAssignee := &models.GithubIssueAssignee{
ConnectionId: githubIssue.ConnectionId,
Expand Down
33 changes: 3 additions & 30 deletions backend/plugins/github_graphql/tasks/pr_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,7 @@ func CollectPr(taskCtx plugin.SubTaskContext) errors.Error {
if err != nil {
return nil, err
}
if rawL.Author != nil {
githubUser, err := convertGraphqlPreAccount(*rawL.Author, data.Options.GithubId, data.Options.ConnectionId)
if err != nil {
return nil, err
}
results = append(results, githubUser)
}
extractGraphqlPreAccount(&results, rawL.Author, data.Options.GithubId, data.Options.ConnectionId)
for _, label := range rawL.Labels.Nodes {
results = append(results, &models.GithubPrLabel{
ConnectionId: data.Options.ConnectionId,
Expand All @@ -236,11 +230,6 @@ func CollectPr(taskCtx plugin.SubTaskContext) errors.Error {

for _, apiPullRequestReview := range rawL.Reviews.Nodes {
if apiPullRequestReview.State != "PENDING" {
githubReviewer := &models.GithubReviewer{
ConnectionId: data.Options.ConnectionId,
PullRequestId: githubPr.GithubId,
}

githubPrReview := &models.GithubPrReview{
ConnectionId: data.Options.ConnectionId,
GithubId: apiPullRequestReview.DatabaseId,
Expand All @@ -253,20 +242,11 @@ func CollectPr(taskCtx plugin.SubTaskContext) errors.Error {
}

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.Options.GithubId, data.Options.ConnectionId)
if err != nil {
return nil, err
}
results = append(results, githubUser)
extractGraphqlPreAccount(&results, apiPullRequestReview.Author, data.Options.GithubId, data.Options.ConnectionId)
}

results = append(results, githubReviewer)
results = append(results, githubPrReview)
}
}
Expand All @@ -290,14 +270,7 @@ func CollectPr(taskCtx plugin.SubTaskContext) errors.Error {
return nil, err
}
results = append(results, githubPullRequestCommit)

if apiPullRequestCommit.Commit.Author.User != nil {
githubUser, err := convertGraphqlPreAccount(*apiPullRequestCommit.Commit.Author.User, data.Options.GithubId, data.Options.ConnectionId)
if err != nil {
return nil, err
}
results = append(results, githubUser)
}
extractGraphqlPreAccount(&results, apiPullRequestCommit.Commit.Author.User, data.Options.GithubId, data.Options.ConnectionId)
}
}

Expand Down