(taskCtx plugin.TaskContext, options map[string]interface{})
| 112 | } |
| 113 | |
| 114 | func (p Sonarqube) PrepareTaskData(taskCtx plugin.TaskContext, options map[string]interface{}) (interface{}, errors.Error) { |
| 115 | logger := taskCtx.GetLogger() |
| 116 | op, err := tasks.DecodeAndValidateTaskOptions(options) |
| 117 | if err != nil { |
| 118 | return nil, err |
| 119 | } |
| 120 | connectionHelper := helper.NewConnectionHelper( |
| 121 | taskCtx, |
| 122 | nil, |
| 123 | p.Name(), |
| 124 | ) |
| 125 | connection := &models.SonarqubeConnection{} |
| 126 | err = connectionHelper.FirstById(connection, op.ConnectionId) |
| 127 | if err != nil { |
| 128 | return nil, errors.Default.Wrap(err, "unable to get Sonarqube connection by the given connection ID") |
| 129 | } |
| 130 | |
| 131 | apiClient, err := tasks.CreateApiClient(taskCtx, connection) |
| 132 | if err != nil { |
| 133 | return nil, errors.Default.Wrap(err, "unable to get Sonarqube API client instance") |
| 134 | } |
| 135 | taskData := &tasks.SonarqubeTaskData{ |
| 136 | Options: op, |
| 137 | ApiClient: apiClient, |
| 138 | TaskStartTime: time.Now(), |
| 139 | IsCloud: connection.IsCloud(), |
| 140 | } |
| 141 | // even we have project in _tool_sonaqube_projects, we still need to collect project to update LastAnalysisDate |
| 142 | var apiProject *models.SonarqubeApiProject |
| 143 | apiProject, err = api.GetApiProject(op.ProjectKey, apiClient) |
| 144 | if err != nil { |
| 145 | return nil, err |
| 146 | } |
| 147 | logger.Debug(fmt.Sprintf("Current project: %s", apiProject.ProjectKey)) |
| 148 | scope := apiProject.ConvertApiScope() |
| 149 | scope.ConnectionId = op.ConnectionId |
| 150 | err = taskCtx.GetDal().CreateOrUpdate(&scope) |
| 151 | if err != nil { |
| 152 | return nil, err |
| 153 | } |
| 154 | taskData.LastAnalysisDate = scope.LastAnalysisDate.ToNullableTime() |
| 155 | |
| 156 | return taskData, nil |
| 157 | } |
| 158 | |
| 159 | // RootPkgPath information lost when compiled as plugin(.so) |
| 160 | func (p Sonarqube) RootPkgPath() string { |
nothing calls this directly
no test coverage detected