You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by zh...@apache.org on 2022/06/21 02:43:02 UTC

[incubator-devlake] branch main updated: fix: linting (#2275)

This is an automated email from the ASF dual-hosted git repository.

zhangliang2022 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new dcd64119 fix: linting (#2275)
dcd64119 is described below

commit dcd641191765fb6068ee4012f3f85c86746933d1
Author: Klesh Wong <zh...@merico.dev>
AuthorDate: Tue Jun 21 10:42:58 2022 +0800

    fix: linting (#2275)
---
 impl/dalgorm/dalgorm.go                            |  3 +--
 plugins/gitextractor/store/database.go             |  1 -
 plugins/helper/api_extractor.go                    | 24 ++++++++++++++--------
 plugins/helper/batch_save_divider.go               |  9 ++++----
 plugins/helper/connection.go                       | 15 +++++++-------
 plugins/helper/data_convertor.go                   |  4 ++--
 plugins/jira/models/issue_label.go                 | 17 +++++++++++++++
 .../migrationscripts/updateSchemas20220615.go      |  2 ++
 plugins/jira/tasks/issue_collector.go              | 12 ++++++-----
 services/blueprint.go                              |  2 +-
 10 files changed, 56 insertions(+), 33 deletions(-)

diff --git a/impl/dalgorm/dalgorm.go b/impl/dalgorm/dalgorm.go
index 51e72c44..72aafd3e 100644
--- a/impl/dalgorm/dalgorm.go
+++ b/impl/dalgorm/dalgorm.go
@@ -19,7 +19,6 @@ package dalgorm
 
 import (
 	"database/sql"
-	"fmt"
 	"strings"
 
 	"github.com/apache/incubator-devlake/plugins/core/dal"
@@ -154,7 +153,7 @@ func (d *Dalgorm) Delete(entity interface{}, clauses ...dal.Clause) error {
 func (d *Dalgorm) AllTables() ([]string, error) {
 	var tableSql string
 	if d.db.Dialector.Name() == "mysql" {
-		tableSql = fmt.Sprintf("show tables")
+		tableSql = "show tables"
 	} else {
 		tableSql = "select table_name from information_schema.tables where table_schema = 'public' and table_name not like '_devlake%'"
 	}
diff --git a/plugins/gitextractor/store/database.go b/plugins/gitextractor/store/database.go
index 68be40b5..b050da94 100644
--- a/plugins/gitextractor/store/database.go
+++ b/plugins/gitextractor/store/database.go
@@ -31,7 +31,6 @@ const BathSize = 100
 type Database struct {
 	//db     *gorm.DB
 	driver *helper.BatchSaveDivider
-	log    core.Logger
 }
 
 func NewDatabase(basicRes core.BasicRes, repoUrl string) *Database {
diff --git a/plugins/helper/api_extractor.go b/plugins/helper/api_extractor.go
index 25fe4b95..55a24876 100644
--- a/plugins/helper/api_extractor.go
+++ b/plugins/helper/api_extractor.go
@@ -23,6 +23,7 @@ import (
 	"github.com/apache/incubator-devlake/models/common"
 
 	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
 )
 
 type ApiExtractorArgs struct {
@@ -61,15 +62,20 @@ func NewApiExtractor(args ApiExtractorArgs) (*ApiExtractor, error) {
 // Execute sub-task
 func (extractor *ApiExtractor) Execute() error {
 	// load data from database
-	db := extractor.args.Ctx.GetDb()
+	db := extractor.args.Ctx.GetDal()
 	log := extractor.args.Ctx.GetLogger()
-	count := int64(0)
-	cursor, err := db.
-		Table(extractor.table).
-		Order("id ASC").
-		Where("params = ?", extractor.params).
-		Count(&count).
-		Rows()
+
+	clauses := []dal.Clause{
+		dal.From(extractor.table),
+		dal.Where("params = ?", extractor.params),
+		dal.Orderby("id ASC"),
+	}
+
+	count, err := db.Count(clauses...)
+	if err != nil {
+		return err
+	}
+	cursor, err := db.Cursor(clauses...)
 	if err != nil {
 		return err
 	}
@@ -91,7 +97,7 @@ func (extractor *ApiExtractor) Execute() error {
 			return ctx.Err()
 		default:
 		}
-		err = db.ScanRows(cursor, row)
+		err = db.Fetch(cursor, row)
 		if err != nil {
 			return err
 		}
diff --git a/plugins/helper/batch_save_divider.go b/plugins/helper/batch_save_divider.go
index 6f1cbffb..6ec3c626 100644
--- a/plugins/helper/batch_save_divider.go
+++ b/plugins/helper/batch_save_divider.go
@@ -75,18 +75,17 @@ func (d *BatchSaveDivider) ForType(rowType reflect.Type) (*BatchSave, error) {
 		}
 		// all good, delete outdated records before we insertion
 		d.log.Debug("deleting outdate records for %s", rowElemType.Name())
-		d.db.Delete(
+		err = d.db.Delete(
 			row,
 			dal.Where("_raw_data_table = ? AND _raw_data_params = ?", d.table, d.params),
 		)
+		if err != nil {
+			return nil, err
+		}
 	}
 	return batch, nil
 }
 
-func (d *BatchSaveDivider) flushBatch() {
-
-}
-
 // Close all batches so the rest records get saved into db
 func (d *BatchSaveDivider) Close() error {
 	for _, batch := range d.batches {
diff --git a/plugins/helper/connection.go b/plugins/helper/connection.go
index 14d66a65..495b9769 100644
--- a/plugins/helper/connection.go
+++ b/plugins/helper/connection.go
@@ -25,10 +25,9 @@ import (
 
 	"github.com/apache/incubator-devlake/models/common"
 	"github.com/apache/incubator-devlake/plugins/core"
+	"github.com/apache/incubator-devlake/plugins/core/dal"
 	"github.com/go-playground/validator/v10"
 	"github.com/mitchellh/mapstructure"
-	"gorm.io/gorm"
-	"gorm.io/gorm/clause"
 )
 
 type BaseConnection struct {
@@ -64,7 +63,7 @@ type RestConnection struct {
 type ConnectionApiHelper struct {
 	encKey    string
 	log       core.Logger
-	db        *gorm.DB
+	db        dal.Dal
 	validator *validator.Validate
 }
 
@@ -78,7 +77,7 @@ func NewConnectionHelper(
 	return &ConnectionApiHelper{
 		encKey:    basicRes.GetConfig(core.EncodeKeyEnvStr),
 		log:       basicRes.GetLogger(),
-		db:        basicRes.GetDb(),
+		db:        basicRes.GetDal(),
 		validator: vld,
 	}
 }
@@ -120,7 +119,7 @@ func (c *ConnectionApiHelper) First(connection interface{}, params map[string]st
 }
 
 func (c *ConnectionApiHelper) FirstById(connection interface{}, id uint64) error {
-	err := c.db.First(connection, "id = ?", id).Error
+	err := c.db.First(connection, dal.Where("id = ?", id))
 	if err != nil {
 		return err
 	}
@@ -130,7 +129,7 @@ func (c *ConnectionApiHelper) FirstById(connection interface{}, id uint64) error
 
 // List returns all connections with password/token decrypted
 func (c *ConnectionApiHelper) List(connections interface{}) error {
-	err := c.db.Find(connections).Error
+	err := c.db.All(connections)
 	if err != nil {
 		return err
 	}
@@ -143,7 +142,7 @@ func (c *ConnectionApiHelper) List(connections interface{}) error {
 
 // Delete connection
 func (c *ConnectionApiHelper) Delete(connection interface{}) error {
-	return c.db.Delete(connection).Error
+	return c.db.Delete(connection)
 }
 
 func (c *ConnectionApiHelper) merge(connection interface{}, body map[string]interface{}) error {
@@ -164,7 +163,7 @@ func (c *ConnectionApiHelper) merge(connection interface{}, body map[string]inte
 func (c *ConnectionApiHelper) save(connection interface{}) error {
 	c.encrypt(connection)
 
-	err := c.db.Clauses(clause.OnConflict{UpdateAll: true}).Create(connection).Error
+	err := c.db.CreateOrUpdate(connection)
 	if err != nil {
 		return err
 	}
diff --git a/plugins/helper/data_convertor.go b/plugins/helper/data_convertor.go
index 071d5f69..b4ede7c3 100644
--- a/plugins/helper/data_convertor.go
+++ b/plugins/helper/data_convertor.go
@@ -64,7 +64,7 @@ func NewDataConverter(args DataConverterArgs) (*DataConverter, error) {
 
 func (converter *DataConverter) Execute() error {
 	// load data from database
-	db := converter.args.Ctx.GetDb()
+	db := converter.args.Ctx.GetDal()
 
 	// batch save divider
 	RAW_DATA_ORIGIN := "RawDataOrigin"
@@ -84,7 +84,7 @@ func (converter *DataConverter) Execute() error {
 		default:
 		}
 		inputRow := reflect.New(converter.args.InputRowType).Interface()
-		err := db.ScanRows(cursor, inputRow)
+		err := db.Fetch(cursor, inputRow)
 		if err != nil {
 			return err
 		}
diff --git a/plugins/jira/models/issue_label.go b/plugins/jira/models/issue_label.go
index 0f9cfbdd..6f9e075e 100644
--- a/plugins/jira/models/issue_label.go
+++ b/plugins/jira/models/issue_label.go
@@ -1,3 +1,20 @@
+/*
+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 models
 
 import (
diff --git a/plugins/jira/models/migrationscripts/updateSchemas20220615.go b/plugins/jira/models/migrationscripts/updateSchemas20220615.go
index f374ede6..f527cdde 100644
--- a/plugins/jira/models/migrationscripts/updateSchemas20220615.go
+++ b/plugins/jira/models/migrationscripts/updateSchemas20220615.go
@@ -5,7 +5,9 @@ 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.
diff --git a/plugins/jira/tasks/issue_collector.go b/plugins/jira/tasks/issue_collector.go
index 7cea5218..a34d0637 100644
--- a/plugins/jira/tasks/issue_collector.go
+++ b/plugins/jira/tasks/issue_collector.go
@@ -20,11 +20,12 @@ package tasks
 import (
 	"encoding/json"
 	"fmt"
-	"github.com/apache/incubator-devlake/plugins/core/dal"
 	"io/ioutil"
 	"net/http"
 	"net/url"
 
+	"github.com/apache/incubator-devlake/plugins/core/dal"
+
 	"github.com/apache/incubator-devlake/plugins/core"
 	"github.com/apache/incubator-devlake/plugins/helper"
 	"github.com/apache/incubator-devlake/plugins/jira/models"
@@ -50,10 +51,11 @@ func CollectIssues(taskCtx core.SubTaskContext) error {
 	if since == nil {
 		var latestUpdated models.JiraIssue
 		clauses := []dal.Clause{
-			dal.Select("*"),
-			dal.From(&latestUpdated),
-			dal.Where("connection_id = ? and board_id = ?", data.Connection.ID, data.Options.BoardId),
-			dal.Orderby("updated DESC"),
+			dal.Select("_tool_jira_issues.*"),
+			dal.From("_tool_jira_issues"),
+			dal.Join("LEFT JOIN _tool_jira_board_issues bi ON (bi.connection_id = _tool_jira_issues.connection_id AND bi.issue_id = _tool_jira_issues.issue_id)"),
+			dal.Where("bi.connection_id = ? and bi.board_id = ?", data.Connection.ID, data.Options.BoardId),
+			dal.Orderby("_tool_jira_issues.updated DESC"),
 		}
 		err := db.First(&latestUpdated, clauses...)
 		if err != nil {
diff --git a/services/blueprint.go b/services/blueprint.go
index 4055c739..0be64d7c 100644
--- a/services/blueprint.go
+++ b/services/blueprint.go
@@ -105,7 +105,7 @@ func validateBlueprint(blueprint *models.Blueprint) error {
 		if err != nil {
 			return fmt.Errorf("invalid cronConfig: %w", err)
 		}
-	} else if blueprint.IsManual == false {
+	} else if !blueprint.IsManual {
 		return fmt.Errorf("cronConfig is required for Automated blueprint")
 	}
 	if blueprint.Mode == models.BLUEPRINT_MODE_ADVANCED {