This is an automated email from the ASF dual-hosted git repository.
klesh 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 879b4025d refactor: remove the gorm for plugins (#3987)
879b4025d is described below
commit 879b4025d81bd9ee9d6dc5bab4e65a986a1163e2
Author: mappjzc <[email protected]>
AuthorDate: Tue Dec 20 19:45:07 2022 +0800
refactor: remove the gorm for plugins (#3987)
remove the gorm for each plugins.
Nddtfjiang <[email protected]>
---
.../template/migrationscripts/add_init_tables.go-template | 12 ++++++------
generator/template/migrationscripts/migration.go-template | 12 +++++++-----
.../migrationscripts/migration_with_config.go-template | 11 ++++++-----
generator/template/plugin/api/init.go-template | 5 ++---
.../template/plugin/impl/impl_complete_plugin.go-template | 5 ++---
generator/template/plugin/plugin_main.go-template | 10 +++-------
helpers/pluginhelper/tap/tap_collector.go | 4 ++--
plugins/dora/tasks/change_lead_time_calculator.go | 13 ++++++-------
plugins/dora/tasks/incident_deploy_connector.go | 7 +++----
plugins/github/api/blueprint_v200.go | 14 +++++++-------
plugins/github/api/scope.go | 6 +++---
plugins/github/impl/impl.go | 6 +++---
plugins/github/tasks/comment_extractor.go | 12 ++++++------
plugins/github/tasks/commit_stats_collector.go | 7 +++----
plugins/github/tasks/commit_stats_extractor.go | 5 ++---
plugins/github/tasks/pr_review_comment_extractor.go | 10 ++++------
plugins/gitlab/api/scope.go | 6 +++---
plugins/gitlab/impl/impl.go | 6 +++---
plugins/helper/api_collector_with_state.go | 6 +++---
plugins/jenkins/api/scope.go | 6 +++---
plugins/jira/api/scope.go | 6 +++---
plugins/jira/impl/impl.go | 8 ++++----
plugins/jira/tasks/issue_collector.go | 4 +---
plugins/refdiff/tasks/refdiff_task_data.go | 4 +---
plugins/tapd/tasks/bug_changelog_collector.go | 7 +++----
plugins/tapd/tasks/bug_collector.go | 7 +++----
plugins/tapd/tasks/iteration_collector.go | 7 +++----
plugins/tapd/tasks/shared.go | 15 +++++++--------
plugins/tapd/tasks/story_changelog_collector.go | 9 ++++-----
plugins/tapd/tasks/story_collector.go | 7 +++----
plugins/tapd/tasks/task_changelog_collector.go | 7 +++----
plugins/tapd/tasks/task_collector.go | 7 +++----
plugins/tapd/tasks/worklog_collector.go | 7 +++----
33 files changed, 118 insertions(+), 140 deletions(-)
diff --git a/generator/template/migrationscripts/add_init_tables.go-template
b/generator/template/migrationscripts/add_init_tables.go-template
index 5b8f86a0a..3abe1c4e1 100644
--- a/generator/template/migrationscripts/add_init_tables.go-template
+++ b/generator/template/migrationscripts/add_init_tables.go-template
@@ -18,18 +18,18 @@ limitations under the License.
package migrationscripts
import (
- "context"
"github.com/apache/incubator-devlake/errors"
- "gorm.io/gorm"
+ "github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/helpers/migrationhelper"
)
type addInitTables struct {}
-func (u *addInitTables) Up(ctx context.Context, db *gorm.DB) errors.Error {
- err := db.Migrator().AutoMigrate(
- // TODO add you models
+func (*{{ .Purpose }}) Up(basicRes core.BasicRes) errors.Error {
+ return migrationhelper.AutoMigrateTables(
+ basicRes,
+ // TO Add models
)
- return errors.Convert(err)
}
func (*addInitTables) Version() uint64 {
diff --git a/generator/template/migrationscripts/migration.go-template
b/generator/template/migrationscripts/migration.go-template
index 5a13101c4..f05133b58 100644
--- a/generator/template/migrationscripts/migration.go-template
+++ b/generator/template/migrationscripts/migration.go-template
@@ -18,16 +18,18 @@ limitations under the License.
package migrationscripts
import (
- "context"
"github.com/apache/incubator-devlake/errors"
- "gorm.io/gorm"
+ "github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/helpers/migrationhelper"
)
type {{ .Purpose }} struct{}
-func (*{{ .Purpose }}) Up(ctx context.Context, db *gorm.DB) errors.Error {
- // TODO db.Migrator()...
- return nil
+func (*{{ .Purpose }}) Up(basicRes core.BasicRes) errors.Error {
+ return migrationhelper.AutoMigrateTables(
+ basicRes,
+ // TO Add models
+ )
}
func (*{{ .Purpose }}) Version() uint64 {
diff --git
a/generator/template/migrationscripts/migration_with_config.go-template
b/generator/template/migrationscripts/migration_with_config.go-template
index a1e332cd8..912e39214 100644
--- a/generator/template/migrationscripts/migration_with_config.go-template
+++ b/generator/template/migrationscripts/migration_with_config.go-template
@@ -18,10 +18,9 @@ limitations under the License.
package migrationscripts
import (
- "context"
- "gorm.io/gorm"
"github.com/apache/incubator-devlake/errors"
"github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/helpers/migrationhelper"
)
type {{ .Purpose }} struct{
@@ -32,9 +31,11 @@ func (u *{{ .Purpose }}) SetConfigGetter(config
core.ConfigGetter) {
u.config = config
}
-func (*{{ .Purpose }}) Up(ctx context.Context, db *gorm.DB) errors.Error {
- // TODO db.Migrator()...
- return nil
+func (*{{ .Purpose }}) Up(basicRes core.BasicRes) errors.Error {
+ return migrationhelper.AutoMigrateTables(
+ basicRes,
+ // TO Add models
+ )
}
func (*{{ .Purpose }}) Version() uint64 {
diff --git a/generator/template/plugin/api/init.go-template
b/generator/template/plugin/api/init.go-template
index 6774e1482..a72cfcda5 100644
--- a/generator/template/plugin/api/init.go-template
+++ b/generator/template/plugin/api/init.go-template
@@ -22,15 +22,14 @@ import (
"github.com/apache/incubator-devlake/plugins/helper"
"github.com/go-playground/validator/v10"
"github.com/spf13/viper"
- "gorm.io/gorm"
)
var vld *validator.Validate
var connectionHelper *helper.ConnectionApiHelper
var basicRes core.BasicRes
-func Init(config *viper.Viper, logger core.Logger, database *gorm.DB) {
- basicRes = helper.NewDefaultBasicRes(config, logger, database)
+func Init(br core.BasicRes) {
+ basicRes = br
vld = validator.New()
connectionHelper = helper.NewConnectionHelper(
basicRes,
diff --git a/generator/template/plugin/impl/impl_complete_plugin.go-template
b/generator/template/plugin/impl/impl_complete_plugin.go-template
index 124402318..9e6bff1a9 100644
--- a/generator/template/plugin/impl/impl_complete_plugin.go-template
+++ b/generator/template/plugin/impl/impl_complete_plugin.go-template
@@ -28,7 +28,6 @@ import (
"github.com/apache/incubator-devlake/plugins/{{ .plugin_name }}/tasks"
"github.com/apache/incubator-devlake/plugins/helper"
"github.com/spf13/viper"
- "gorm.io/gorm"
)
// make sure interface is implemented
@@ -47,8 +46,8 @@ func (plugin {{ .PluginName }}) Description() string {
return "collect some {{ .PluginName }} data"
}
-func (plugin {{ .PluginName }}) Init(config *viper.Viper, logger core.Logger,
db *gorm.DB) errors.Error {
- api.Init(config, logger, db)
+func (plugin {{ .PluginName }}) Init(br core.BasicRes) errors.Error {
+ api.Init(br)
return nil
}
diff --git a/generator/template/plugin/plugin_main.go-template
b/generator/template/plugin/plugin_main.go-template
index cb1ea8094..d09aec1db 100644
--- a/generator/template/plugin/plugin_main.go-template
+++ b/generator/template/plugin/plugin_main.go-template
@@ -26,7 +26,6 @@ import (
"github.com/mitchellh/mapstructure"
"github.com/spf13/cobra"
"github.com/spf13/viper"
- "gorm.io/gorm"
)
// make sure interface is implemented
@@ -44,12 +43,9 @@ func (plugin {{ .PluginName }}) Description() string {
return "collect some {{ .PluginName }} data"
}
-func (plugin {{ .PluginName }}) Init(config *viper.Viper, logger core.Logger,
db *gorm.DB) errors.Error {
- // AutoSchemas is a **develop** script to auto migrate models easily.
- // FIXME Don't submit it as a open source plugin
- return db.Migrator().AutoMigrate(
- // TODO add your models in here
- )
+func (plugin {{ .PluginName }}) Init(br core.BasicRes) errors.Error {
+ api.Init(br)
+ return nil
}
func (plugin {{ .PluginName }}) SubTaskMetas() []core.SubTaskMeta {
diff --git a/helpers/pluginhelper/tap/tap_collector.go
b/helpers/pluginhelper/tap/tap_collector.go
index 99aba819d..f6f6fda4a 100644
--- a/helpers/pluginhelper/tap/tap_collector.go
+++ b/helpers/pluginhelper/tap/tap_collector.go
@@ -20,11 +20,11 @@ package tap
import (
"encoding/json"
"fmt"
+
"github.com/apache/incubator-devlake/errors"
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/core/dal"
"github.com/apache/incubator-devlake/plugins/helper"
- "gorm.io/gorm"
)
// CollectorArgs args to initialize a Collector
@@ -83,7 +83,7 @@ func (c *Collector[Stream]) getState() (*State, errors.Error)
{
rawState := RawState{}
rawState.ID = c.getStateId()
if err := db.First(&rawState); err != nil {
- if errors.Is(err, gorm.ErrRecordNotFound) {
+ if db.IsErrorNotFound(err) {
return nil, errors.NotFound.Wrap(err, "record not
found")
}
return nil, err
diff --git a/plugins/dora/tasks/change_lead_time_calculator.go
b/plugins/dora/tasks/change_lead_time_calculator.go
index cf52ddac0..fab50074e 100644
--- a/plugins/dora/tasks/change_lead_time_calculator.go
+++ b/plugins/dora/tasks/change_lead_time_calculator.go
@@ -18,18 +18,17 @@ limitations under the License.
package tasks
import (
- goerror "errors"
- "github.com/apache/incubator-devlake/models/domainlayer/crossdomain"
- "github.com/apache/incubator-devlake/models/domainlayer/devops"
"reflect"
"time"
+ "github.com/apache/incubator-devlake/models/domainlayer/crossdomain"
+ "github.com/apache/incubator-devlake/models/domainlayer/devops"
+
"github.com/apache/incubator-devlake/errors"
"github.com/apache/incubator-devlake/models/domainlayer/code"
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/core/dal"
"github.com/apache/incubator-devlake/plugins/helper"
- "gorm.io/gorm"
)
func CalculateChangeLeadTime(taskCtx core.SubTaskContext) errors.Error {
@@ -166,7 +165,7 @@ func getFirstCommit(prId string, db dal.Dal) (*code.Commit,
errors.Error) {
dal.Orderby("commits.authored_date ASC"),
}
err := db.First(commit, commitClauses...)
- if goerror.Is(err, gorm.ErrRecordNotFound) {
+ if db.IsErrorNotFound(err) {
return nil, nil
}
if err != nil {
@@ -183,7 +182,7 @@ func getFirstReview(prId string, prCreator string, db
dal.Dal) (*code.PullReques
dal.Orderby("created_date ASC"),
}
err := db.First(review, commentClauses...)
- if goerror.Is(err, gorm.ErrRecordNotFound) {
+ if db.IsErrorNotFound(err) {
return nil, nil
}
if err != nil {
@@ -207,7 +206,7 @@ func getDeployment(mergeSha string, repoId string,
deploymentPairList []deployme
if err == nil {
return &pair, nil
}
- if goerror.Is(err, gorm.ErrRecordNotFound) {
+ if db.IsErrorNotFound(err) {
continue
}
if err != nil {
diff --git a/plugins/dora/tasks/incident_deploy_connector.go
b/plugins/dora/tasks/incident_deploy_connector.go
index 52123cf1f..5cab03450 100644
--- a/plugins/dora/tasks/incident_deploy_connector.go
+++ b/plugins/dora/tasks/incident_deploy_connector.go
@@ -18,10 +18,10 @@ limitations under the License.
package tasks
import (
- goerror "errors"
+ "reflect"
+
"github.com/apache/incubator-devlake/models/domainlayer"
"github.com/apache/incubator-devlake/models/domainlayer/crossdomain"
- "reflect"
"github.com/apache/incubator-devlake/errors"
"github.com/apache/incubator-devlake/models/domainlayer/devops"
@@ -29,7 +29,6 @@ import (
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/core/dal"
"github.com/apache/incubator-devlake/plugins/helper"
- "gorm.io/gorm"
)
var ConnectIncidentToDeploymentMeta = core.SubTaskMeta{
@@ -94,7 +93,7 @@ func ConnectIncidentToDeployment(taskCtx core.SubTaskContext)
errors.Error {
}
err = db.First(cicdTask, cicdTakClauses...)
if err != nil {
- if goerror.Is(err, gorm.ErrRecordNotFound) {
+ if db.IsErrorNotFound(err) {
return nil, nil
} else {
return nil, err
diff --git a/plugins/github/api/blueprint_v200.go
b/plugins/github/api/blueprint_v200.go
index 333e38c95..23fc595ec 100644
--- a/plugins/github/api/blueprint_v200.go
+++ b/plugins/github/api/blueprint_v200.go
@@ -18,8 +18,11 @@ limitations under the License.
package api
import (
- goerror "errors"
"fmt"
+ "net/url"
+ "strings"
+ "time"
+
"github.com/apache/incubator-devlake/errors"
"github.com/apache/incubator-devlake/models/domainlayer"
"github.com/apache/incubator-devlake/models/domainlayer/code"
@@ -30,10 +33,6 @@ import (
"github.com/apache/incubator-devlake/plugins/github/tasks"
"github.com/apache/incubator-devlake/utils"
"github.com/go-playground/validator/v10"
- "gorm.io/gorm"
- "net/url"
- "strings"
- "time"
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/github/models"
@@ -83,8 +82,9 @@ func makeDataSourcePipelinePlanV200(
}
transformationRule := &models.GithubTransformationRule{}
// get transformation rules from db
- err = basicRes.GetDal().First(transformationRule, dal.Where(`id
= ?`, githubRepo.TransformationRuleId))
- if err != nil && !goerror.Is(err, gorm.ErrRecordNotFound) {
+ db := basicRes.GetDal()
+ err = db.First(transformationRule, dal.Where(`id = ?`,
githubRepo.TransformationRuleId))
+ if err != nil && !db.IsErrorNotFound(err) {
return nil, err
}
// refdiff
diff --git a/plugins/github/api/scope.go b/plugins/github/api/scope.go
index 008780188..615ba11ef 100644
--- a/plugins/github/api/scope.go
+++ b/plugins/github/api/scope.go
@@ -28,7 +28,6 @@ import (
"github.com/apache/incubator-devlake/plugins/github/models"
"github.com/apache/incubator-devlake/plugins/helper"
"github.com/mitchellh/mapstructure"
- "gorm.io/gorm"
)
type apiRepo struct {
@@ -184,8 +183,9 @@ func GetScope(input *core.ApiResourceInput)
(*core.ApiResourceOutput, errors.Err
if connectionId*repoId == 0 {
return nil, errors.BadInput.New("invalid path params")
}
- err := basicRes.GetDal().First(&repo, dal.Where("connection_id = ? AND
github_id = ?", connectionId, repoId))
- if errors.Is(err, gorm.ErrRecordNotFound) {
+ db := basicRes.GetDal()
+ err := db.First(&repo, dal.Where("connection_id = ? AND github_id = ?",
connectionId, repoId))
+ if db.IsErrorNotFound(err) {
return nil, errors.NotFound.New("record not found")
}
if err != nil {
diff --git a/plugins/github/impl/impl.go b/plugins/github/impl/impl.go
index e746cfeb5..e76b2412a 100644
--- a/plugins/github/impl/impl.go
+++ b/plugins/github/impl/impl.go
@@ -22,7 +22,6 @@ import (
"time"
"github.com/apache/incubator-devlake/plugins/core/dal"
- "gorm.io/gorm"
"github.com/apache/incubator-devlake/errors"
"github.com/apache/incubator-devlake/plugins/core"
@@ -287,8 +286,9 @@ func EnrichOptions(taskCtx core.TaskContext,
// Set GithubTransformationRule if it's nil, this has lower priority
if op.GithubTransformationRule == nil && op.TransformationRuleId != 0 {
var transformationRule models.GithubTransformationRule
- err = taskCtx.GetDal().First(&transformationRule, dal.Where("id
= ?", githubRepo.TransformationRuleId))
- if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
+ db := taskCtx.GetDal()
+ err = db.First(&transformationRule, dal.Where("id = ?",
githubRepo.TransformationRuleId))
+ if err != nil && !db.IsErrorNotFound(err) {
return errors.BadInput.Wrap(err, "fail to get
transformationRule")
}
op.GithubTransformationRule = &transformationRule
diff --git a/plugins/github/tasks/comment_extractor.go
b/plugins/github/tasks/comment_extractor.go
index bf983cdca..56a56d748 100644
--- a/plugins/github/tasks/comment_extractor.go
+++ b/plugins/github/tasks/comment_extractor.go
@@ -19,9 +19,8 @@ package tasks
import (
"encoding/json"
- goerror "errors"
+
"github.com/apache/incubator-devlake/errors"
- "gorm.io/gorm"
"github.com/apache/incubator-devlake/plugins/core/dal"
@@ -78,15 +77,16 @@ func ExtractApiComments(taskCtx core.SubTaskContext)
errors.Error {
return nil, err
}
issue := &models.GithubIssue{}
- err = taskCtx.GetDal().All(issue,
dal.Where("connection_id = ? and number = ? and repo_id = ?",
data.Options.ConnectionId, issueINumber, data.Options.GithubId))
- if err != nil && !goerror.Is(err,
gorm.ErrRecordNotFound) {
+ db := taskCtx.GetDal()
+ err = db.All(issue, dal.Where("connection_id = ? and
number = ? and repo_id = ?", data.Options.ConnectionId, issueINumber,
data.Options.GithubId))
+ if err != nil && !db.IsErrorNotFound(err) {
return nil, err
}
//if we can not find issues with issue number above,
move the comments to github_pull_request_comments
if issue.GithubId == 0 {
pr := &models.GithubPullRequest{}
- err = taskCtx.GetDal().First(pr,
dal.Where("connection_id = ? and number = ? and repo_id = ?",
data.Options.ConnectionId, issueINumber, data.Options.GithubId))
- if err != nil && !goerror.Is(err,
gorm.ErrRecordNotFound) {
+ err = db.First(pr, dal.Where("connection_id = ?
and number = ? and repo_id = ?", data.Options.ConnectionId, issueINumber,
data.Options.GithubId))
+ if err != nil && !db.IsErrorNotFound(err) {
return nil, err
}
githubPrComment := &models.GithubPrComment{
diff --git a/plugins/github/tasks/commit_stats_collector.go
b/plugins/github/tasks/commit_stats_collector.go
index 024522aec..20d24fa18 100644
--- a/plugins/github/tasks/commit_stats_collector.go
+++ b/plugins/github/tasks/commit_stats_collector.go
@@ -20,14 +20,13 @@ package tasks
import (
"encoding/json"
"fmt"
- "github.com/apache/incubator-devlake/errors"
- goerror "github.com/cockroachdb/errors"
- "gorm.io/gorm"
"io"
"net/http"
"net/url"
"reflect"
+ "github.com/apache/incubator-devlake/errors"
+
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/core/dal"
"github.com/apache/incubator-devlake/plugins/github/models"
@@ -56,7 +55,7 @@ func CollectApiCommitStats(taskCtx core.SubTaskContext)
errors.Error {
dal.Orderby("committed_date DESC"),
dal.Limit(1),
)
- if err != nil && !goerror.Is(err, gorm.ErrRecordNotFound) {
+ if err != nil && !db.IsErrorNotFound(err) {
return errors.Default.Wrap(err, "failed to get latest github
commit record")
}
diff --git a/plugins/github/tasks/commit_stats_extractor.go
b/plugins/github/tasks/commit_stats_extractor.go
index 2b687eb97..3f8cae260 100644
--- a/plugins/github/tasks/commit_stats_extractor.go
+++ b/plugins/github/tasks/commit_stats_extractor.go
@@ -19,10 +19,9 @@ package tasks
import (
"encoding/json"
- goerror "errors"
+
"github.com/apache/incubator-devlake/errors"
"github.com/apache/incubator-devlake/plugins/core/dal"
- "gorm.io/gorm"
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/github/models"
@@ -84,7 +83,7 @@ func ExtractApiCommitStats(taskCtx core.SubTaskContext)
errors.Error {
db := taskCtx.GetDal()
commit := &models.GithubCommit{}
err = db.First(commit, dal.Where("sha = ?", body.Sha),
dal.Limit(1))
- if err != nil && !goerror.Is(err,
gorm.ErrRecordNotFound) {
+ if err != nil && !db.IsErrorNotFound(err) {
return nil, err
}
diff --git a/plugins/github/tasks/pr_review_comment_extractor.go
b/plugins/github/tasks/pr_review_comment_extractor.go
index c3bc63d7a..07f490324 100644
--- a/plugins/github/tasks/pr_review_comment_extractor.go
+++ b/plugins/github/tasks/pr_review_comment_extractor.go
@@ -19,9 +19,7 @@ package tasks
import (
"encoding/json"
- goerror "errors"
"fmt"
- "gorm.io/gorm"
"regexp"
"strconv"
@@ -126,11 +124,11 @@ func enrichGithubPrComment(data *GithubTaskData, db
dal.Dal, prUrlRegex *regexp.
return 0, errors.Default.Wrap(err, "parse prId failed")
}
pr := &models.GithubPullRequest{}
- err = db.First(pr, dal.Where("connection_id = ? and number = ?
and repo_id = ?", data.Options.ConnectionId, prNumber, data.Options.GithubId))
- if goerror.Is(err, gorm.ErrRecordNotFound) {
+ err1 := db.First(pr, dal.Where("connection_id = ? and number =
? and repo_id = ?", data.Options.ConnectionId, prNumber, data.Options.GithubId))
+ if db.IsErrorNotFound(err1) {
return 0, nil
- } else if err != nil {
- return 0, errors.NotFound.Wrap(err, "github pull
request parse failed ")
+ } else if err1 != nil {
+ return 0, errors.NotFound.Wrap(err1, "github pull
request parse failed ")
}
return pr.GithubId, nil
}
diff --git a/plugins/gitlab/api/scope.go b/plugins/gitlab/api/scope.go
index db3358460..c1a410d34 100644
--- a/plugins/gitlab/api/scope.go
+++ b/plugins/gitlab/api/scope.go
@@ -28,7 +28,6 @@ import (
"github.com/apache/incubator-devlake/plugins/gitlab/models"
"github.com/apache/incubator-devlake/plugins/helper"
"github.com/mitchellh/mapstructure"
- "gorm.io/gorm"
)
type apiProject struct {
@@ -183,8 +182,9 @@ func GetScope(input *core.ApiResourceInput)
(*core.ApiResourceOutput, errors.Err
if connectionId*projectId == 0 {
return nil, errors.BadInput.New("invalid path params")
}
- err := basicRes.GetDal().First(&project, dal.Where("connection_id = ?
AND gitlab_id = ?", connectionId, projectId))
- if errors.Is(err, gorm.ErrRecordNotFound) {
+ db := basicRes.GetDal()
+ err := db.First(&project, dal.Where("connection_id = ? AND gitlab_id =
?", connectionId, projectId))
+ if db.IsErrorNotFound(err) {
return nil, errors.NotFound.New("record not found")
}
if err != nil {
diff --git a/plugins/gitlab/impl/impl.go b/plugins/gitlab/impl/impl.go
index e0eeb3834..0c2675030 100644
--- a/plugins/gitlab/impl/impl.go
+++ b/plugins/gitlab/impl/impl.go
@@ -19,7 +19,6 @@ package impl
import (
"fmt"
- "gorm.io/gorm"
"strconv"
"time"
@@ -165,8 +164,9 @@ func (plugin Gitlab) PrepareTaskData(taskCtx
core.TaskContext, options map[strin
var scope *models.GitlabProject
// support v100 & advance mode
// If we still cannot find the record in db, we have to request
from remote server and save it to db
- err = taskCtx.GetDal().First(&scope, dal.Where("connection_id =
? AND gitlab_id = ?", op.ConnectionId, op.ProjectId))
- if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
+ db := taskCtx.GetDal()
+ err = db.First(&scope, dal.Where("connection_id = ? AND
gitlab_id = ?", op.ConnectionId, op.ProjectId))
+ if err != nil && db.IsErrorNotFound(err) {
var project *tasks.GitlabApiProject
project, err = api.GetApiProject(op, apiClient)
if err != nil {
diff --git a/plugins/helper/api_collector_with_state.go
b/plugins/helper/api_collector_with_state.go
index d0c8a81c1..9481ed0d7 100644
--- a/plugins/helper/api_collector_with_state.go
+++ b/plugins/helper/api_collector_with_state.go
@@ -18,11 +18,11 @@ limitations under the License.
package helper
import (
+ "time"
+
"github.com/apache/incubator-devlake/errors"
"github.com/apache/incubator-devlake/models"
"github.com/apache/incubator-devlake/plugins/core/dal"
- "gorm.io/gorm"
- "time"
)
// ApiCollectorStateManager save collector state in framework table
@@ -45,7 +45,7 @@ func NewApiCollectorWithState(args RawDataSubTaskArgs,
createdDateAfter *time.Ti
latestState := models.CollectorLatestState{}
err = db.First(&latestState, dal.Where(`raw_data_table = ? AND
raw_data_params = ?`, rawDataSubTask.table, rawDataSubTask.params))
if err != nil {
- if errors.Is(err, gorm.ErrRecordNotFound) {
+ if db.IsErrorNotFound(err) {
latestState = models.CollectorLatestState{
RawDataTable: rawDataSubTask.table,
RawDataParams: rawDataSubTask.params,
diff --git a/plugins/jenkins/api/scope.go b/plugins/jenkins/api/scope.go
index 016536b9c..c3615d9b8 100644
--- a/plugins/jenkins/api/scope.go
+++ b/plugins/jenkins/api/scope.go
@@ -27,7 +27,6 @@ import (
"github.com/apache/incubator-devlake/plugins/helper"
"github.com/apache/incubator-devlake/plugins/jenkins/models"
"github.com/mitchellh/mapstructure"
- "gorm.io/gorm"
)
type apiJob struct {
@@ -174,8 +173,9 @@ func GetScope(input *core.ApiResourceInput)
(*core.ApiResourceOutput, errors.Err
if err != nil {
return nil, err
}
- err = basicRes.GetDal().First(&job, dal.Where("connection_id = ? AND
full_name = ?", connectionId, fullName))
- if errors.Is(err, gorm.ErrRecordNotFound) {
+ db := basicRes.GetDal()
+ err = db.First(&job, dal.Where("connection_id = ? AND full_name = ?",
connectionId, fullName))
+ if db.IsErrorNotFound(err) {
return nil, errors.NotFound.New("record not found")
}
if err != nil {
diff --git a/plugins/jira/api/scope.go b/plugins/jira/api/scope.go
index ff4a406a9..3a35f1a70 100644
--- a/plugins/jira/api/scope.go
+++ b/plugins/jira/api/scope.go
@@ -20,7 +20,6 @@ package api
import (
"encoding/json"
"fmt"
- "gorm.io/gorm"
"io"
"net/http"
"strconv"
@@ -184,8 +183,9 @@ func GetScope(input *core.ApiResourceInput)
(*core.ApiResourceOutput, errors.Err
if connectionId*boardId == 0 {
return nil, errors.BadInput.New("invalid path params")
}
- err := basicRes.GetDal().First(&board, dal.Where("connection_id = ? AND
board_id = ?", connectionId, boardId))
- if errors.Is(err, gorm.ErrRecordNotFound) {
+ db := basicRes.GetDal()
+ err := db.First(&board, dal.Where("connection_id = ? AND board_id = ?",
connectionId, boardId))
+ if db.IsErrorNotFound(err) {
return nil, errors.NotFound.New("record not found")
}
if err != nil {
diff --git a/plugins/jira/impl/impl.go b/plugins/jira/impl/impl.go
index bd69cd76c..7ce326c93 100644
--- a/plugins/jira/impl/impl.go
+++ b/plugins/jira/impl/impl.go
@@ -19,7 +19,6 @@ package impl
import (
"fmt"
- "gorm.io/gorm"
"net/http"
"time"
@@ -176,8 +175,9 @@ func (plugin Jira) PrepareTaskData(taskCtx
core.TaskContext, options map[string]
var scope *models.JiraBoard
// support v100 & advance mode
// If we still cannot find the record in db, we have to request
from remote server and save it to db
- err = taskCtx.GetDal().First(&scope, dal.Where("connection_id =
? AND board_id = ?", op.ConnectionId, op.BoardId))
- if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
+ db := taskCtx.GetDal()
+ err = db.First(&scope, dal.Where("connection_id = ? AND
board_id = ?", op.ConnectionId, op.BoardId))
+ if err != nil && db.IsErrorNotFound(err) {
var board *apiv2models.Board
board, err = api.GetApiJira(&op, jiraApiClient)
if err != nil {
@@ -185,7 +185,7 @@ func (plugin Jira) PrepareTaskData(taskCtx
core.TaskContext, options map[string]
}
logger.Debug(fmt.Sprintf("Current project: %d",
board.ID))
scope = board.ToToolLayer(connection.ID)
- err = taskCtx.GetDal().CreateIfNotExist(&scope)
+ err = db.CreateIfNotExist(&scope)
if err != nil {
return nil, err
}
diff --git a/plugins/jira/tasks/issue_collector.go
b/plugins/jira/tasks/issue_collector.go
index 2120e6b30..50a8504f8 100644
--- a/plugins/jira/tasks/issue_collector.go
+++ b/plugins/jira/tasks/issue_collector.go
@@ -19,9 +19,7 @@ package tasks
import (
"encoding/json"
- goerror "errors"
"fmt"
- "gorm.io/gorm"
"io"
"net/http"
"net/url"
@@ -90,7 +88,7 @@ func CollectIssues(taskCtx core.SubTaskContext) errors.Error {
dal.Orderby("_tool_jira_issues.updated DESC"),
}
err := db.First(&latestUpdated, clauses...)
- if err != nil && !goerror.Is(err, gorm.ErrRecordNotFound) {
+ if err != nil && !db.IsErrorNotFound(err) {
return errors.NotFound.Wrap(err, "failed to get latest
jira issue record")
}
if latestUpdated.IssueId > 0 {
diff --git a/plugins/refdiff/tasks/refdiff_task_data.go
b/plugins/refdiff/tasks/refdiff_task_data.go
index d0aec9a7f..3569bfa0b 100644
--- a/plugins/refdiff/tasks/refdiff_task_data.go
+++ b/plugins/refdiff/tasks/refdiff_task_data.go
@@ -18,7 +18,6 @@ limitations under the License.
package tasks
import (
- goerror "errors"
"fmt"
"regexp"
"sort"
@@ -26,7 +25,6 @@ import (
"time"
"github.com/apache/incubator-devlake/errors"
- "gorm.io/gorm"
"github.com/apache/incubator-devlake/models/domainlayer/code"
"github.com/apache/incubator-devlake/plugins/core/dal"
@@ -207,7 +205,7 @@ func CalculateCommitPairs(db dal.Dal, repoId string, pairs
[]RefPair, rs Refs) (
}
ref.Id = fmt.Sprintf("%s:%s", repoId, refName)
err := db.First(ref)
- if err != nil && !goerror.Is(err, gorm.ErrRecordNotFound) {
+ if err != nil && !db.IsErrorNotFound(err) {
return "", errors.NotFound.Wrap(err, fmt.Sprintf("faild
to load Ref info for repoId:%s, refName:%s", repoId, refName))
}
return ref.CommitSha, nil
diff --git a/plugins/tapd/tasks/bug_changelog_collector.go
b/plugins/tapd/tasks/bug_changelog_collector.go
index 4ca497168..6b395c297 100644
--- a/plugins/tapd/tasks/bug_changelog_collector.go
+++ b/plugins/tapd/tasks/bug_changelog_collector.go
@@ -18,13 +18,12 @@ limitations under the License.
package tasks
import (
- goerror "errors"
"fmt"
- "github.com/apache/incubator-devlake/errors"
- "gorm.io/gorm"
"net/url"
"time"
+ "github.com/apache/incubator-devlake/errors"
+
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/core/dal"
"github.com/apache/incubator-devlake/plugins/helper"
@@ -50,7 +49,7 @@ func CollectBugChangelogs(taskCtx core.SubTaskContext)
errors.Error {
dal.Orderby("created DESC"),
}
err := db.First(&latestUpdated, clauses...)
- if err != nil && !goerror.Is(err, gorm.ErrRecordNotFound) {
+ if err != nil && !db.IsErrorNotFound(err) {
return errors.NotFound.Wrap(err, "failed to get latest
tapd changelog record")
}
if latestUpdated.Id > 0 {
diff --git a/plugins/tapd/tasks/bug_collector.go
b/plugins/tapd/tasks/bug_collector.go
index bbd4e7f3f..570d2824c 100644
--- a/plugins/tapd/tasks/bug_collector.go
+++ b/plugins/tapd/tasks/bug_collector.go
@@ -18,13 +18,12 @@ limitations under the License.
package tasks
import (
- goerror "errors"
"fmt"
- "github.com/apache/incubator-devlake/errors"
- "gorm.io/gorm"
"net/url"
"time"
+ "github.com/apache/incubator-devlake/errors"
+
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/core/dal"
"github.com/apache/incubator-devlake/plugins/helper"
@@ -50,7 +49,7 @@ func CollectBugs(taskCtx core.SubTaskContext) errors.Error {
dal.Orderby("modified DESC"),
}
err := db.First(&latestUpdated, clauses...)
- if err != nil && !goerror.Is(err, gorm.ErrRecordNotFound) {
+ if err != nil && !db.IsErrorNotFound(err) {
return errors.Default.Wrap(err, "failed to get latest
tapd changelog record")
}
if latestUpdated.Id > 0 {
diff --git a/plugins/tapd/tasks/iteration_collector.go
b/plugins/tapd/tasks/iteration_collector.go
index 9e1ff4c9b..a3b379be3 100644
--- a/plugins/tapd/tasks/iteration_collector.go
+++ b/plugins/tapd/tasks/iteration_collector.go
@@ -19,14 +19,13 @@ package tasks
import (
"encoding/json"
- goerror "errors"
"fmt"
- "github.com/apache/incubator-devlake/errors"
- "gorm.io/gorm"
"net/http"
"net/url"
"time"
+ "github.com/apache/incubator-devlake/errors"
+
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/core/dal"
"github.com/apache/incubator-devlake/plugins/helper"
@@ -52,7 +51,7 @@ func CollectIterations(taskCtx core.SubTaskContext)
errors.Error {
dal.Orderby("modified DESC"),
}
err := db.First(&latestUpdated, clauses...)
- if err != nil && !goerror.Is(err, gorm.ErrRecordNotFound) {
+ if err != nil && !db.IsErrorNotFound(err) {
return errors.NotFound.Wrap(err, "failed to get latest
tapd changelog record")
}
if latestUpdated.Id > 0 {
diff --git a/plugins/tapd/tasks/shared.go b/plugins/tapd/tasks/shared.go
index d29867b19..5b3620593 100644
--- a/plugins/tapd/tasks/shared.go
+++ b/plugins/tapd/tasks/shared.go
@@ -19,8 +19,12 @@ package tasks
import (
"encoding/json"
- goerror "errors"
"fmt"
+ "io"
+ "net/http"
+ "net/url"
+ "strings"
+
"github.com/apache/incubator-devlake/errors"
"github.com/apache/incubator-devlake/models/domainlayer/didgen"
"github.com/apache/incubator-devlake/models/domainlayer/ticket"
@@ -28,11 +32,6 @@ import (
"github.com/apache/incubator-devlake/plugins/core/dal"
"github.com/apache/incubator-devlake/plugins/helper"
"github.com/apache/incubator-devlake/plugins/tapd/models"
- "gorm.io/gorm"
- "io"
- "net/http"
- "net/url"
- "strings"
)
type Page struct {
@@ -99,7 +98,7 @@ func parseIterationChangelog(taskCtx core.SubTaskContext, old
string, new string
data.Options.ConnectionId, data.Options.WorkspaceId,
old),
}
err = db.First(iterationFrom, clauses...)
- if err != nil && !goerror.Is(err, gorm.ErrRecordNotFound) {
+ if err != nil && !db.IsErrorNotFound(err) {
return 0, 0, err
}
@@ -110,7 +109,7 @@ func parseIterationChangelog(taskCtx core.SubTaskContext,
old string, new string
data.Options.ConnectionId, data.Options.WorkspaceId,
new),
}
err = db.First(iterationTo, clauses...)
- if err != nil && !goerror.Is(err, gorm.ErrRecordNotFound) {
+ if err != nil && !db.IsErrorNotFound(err) {
return 0, 0, err
}
return iterationFrom.Id, iterationTo.Id, nil
diff --git a/plugins/tapd/tasks/story_changelog_collector.go
b/plugins/tapd/tasks/story_changelog_collector.go
index 741a014e4..9de0e97bb 100644
--- a/plugins/tapd/tasks/story_changelog_collector.go
+++ b/plugins/tapd/tasks/story_changelog_collector.go
@@ -18,16 +18,15 @@ limitations under the License.
package tasks
import (
- goerror "errors"
"fmt"
+ "net/url"
+ "time"
+
"github.com/apache/incubator-devlake/errors"
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/core/dal"
"github.com/apache/incubator-devlake/plugins/helper"
"github.com/apache/incubator-devlake/plugins/tapd/models"
- "gorm.io/gorm"
- "net/url"
- "time"
)
const RAW_STORY_CHANGELOG_TABLE = "tapd_api_story_changelogs"
@@ -49,7 +48,7 @@ func CollectStoryChangelogs(taskCtx core.SubTaskContext)
errors.Error {
dal.Orderby("created DESC"),
}
err := db.First(&latestUpdated, clauses...)
- if err != nil && !goerror.Is(err, gorm.ErrRecordNotFound) {
+ if err != nil && !db.IsErrorNotFound(err) {
return errors.NotFound.Wrap(err, "failed to get latest
tapd changelog record")
}
if latestUpdated.Id > 0 {
diff --git a/plugins/tapd/tasks/story_collector.go
b/plugins/tapd/tasks/story_collector.go
index 608b98c92..887f4671a 100644
--- a/plugins/tapd/tasks/story_collector.go
+++ b/plugins/tapd/tasks/story_collector.go
@@ -18,13 +18,12 @@ limitations under the License.
package tasks
import (
- goerror "errors"
"fmt"
- "github.com/apache/incubator-devlake/errors"
- "gorm.io/gorm"
"net/url"
"time"
+ "github.com/apache/incubator-devlake/errors"
+
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/core/dal"
"github.com/apache/incubator-devlake/plugins/helper"
@@ -50,7 +49,7 @@ func CollectStorys(taskCtx core.SubTaskContext) errors.Error {
dal.Orderby("modified DESC"),
}
err := db.First(&latestUpdated, clauses...)
- if err != nil && !goerror.Is(err, gorm.ErrRecordNotFound) {
+ if err != nil && !db.IsErrorNotFound(err) {
return errors.Default.Wrap(err, "failed to get latest
tapd changelog record")
}
if latestUpdated.Id > 0 {
diff --git a/plugins/tapd/tasks/task_changelog_collector.go
b/plugins/tapd/tasks/task_changelog_collector.go
index 1ab72685f..88cb80ede 100644
--- a/plugins/tapd/tasks/task_changelog_collector.go
+++ b/plugins/tapd/tasks/task_changelog_collector.go
@@ -18,13 +18,12 @@ limitations under the License.
package tasks
import (
- goerror "errors"
"fmt"
- "github.com/apache/incubator-devlake/errors"
- "gorm.io/gorm"
"net/url"
"time"
+ "github.com/apache/incubator-devlake/errors"
+
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/core/dal"
"github.com/apache/incubator-devlake/plugins/helper"
@@ -50,7 +49,7 @@ func CollectTaskChangelogs(taskCtx core.SubTaskContext)
errors.Error {
dal.Orderby("created DESC"),
}
err := db.First(&latestUpdated, clauses...)
- if err != nil && !goerror.Is(err, gorm.ErrRecordNotFound) {
+ if err != nil && !db.IsErrorNotFound(err) {
return errors.NotFound.Wrap(err, "failed to get latest
tapd changelog record")
}
if latestUpdated.Id > 0 {
diff --git a/plugins/tapd/tasks/task_collector.go
b/plugins/tapd/tasks/task_collector.go
index 125122d3d..68a40fd15 100644
--- a/plugins/tapd/tasks/task_collector.go
+++ b/plugins/tapd/tasks/task_collector.go
@@ -18,13 +18,12 @@ limitations under the License.
package tasks
import (
- goerror "errors"
"fmt"
- "github.com/apache/incubator-devlake/errors"
- "gorm.io/gorm"
"net/url"
"time"
+ "github.com/apache/incubator-devlake/errors"
+
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/core/dal"
"github.com/apache/incubator-devlake/plugins/helper"
@@ -52,7 +51,7 @@ func CollectTasks(taskCtx core.SubTaskContext) errors.Error {
dal.Orderby("modified DESC"),
}
err := db.First(&latestUpdated, clauses...)
- if err != nil && !goerror.Is(err, gorm.ErrRecordNotFound) {
+ if err != nil && !db.IsErrorNotFound(err) {
return errors.NotFound.Wrap(err, "failed to get latest
tapd changelog record")
}
if latestUpdated.Id > 0 {
diff --git a/plugins/tapd/tasks/worklog_collector.go
b/plugins/tapd/tasks/worklog_collector.go
index 4e06f1c55..084b01820 100644
--- a/plugins/tapd/tasks/worklog_collector.go
+++ b/plugins/tapd/tasks/worklog_collector.go
@@ -18,13 +18,12 @@ limitations under the License.
package tasks
import (
- goerror "errors"
"fmt"
- "github.com/apache/incubator-devlake/errors"
- "gorm.io/gorm"
"net/url"
"time"
+ "github.com/apache/incubator-devlake/errors"
+
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/core/dal"
"github.com/apache/incubator-devlake/plugins/helper"
@@ -50,7 +49,7 @@ func CollectWorklogs(taskCtx core.SubTaskContext)
errors.Error {
dal.Orderby("created DESC"),
}
err := db.First(&latestUpdated, clauses...)
- if err != nil && !goerror.Is(err, gorm.ErrRecordNotFound) {
+ if err != nil && !db.IsErrorNotFound(err) {
return errors.NotFound.Wrap(err, "failed to get latest
tapd changelog record")
}
if latestUpdated.Id > 0 {