You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by kl...@apache.org on 2024/08/13 08:13:31 UTC
(incubator-devlake) 04/19: refactor: update github issue extractor to extract single record
This is an automated email from the ASF dual-hosted git repository.
klesh pushed a commit to branch kw-7852-components-field-length
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit 6128b6872715ae4677c5a616c8b1eff6234c7384
Author: Klesh Wong <zh...@merico.dev>
AuthorDate: Wed Aug 7 17:23:32 2024 +0800
refactor: update github issue extractor to extract single record
---
.../github_graphql/tasks/issue_extractor.go | 55 ++++++++++------------
1 file changed, 26 insertions(+), 29 deletions(-)
diff --git a/backend/plugins/github_graphql/tasks/issue_extractor.go b/backend/plugins/github_graphql/tasks/issue_extractor.go
index b5652587e..7ebd40822 100644
--- a/backend/plugins/github_graphql/tasks/issue_extractor.go
+++ b/backend/plugins/github_graphql/tasks/issue_extractor.go
@@ -63,38 +63,35 @@ func ExtractIssues(taskCtx plugin.SubTaskContext) errors.Error {
Table: RAW_ISSUES_TABLE,
},
Extract: func(row *api.RawData) ([]interface{}, errors.Error) {
- apiIssue := &GraphqlQueryIssueWrapper{}
- err := errors.Convert(json.Unmarshal(row.Data, apiIssue))
+ issue := &GraphqlQueryIssue{}
+ err := errors.Convert(json.Unmarshal(row.Data, issue))
if err != nil {
return nil, err
}
- issues := apiIssue.Repository.IssueList.Issues
results := make([]interface{}, 0, 1)
- for _, issue := range issues {
- githubIssue, err := convertGithubIssue(milestoneMap, issue, data.Options.ConnectionId, data.Options.GithubId)
- if err != nil {
- return nil, err
- }
- githubLabels, err := convertGithubLabels(issueRegexes, issue, githubIssue)
- if err != nil {
- return nil, err
- }
- results = append(results, githubLabels...)
- results = append(results, githubIssue)
- 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,
- IssueId: githubIssue.GithubId,
- RepoId: githubIssue.RepoId,
- AssigneeId: assignee.Id,
- AssigneeName: assignee.Login,
- }
- results = append(results, issueAssignee)
+ githubIssue, err := convertGithubIssue(milestoneMap, issue, data.Options.ConnectionId, data.Options.GithubId)
+ if err != nil {
+ return nil, err
+ }
+ githubLabels, err := convertGithubLabels(issueRegexes, issue, githubIssue)
+ if err != nil {
+ return nil, err
+ }
+ results = append(results, githubLabels...)
+ results = append(results, githubIssue)
+ 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,
+ IssueId: githubIssue.GithubId,
+ RepoId: githubIssue.RepoId,
+ AssigneeId: assignee.Id,
+ AssigneeName: assignee.Login,
}
+ results = append(results, issueAssignee)
}
return results, nil
},
@@ -129,7 +126,7 @@ func getMilestoneMap(db dal.Dal, repoId int, connectionId uint64) (map[int]int,
return milestoneMap, nil
}
-func convertGithubIssue(milestoneMap map[int]int, issue GraphqlQueryIssue, connectionId uint64, repositoryId int) (*models.GithubIssue, errors.Error) {
+func convertGithubIssue(milestoneMap map[int]int, issue *GraphqlQueryIssue, connectionId uint64, repositoryId int) (*models.GithubIssue, errors.Error) {
githubIssue := &models.GithubIssue{
ConnectionId: connectionId,
GithubId: issue.DatabaseId,
@@ -163,7 +160,7 @@ func convertGithubIssue(milestoneMap map[int]int, issue GraphqlQueryIssue, conne
return githubIssue, nil
}
-func convertGithubLabels(issueRegexes *githubTasks.IssueRegexes, issue GraphqlQueryIssue, githubIssue *models.GithubIssue) ([]interface{}, errors.Error) {
+func convertGithubLabels(issueRegexes *githubTasks.IssueRegexes, issue *GraphqlQueryIssue, githubIssue *models.GithubIssue) ([]interface{}, errors.Error) {
var results []interface{}
var joinedLabels []string
for _, label := range issue.Labels.Nodes {