keon94 commented on code in PR #2215:
URL: https://github.com/apache/incubator-devlake/pull/2215#discussion_r910445671


##########
plugins/github/tasks/milestone_converter.go:
##########
@@ -0,0 +1,119 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package tasks
+
+import (
+       "github.com/apache/incubator-devlake/models/common"
+       "github.com/apache/incubator-devlake/models/domainlayer"
+       "github.com/apache/incubator-devlake/models/domainlayer/didgen"
+       "github.com/apache/incubator-devlake/models/domainlayer/ticket"
+       "github.com/apache/incubator-devlake/plugins/core"
+       "github.com/apache/incubator-devlake/plugins/core/dal"
+       githubModels "github.com/apache/incubator-devlake/plugins/github/models"
+       "github.com/apache/incubator-devlake/plugins/helper"
+       "reflect"
+)
+
+var ConvertMilestonesMeta = core.SubTaskMeta{
+       Name:             "convertMilestones",
+       EntryPoint:       ConvertMilestones,
+       EnabledByDefault: true,
+       Description:      "Convert tool layer table github_milestones into  
domain layer table milestones",
+}
+
+type MilestoneConverterModel struct {
+       common.RawDataOrigin
+       githubModels.GithubMilestone
+       GithubId int
+}
+
+func ConvertMilestones(taskCtx core.SubTaskContext) error {
+       data := taskCtx.GetData().(*GithubTaskData)
+       repoId := data.Repo.GithubId
+       connectionId := data.Repo.ConnectionId
+       db := taskCtx.GetDal()
+       clauses := []dal.Clause{
+               dal.Select("gi.github_id, gm.*"),
+               dal.From("_tool_github_issues gi"),
+               dal.Join("JOIN _tool_github_milestones gm ON gm.milestone_id = 
gi.milestone_id"),
+               dal.Where("gm.repo_id = ?", repoId),
+       }
+       cursor, err := db.Cursor(clauses...)
+       if err != nil {
+               return err
+       }
+       defer cursor.Close()
+
+       boardIdGen := didgen.NewDomainIdGenerator(&githubModels.GithubRepo{})
+       domainBoardId := boardIdGen.Generate(connectionId, repoId)
+       sprintIdGen := 
didgen.NewDomainIdGenerator(&githubModels.GithubMilestone{})
+       issueIdGen := didgen.NewDomainIdGenerator(&githubModels.GithubIssue{})
+
+       converter, err := helper.NewDataConverter(helper.DataConverterArgs{
+               RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
+                       Ctx: taskCtx,
+                       Params: GithubApiParams{
+                               Owner: data.Options.Owner,
+                               Repo:  data.Options.Repo,
+                       },
+                       Table: RAW_MILESTONE_TABLE,
+               },
+               InputRowType: reflect.TypeOf(MilestoneConverterModel{}),
+               Input:        cursor,
+               Convert: func(inputRow interface{}) ([]interface{}, error) {
+                       response := inputRow.(*MilestoneConverterModel)
+                       domainSprintId := 
sprintIdGen.Generate(response.GithubMilestone.MilestoneId)

Review Comment:
   Yeah, this was causing errors, but it should be fixed now



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to