You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by GitBox <gi...@apache.org> on 2022/06/17 07:43:30 UTC

[GitHub] [incubator-devlake] klesh commented on a diff in pull request #2204: github comment task refactor

klesh commented on code in PR #2204:
URL: https://github.com/apache/incubator-devlake/pull/2204#discussion_r899829354


##########
helpers/e2ehelper/data_flow_tester.go:
##########
@@ -98,16 +98,37 @@ func NewDataFlowTester(t *testing.T, pluginName string, pluginMeta core.PluginMe
 	}
 }
 
-// ImportCsvIntoRawTable imports records from specified csv file into target table, note that existing data would be deleted first.
-func (t *DataFlowTester) ImportCsvIntoRawTable(csvRelPath string, tableName string) {
+// ImportCsvIntoRawTable imports records from specified csv file into target raw table, note that existing data would be deleted first.
+func (t *DataFlowTester) ImportCsvIntoRawTable(csvRelPath string, rawTableName string) {
 	csvIter := pluginhelper.NewCsvFileIterator(csvRelPath)
 	defer csvIter.Close()
-	t.FlushRawTable(tableName)
+	t.FlushRawTable(rawTableName)
 	// load rows and insert into target table
 	for csvIter.HasNext() {
 		toInsertValues := csvIter.Fetch()
 		toInsertValues[`data`] = json.RawMessage(toInsertValues[`data`].(string))
-		result := t.Db.Table(tableName).Create(toInsertValues)
+		result := t.Db.Table(rawTableName).Create(toInsertValues)
+		if result.Error != nil {
+			panic(result.Error)
+		}
+		assert.Equal(t.T, int64(1), result.RowsAffected)
+	}
+}
+
+// ImportCsvIntoTabler imports records from specified csv file into target tabler, note that existing data would be deleted first.
+func (t *DataFlowTester) ImportCsvIntoTabler(csvRelPath string, dst schema.Tabler) {
+	csvIter := pluginhelper.NewCsvFileIterator(csvRelPath)
+	defer csvIter.Close()
+	t.FlushTabler(dst)
+	// load rows and insert into target table
+	for csvIter.HasNext() {
+		toInsertValues := csvIter.Fetch()

Review Comment:
   This value doesn't seem to be used anywhere?



##########
helpers/e2ehelper/data_flow_tester.go:
##########
@@ -98,16 +98,37 @@ func NewDataFlowTester(t *testing.T, pluginName string, pluginMeta core.PluginMe
 	}
 }
 
-// ImportCsvIntoRawTable imports records from specified csv file into target table, note that existing data would be deleted first.
-func (t *DataFlowTester) ImportCsvIntoRawTable(csvRelPath string, tableName string) {
+// ImportCsvIntoRawTable imports records from specified csv file into target raw table, note that existing data would be deleted first.
+func (t *DataFlowTester) ImportCsvIntoRawTable(csvRelPath string, rawTableName string) {
 	csvIter := pluginhelper.NewCsvFileIterator(csvRelPath)
 	defer csvIter.Close()
-	t.FlushRawTable(tableName)
+	t.FlushRawTable(rawTableName)
 	// load rows and insert into target table
 	for csvIter.HasNext() {
 		toInsertValues := csvIter.Fetch()
 		toInsertValues[`data`] = json.RawMessage(toInsertValues[`data`].(string))
-		result := t.Db.Table(tableName).Create(toInsertValues)
+		result := t.Db.Table(rawTableName).Create(toInsertValues)
+		if result.Error != nil {
+			panic(result.Error)
+		}
+		assert.Equal(t.T, int64(1), result.RowsAffected)
+	}
+}
+
+// ImportCsvIntoTabler imports records from specified csv file into target tabler, note that existing data would be deleted first.
+func (t *DataFlowTester) ImportCsvIntoTabler(csvRelPath string, dst schema.Tabler) {
+	csvIter := pluginhelper.NewCsvFileIterator(csvRelPath)
+	defer csvIter.Close()
+	t.FlushTabler(dst)
+	// load rows and insert into target table
+	for csvIter.HasNext() {
+		toInsertValues := csvIter.Fetch()
+		for i := range toInsertValues {
+			if toInsertValues[i].(string) == `` {
+				toInsertValues[i] = nil
+			}
+		}
+		result := t.Db.Model(dst).Create(csvIter.Fetch())

Review Comment:
   Looks like `csvIter. Fetch()` should be replaced with `toInsertValues`



##########
plugins/github/tasks/comment_collector.go:
##########
@@ -43,18 +44,26 @@ func CollectApiComments(taskCtx core.SubTaskContext) error {
 	// actually, for github pull, since doesn't make any sense, github pull api doesn't support it

Review Comment:
   line 43, 44 can be deleted



##########
plugins/github/e2e/comment_test.go:
##########
@@ -0,0 +1,135 @@
+/*
+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 e2e
+
+import (
+	"fmt"
+	"github.com/apache/incubator-devlake/models/domainlayer/code"
+	"github.com/apache/incubator-devlake/models/domainlayer/ticket"
+	"github.com/apache/incubator-devlake/plugins/github/models"
+	"github.com/apache/incubator-devlake/plugins/github/tasks"
+	"testing"
+
+	"github.com/apache/incubator-devlake/helpers/e2ehelper"
+	"github.com/apache/incubator-devlake/plugins/github/impl"
+)
+
+func TestCommentDataFlow(t *testing.T) {
+	var plugin impl.Github
+	dataflowTester := e2ehelper.NewDataFlowTester(t, "gitlab", plugin)
+
+	githubRepository := &models.GithubRepo{
+		GithubId: 134018330,
+	}
+	taskData := &tasks.GithubTaskData{
+		Options: &tasks.GithubOptions{
+			ConnectionId: 1,
+			Owner:        "panjf2000",
+			Repo:         "ants",
+			Config: models.Config{
+				PrType:               "type/(.*)$",
+				PrComponent:          "component/(.*)$",
+				PrBodyClosePattern:   "(?mi)(fix|close|resolve|fixes|closes|resolves|fixed|closed|resolved)[\\s]*.*(((and )?(#|https:\\/\\/github.com\\/%s\\/%s\\/issues\\/)\\d+[ ]*)+)",
+				IssueSeverity:        "severity/(.*)$",
+				IssuePriority:        "^(highest|high|medium|low)$",
+				IssueComponent:       "component/(.*)$",
+				IssueTypeBug:         "^(bug|failure|error)$",
+				IssueTypeIncident:    "",
+				IssueTypeRequirement: "^(feat|feature|proposal|requirement)$",
+			},
+		},
+		Repo: githubRepository,
+	}
+
+	// import raw data table
+	dataflowTester.ImportCsvIntoRawTable("./raw_tables/_raw_github_api_comments.csv", "_raw_github_api_comments")
+	dataflowTester.ImportCsvIntoTabler(fmt.Sprintf("./snapshot_tables/%s.csv", models.GithubIssue{}.TableName()), &models.GithubIssue{})

Review Comment:
   Hardcode this and following 2 lines pls



-- 
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: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org