(taskCtx plugin.TaskContext, options map[string]interface{})
| 123 | } |
| 124 | |
| 125 | func (p Gitlab) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]interface{}) (interface{}, errors.Error) { |
| 126 | logger := taskCtx.GetLogger() |
| 127 | logger.Debug("%v", options) |
| 128 | op, err := tasks.DecodeAndValidateTaskOptions(options) |
| 129 | if err != nil { |
| 130 | return nil, err |
| 131 | } |
| 132 | if op.ConnectionId == 0 { |
| 133 | return nil, errors.BadInput.New("connectionId is invalid") |
| 134 | } |
| 135 | connection := &models.GitlabConnection{} |
| 136 | connectionHelper := helper.NewConnectionHelper( |
| 137 | taskCtx, |
| 138 | nil, |
| 139 | p.Name(), |
| 140 | ) |
| 141 | if err != nil { |
| 142 | return nil, err |
| 143 | } |
| 144 | err = connectionHelper.FirstById(connection, op.ConnectionId) |
| 145 | if err != nil { |
| 146 | return nil, errors.BadInput.Wrap(err, "connection not found") |
| 147 | } |
| 148 | |
| 149 | apiClient, err := tasks.NewGitlabApiClient(taskCtx, connection) |
| 150 | if err != nil { |
| 151 | return nil, err |
| 152 | } |
| 153 | if op.ProjectId != 0 { |
| 154 | var scope *models.GitlabProject |
| 155 | // support v100 & advance mode |
| 156 | // If we still cannot find the record in db, we have to request from remote server and save it to db |
| 157 | db := taskCtx.GetDal() |
| 158 | err = db.First(&scope, dal.Where("connection_id = ? AND gitlab_id = ?", op.ConnectionId, op.ProjectId)) |
| 159 | if err == nil { |
| 160 | if op.ScopeConfigId == 0 && scope.ScopeConfigId != 0 { |
| 161 | op.ScopeConfigId = scope.ScopeConfigId |
| 162 | } |
| 163 | } |
| 164 | if err != nil && db.IsErrorNotFound(err) { |
| 165 | var project *models.GitlabApiProject |
| 166 | project, err = api.GetApiProject(op, apiClient) |
| 167 | if err != nil { |
| 168 | return nil, err |
| 169 | } |
| 170 | logger.Debug(fmt.Sprintf("Current project: %d", project.GitlabId)) |
| 171 | scope := project.ConvertApiScope() |
| 172 | scope.ConnectionId = op.ConnectionId |
| 173 | err = taskCtx.GetDal().CreateIfNotExist(scope) |
| 174 | if err != nil { |
| 175 | return nil, err |
| 176 | } |
| 177 | } |
| 178 | if err != nil { |
| 179 | return nil, errors.Default.Wrap(err, fmt.Sprintf("fail to find project: %d", op.ProjectId)) |
| 180 | } |
| 181 | } |
| 182 |
nothing calls this directly
no test coverage detected