| package tasks |
| |
| import ( |
| "reflect" |
| |
| "github.com/merico-dev/lake/models/domainlayer/crossdomain" |
| "github.com/merico-dev/lake/models/domainlayer/didgen" |
| "github.com/merico-dev/lake/plugins/core" |
| "github.com/merico-dev/lake/plugins/helper" |
| "github.com/merico-dev/lake/plugins/jira/models" |
| ) |
| |
| func ConvertIssueCommits(taskCtx core.SubTaskContext) error { |
| data := taskCtx.GetData().(*JiraTaskData) |
| db := taskCtx.GetDb() |
| connectionId := data.Connection.ID |
| boardId := data.Options.BoardId |
| logger := taskCtx.GetLogger() |
| logger.Info("convert issue commits") |
| |
| cursor, err := db.Table("_tool_jira_issue_commits jic"). |
| Joins(`left join _tool_jira_board_issues jbi on ( |
| jbi.connection_id = jic.connection_id |
| AND jbi.issue_id = jic.issue_id |
| )`). |
| Select("jic.*"). |
| Where("jbi.connection_id = ? AND jbi.board_id = ?", connectionId, boardId). |
| Order("jbi.connection_id, jbi.issue_id"). |
| Rows() |
| if err != nil { |
| return err |
| } |
| defer cursor.Close() |
| |
| issueIdGenerator := didgen.NewDomainIdGenerator(&models.JiraIssue{}) |
| converter, err := helper.NewDataConverter(helper.DataConverterArgs{ |
| RawDataSubTaskArgs: helper.RawDataSubTaskArgs{ |
| Ctx: taskCtx, |
| Params: JiraApiParams{ |
| ConnectionId: connectionId, |
| BoardId: boardId, |
| }, |
| Table: RAW_REMOTELINK_TABLE, |
| }, |
| InputRowType: reflect.TypeOf(models.JiraIssueCommit{}), |
| Input: cursor, |
| Convert: func(inputRow interface{}) ([]interface{}, error) { |
| var result []interface{} |
| issueCommit := inputRow.(*models.JiraIssueCommit) |
| item := &crossdomain.IssueCommit{ |
| IssueId: issueIdGenerator.Generate(connectionId, issueCommit.IssueId), |
| CommitSha: issueCommit.CommitSha, |
| } |
| result = append(result, item) |
| return result, nil |
| }, |
| }) |
| if err != nil { |
| return err |
| } |
| |
| return converter.Execute() |
| } |