| 37 | } |
| 38 | |
| 39 | func ConvertCommits(taskCtx plugin.SubTaskContext) errors.Error { |
| 40 | rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_COMMIT_TABLE) |
| 41 | db := taskCtx.GetDal() |
| 42 | repoId := data.Repo.GiteeId |
| 43 | |
| 44 | // select all commits belongs to the project |
| 45 | cursor, err := db.Cursor( |
| 46 | dal.Select("gc.*"), |
| 47 | dal.From("_tool_gitee_commits gc"), |
| 48 | dal.Join(`left join _tool_gitee_repo_commits grc on ( |
| 49 | grc.commit_sha = gc.sha |
| 50 | )`), |
| 51 | dal.Where("grc.repo_id = ? AND grc.connection_id = ?", repoId, data.Options.ConnectionId), |
| 52 | ) |
| 53 | if err != nil { |
| 54 | return err |
| 55 | } |
| 56 | defer cursor.Close() |
| 57 | |
| 58 | accountIdGen := didgen.NewDomainIdGenerator(&models.GiteeAccount{}) |
| 59 | repoDidGen := didgen.NewDomainIdGenerator(&models.GiteeRepo{}) |
| 60 | domainRepoId := repoDidGen.Generate(data.Options.ConnectionId, repoId) |
| 61 | |
| 62 | converter, err := helper.NewDataConverter(helper.DataConverterArgs{ |
| 63 | RawDataSubTaskArgs: *rawDataSubTaskArgs, |
| 64 | InputRowType: reflect.TypeOf(models.GiteeCommit{}), |
| 65 | Input: cursor, |
| 66 | |
| 67 | Convert: func(inputRow interface{}) ([]interface{}, errors.Error) { |
| 68 | giteeCommit := inputRow.(*models.GiteeCommit) |
| 69 | |
| 70 | // convert commit |
| 71 | commit := &code.Commit{} |
| 72 | commit.Sha = giteeCommit.Sha |
| 73 | commit.Message = giteeCommit.Message |
| 74 | commit.Additions = giteeCommit.Additions |
| 75 | commit.Deletions = giteeCommit.Deletions |
| 76 | commit.AuthorId = accountIdGen.Generate(data.Options.ConnectionId, giteeCommit.AuthorId) |
| 77 | commit.AuthorName = giteeCommit.AuthorName |
| 78 | commit.AuthorEmail = giteeCommit.AuthorEmail |
| 79 | commit.AuthoredDate = giteeCommit.AuthoredDate |
| 80 | commit.CommitterName = giteeCommit.CommitterName |
| 81 | commit.CommitterEmail = giteeCommit.CommitterEmail |
| 82 | commit.CommittedDate = giteeCommit.CommittedDate |
| 83 | commit.CommitterId = accountIdGen.Generate(data.Options.ConnectionId, giteeCommit.CommitterId) |
| 84 | |
| 85 | // convert repo / commits relationship |
| 86 | repoCommit := &code.RepoCommit{ |
| 87 | RepoId: domainRepoId, |
| 88 | CommitSha: giteeCommit.Sha, |
| 89 | } |
| 90 | |
| 91 | return []interface{}{ |
| 92 | commit, |
| 93 | repoCommit, |
| 94 | }, nil |
| 95 | }, |
| 96 | }) |