| 139 | } |
| 140 | |
| 141 | func (p Bitbucket) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]interface{}) (interface{}, errors.Error) { |
| 142 | logger := taskCtx.GetLogger() |
| 143 | logger.Debug("%v", options) |
| 144 | op, err := tasks.DecodeAndValidateTaskOptions(options) |
| 145 | if err != nil { |
| 146 | return nil, err |
| 147 | } |
| 148 | connectionHelper := helper.NewConnectionHelper( |
| 149 | taskCtx, |
| 150 | nil, |
| 151 | p.Name(), |
| 152 | ) |
| 153 | connection := &models.BitbucketConnection{} |
| 154 | err = connectionHelper.FirstById(connection, op.ConnectionId) |
| 155 | if err != nil { |
| 156 | return nil, errors.Default.Wrap(err, "unable to get bitbucket connection by the given connection ID") |
| 157 | } |
| 158 | |
| 159 | apiClient, err := tasks.CreateApiClient(taskCtx, connection) |
| 160 | if err != nil { |
| 161 | return nil, errors.Default.Wrap(err, "unable to get bitbucket API client instance") |
| 162 | } |
| 163 | err = EnrichOptions(taskCtx, op, apiClient.ApiClient) |
| 164 | if err != nil { |
| 165 | return nil, err |
| 166 | } |
| 167 | |
| 168 | regexEnricher := helper.NewRegexEnricher() |
| 169 | if err := regexEnricher.TryAdd(devops.DEPLOYMENT, op.DeploymentPattern); err != nil { |
| 170 | return nil, errors.BadInput.Wrap(err, "invalid value for `deploymentPattern`") |
| 171 | } |
| 172 | if err := regexEnricher.TryAdd(devops.PRODUCTION, op.ProductionPattern); err != nil { |
| 173 | return nil, errors.BadInput.Wrap(err, "invalid value for `productionPattern`") |
| 174 | } |
| 175 | taskData := &tasks.BitbucketTaskData{ |
| 176 | Options: op, |
| 177 | ApiClient: apiClient, |
| 178 | RegexEnricher: regexEnricher, |
| 179 | } |
| 180 | |
| 181 | return taskData, nil |
| 182 | } |
| 183 | |
| 184 | func (p Bitbucket) RootPkgPath() string { |
| 185 | return "github.com/apache/incubator-devlake/plugins/bitbucket/" // the "/" fixes an issue where records from "bitbucket_server" are counted as "bitbucket" records and vice versa |