warren830 commented on code in PR #4357: URL: https://github.com/apache/incubator-devlake/pull/4357#discussion_r1099769133
########## backend/plugins/sonarqube/tasks/issue_code_blocks_convertor.go: ########## @@ -0,0 +1,89 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package tasks + +import ( + "reflect" + + "github.com/apache/incubator-devlake/core/models/domainlayer/securitytesting" + + "github.com/apache/incubator-devlake/core/dal" + "github.com/apache/incubator-devlake/core/errors" + "github.com/apache/incubator-devlake/core/models/domainlayer" + "github.com/apache/incubator-devlake/core/models/domainlayer/didgen" + "github.com/apache/incubator-devlake/core/plugin" + "github.com/apache/incubator-devlake/helpers/pluginhelper/api" + "github.com/apache/incubator-devlake/plugins/sonarqube/models" +) + +func ConvertIssueCodeBlocks(taskCtx plugin.SubTaskContext) errors.Error { + db := taskCtx.GetDal() + data := taskCtx.GetData().(*SonarqubeTaskData) + + cursor, err := db.Cursor(dal.From(&models.SonarqubeIssueCodeBlock{}), dal.Where("connection_id = ?", data.Options.ConnectionId)) + if err != nil { + return err + } + defer cursor.Close() + + idGen := didgen.NewDomainIdGenerator(&models.SonarqubeIssueCodeBlock{}) + converter, err := api.NewDataConverter(api.DataConverterArgs{ + InputRowType: reflect.TypeOf(models.SonarqubeIssueCodeBlock{}), + Input: cursor, + RawDataSubTaskArgs: api.RawDataSubTaskArgs{ + Ctx: taskCtx, + Params: SonarqubeApiParams{ + ConnectionId: data.Options.ConnectionId, + ProjectKey: data.Options.ProjectKey, + }, + Table: RAW_ISSUES_TABLE, + }, + Convert: func(inputRow interface{}) ([]interface{}, errors.Error) { + sonarqubeIssueCodeBlock := inputRow.(*models.SonarqubeIssueCodeBlock) + domainIssueCodeBlock := &securitytesting.StIssueCodeBlock{ + DomainEntity: domainlayer.DomainEntity{Id: idGen.Generate(data.Options.ConnectionId, sonarqubeIssueCodeBlock.Id)}, + Id: sonarqubeIssueCodeBlock.Id, + IssueKey: sonarqubeIssueCodeBlock.IssueKey, + Component: sonarqubeIssueCodeBlock.Component, + Msg: sonarqubeIssueCodeBlock.Msg, + StartLine: sonarqubeIssueCodeBlock.StartLine, + EndLine: sonarqubeIssueCodeBlock.EndLine, + StartOffset: sonarqubeIssueCodeBlock.StartOffset, + EndOffset: sonarqubeIssueCodeBlock.EndOffset, + } + + return []interface{}{ + domainIssueCodeBlock, + }, nil + }, + }) + + if err != nil { + return err + } + + return converter.Execute() +} + +var ConvertIssueCodeBlocksMeta = plugin.SubTaskMeta{ + Name: "convertIssueCodeBlocks", + EntryPoint: ConvertIssueCodeBlocks, + EnabledByDefault: true, + Description: "Convert tool layer table sonarqube_accounts into domain layer table accounts", Review Comment: not accounts here -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
