| 122 | } |
| 123 | |
| 124 | func (p Github) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]interface{}) (interface{}, errors.Error) { |
| 125 | logger := taskCtx.GetLogger() |
| 126 | logger.Debug("%v", options) |
| 127 | op, err := tasks.DecodeTaskOptions(options) |
| 128 | if err != nil { |
| 129 | return nil, err |
| 130 | } |
| 131 | connectionHelper := helper.NewConnectionHelper( |
| 132 | taskCtx, |
| 133 | nil, |
| 134 | p.Name(), |
| 135 | ) |
| 136 | connection := &models.GithubConnection{} |
| 137 | err = connectionHelper.FirstById(connection, op.ConnectionId) |
| 138 | if err != nil { |
| 139 | return nil, errors.Default.Wrap(err, "unable to get github connection by the given connection ID") |
| 140 | } |
| 141 | apiClient, err := tasks.CreateApiClient(taskCtx, connection) |
| 142 | if err != nil { |
| 143 | return nil, errors.Default.Wrap(err, "unable to get github API client instance") |
| 144 | } |
| 145 | err = EnrichOptions(taskCtx, op, apiClient.ApiClient) |
| 146 | if err != nil { |
| 147 | return nil, err |
| 148 | } |
| 149 | |
| 150 | regexEnricher := helper.NewRegexEnricher() |
| 151 | if err = regexEnricher.TryAdd(devops.DEPLOYMENT, op.ScopeConfig.DeploymentPattern); err != nil { |
| 152 | return nil, errors.BadInput.Wrap(err, "invalid value for `deploymentPattern`") |
| 153 | } |
| 154 | if err = regexEnricher.TryAdd(devops.PRODUCTION, op.ScopeConfig.ProductionPattern); err != nil { |
| 155 | return nil, errors.BadInput.Wrap(err, "invalid value for `productionPattern`") |
| 156 | } |
| 157 | if err = regexEnricher.TryAdd(devops.ENV_NAME_PATTERN, op.ScopeConfig.EnvNamePattern); err != nil { |
| 158 | return nil, errors.BadInput.Wrap(err, "invalid value for `envNamePattern`") |
| 159 | } |
| 160 | |
| 161 | taskData := &tasks.GithubTaskData{ |
| 162 | Options: op, |
| 163 | ApiClient: apiClient, |
| 164 | RegexEnricher: regexEnricher, |
| 165 | } |
| 166 | |
| 167 | return taskData, nil |
| 168 | } |
| 169 | |
| 170 | func (p Github) RootPkgPath() string { |
| 171 | return "github.com/apache/incubator-devlake/plugins/github" |