| 56 | } |
| 57 | |
| 58 | func ConvertAccounts(taskCtx plugin.SubTaskContext) errors.Error { |
| 59 | db := taskCtx.GetDal() |
| 60 | data := taskCtx.GetData().(*GithubTaskData) |
| 61 | |
| 62 | cursor, err := db.Cursor( |
| 63 | dal.Select("_tool_github_accounts.*"), |
| 64 | dal.From(&models.GithubAccount{}), |
| 65 | dal.Where( |
| 66 | "repo_github_id = ? and _tool_github_accounts.connection_id=?", |
| 67 | data.Options.GithubId, |
| 68 | data.Options.ConnectionId, |
| 69 | ), |
| 70 | dal.Join(`left join _tool_github_repo_accounts gra on ( |
| 71 | _tool_github_accounts.connection_id = gra.connection_id |
| 72 | AND _tool_github_accounts.id = gra.account_id |
| 73 | )`), |
| 74 | ) |
| 75 | if err != nil { |
| 76 | return err |
| 77 | } |
| 78 | defer cursor.Close() |
| 79 | |
| 80 | accountIdGen := didgen.NewDomainIdGenerator(&models.GithubAccount{}) |
| 81 | |
| 82 | converter, err := api.NewDataConverter(api.DataConverterArgs{ |
| 83 | InputRowType: reflect.TypeOf(models.GithubAccount{}), |
| 84 | Input: cursor, |
| 85 | RawDataSubTaskArgs: api.RawDataSubTaskArgs{ |
| 86 | Ctx: taskCtx, |
| 87 | Params: GithubApiParams{ |
| 88 | ConnectionId: data.Options.ConnectionId, |
| 89 | Name: data.Options.Name, |
| 90 | }, |
| 91 | Table: RAW_ACCOUNT_TABLE, |
| 92 | }, |
| 93 | Convert: func(inputRow interface{}) ([]interface{}, errors.Error) { |
| 94 | githubUser := inputRow.(*models.GithubAccount) |
| 95 | |
| 96 | // query related orgs |
| 97 | var orgs []string |
| 98 | err := db.Pluck(`org_login`, &orgs, |
| 99 | dal.From(&models.GithubAccountOrg{}), |
| 100 | dal.Where(`account_id = ? and connection_id = ?`, githubUser.Id, data.Options.ConnectionId), |
| 101 | ) |
| 102 | if err != nil { |
| 103 | return nil, err |
| 104 | } |
| 105 | var orgStr string |
| 106 | if len(orgs) == 0 { |
| 107 | orgStr = `` |
| 108 | } else { |
| 109 | orgStr = strings.Join(orgs, `,`) |
| 110 | if len(orgStr) > 255 { |
| 111 | orgStr = orgStr[:255] |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | domainUser := &crossdomain.Account{ |