You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by wa...@apache.org on 2023/03/15 03:47:03 UTC

[incubator-devlake] branch main updated: fix(gitlab): change type of createdDateto adapt scope helper (#4666)

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

warren 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 006756bed fix(gitlab): change type of createdDateto adapt scope helper (#4666)
006756bed is described below

commit 006756bed4f38dd66a7a7ff0404f5d490d79e58a
Author: Warren Chen <yi...@merico.dev>
AuthorDate: Wed Mar 15 11:46:58 2023 +0800

    fix(gitlab): change type of createdDateto adapt scope helper (#4666)
---
 backend/helpers/pluginhelper/api/scope_helper.go      | 7 ++++++-
 backend/helpers/pluginhelper/api/scope_helper_test.go | 9 +++++++++
 backend/plugins/gitlab/api/blueprint_V200_test.go     | 2 +-
 backend/plugins/gitlab/models/project.go              | 2 +-
 backend/plugins/gitlab/tasks/project_convertor.go     | 6 +++---
 backend/plugins/gitlab/tasks/project_extractor.go     | 2 +-
 6 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/backend/helpers/pluginhelper/api/scope_helper.go b/backend/helpers/pluginhelper/api/scope_helper.go
index 5102eee88..57e508726 100644
--- a/backend/helpers/pluginhelper/api/scope_helper.go
+++ b/backend/helpers/pluginhelper/api/scope_helper.go
@@ -275,10 +275,15 @@ func setScopeFields(p interface{}, connectionId uint64, createdDate *time.Time,
 
 	// set CreatedDate
 	createdDateField := pValue.FieldByName("CreatedDate")
-	createdDateField.Set(reflect.ValueOf(createdDate))
+	if createdDateField.IsValid() {
+		createdDateField.Set(reflect.ValueOf(createdDate))
+	}
 
 	// set UpdatedDate
 	updatedDateField := pValue.FieldByName("UpdatedDate")
+	if !updatedDateField.IsValid() {
+		return
+	}
 	if updatedDate == nil {
 		// if updatedDate is nil, set UpdatedDate to be nil
 		updatedDateField.Set(reflect.Zero(updatedDateField.Type()))
diff --git a/backend/helpers/pluginhelper/api/scope_helper_test.go b/backend/helpers/pluginhelper/api/scope_helper_test.go
index c90afffa4..f77acb079 100644
--- a/backend/helpers/pluginhelper/api/scope_helper_test.go
+++ b/backend/helpers/pluginhelper/api/scope_helper_test.go
@@ -180,6 +180,15 @@ func TestSetScopeFields(t *testing.T) {
 	if p.UpdatedDate != nil {
 		t.Errorf("UpdatedDate not set correctly, expected: %v, got: %v", nil, p.UpdatedDate)
 	}
+
+	var p1 struct {
+		ConnectionId uint64 `json:"connectionId" mapstructure:"connectionId" gorm:"primaryKey"`
+		GitlabId     int    `json:"gitlabId" mapstructure:"gitlabId" gorm:"primaryKey"`
+
+		common.NoPKModel `json:"-" mapstructure:"-"`
+	}
+	setScopeFields(&p1, connectionId, &createdDate, &createdDate)
+
 }
 
 func TestReturnPrimaryKeyValue(t *testing.T) {
diff --git a/backend/plugins/gitlab/api/blueprint_V200_test.go b/backend/plugins/gitlab/api/blueprint_V200_test.go
index 959ac59d1..0c0720fe2 100644
--- a/backend/plugins/gitlab/api/blueprint_V200_test.go
+++ b/backend/plugins/gitlab/api/blueprint_V200_test.go
@@ -66,7 +66,7 @@ func TestMakeDataSourcePipelinePlanV200(t *testing.T) {
 		Name:         testName,
 
 		TransformationRuleId: testTransformationRuleId,
-		CreatedDate:          time.Time{},
+		CreatedDate:          &time.Time{},
 		HttpUrlToRepo:        testHttpUrlToRepo,
 	}
 
diff --git a/backend/plugins/gitlab/models/project.go b/backend/plugins/gitlab/models/project.go
index 41c6855f5..8db83c195 100644
--- a/backend/plugins/gitlab/models/project.go
+++ b/backend/plugins/gitlab/models/project.go
@@ -40,7 +40,7 @@ type GitlabProject struct {
 	ForkedFromProjectWebUrl string `json:"forkedFromProjectWebUrl" mapstructure:"forkedFromProjectWebUrl" gorm:"type:varchar(255)"`
 	HttpUrlToRepo           string `json:"httpUrlToRepo" gorm:"type:varchar(255)"`
 
-	CreatedDate      time.Time  `json:"createdDate" mapstructure:"-"`
+	CreatedDate      *time.Time `json:"createdDate" mapstructure:"-"`
 	UpdatedDate      *time.Time `json:"updatedDate" mapstructure:"-"`
 	common.NoPKModel `json:"-" mapstructure:"-"`
 }
diff --git a/backend/plugins/gitlab/tasks/project_convertor.go b/backend/plugins/gitlab/tasks/project_convertor.go
index 3828b375e..24378a193 100644
--- a/backend/plugins/gitlab/tasks/project_convertor.go
+++ b/backend/plugins/gitlab/tasks/project_convertor.go
@@ -108,7 +108,7 @@ func convertToRepositoryModel(project *models.GitlabProject) *code.Repo {
 		Url:         project.WebUrl,
 		Description: project.Description,
 		ForkedFrom:  project.ForkedFromProjectWebUrl,
-		CreatedDate: &project.CreatedDate,
+		CreatedDate: project.CreatedDate,
 		UpdatedDate: project.UpdatedDate,
 	}
 	return domainRepository
@@ -122,7 +122,7 @@ func convertToBoardModel(project *models.GitlabProject) *ticket.Board {
 		Name:        project.Name,
 		Url:         project.WebUrl,
 		Description: project.Description,
-		CreatedDate: &project.CreatedDate,
+		CreatedDate: project.CreatedDate,
 	}
 	return domainBoard
 }
@@ -143,7 +143,7 @@ func convertToCicdScopeModel(project *models.GitlabProject) *devops.CicdScope {
 		Name:        project.Name,
 		Url:         project.WebUrl,
 		Description: project.Description,
-		CreatedDate: &project.CreatedDate,
+		CreatedDate: project.CreatedDate,
 		UpdatedDate: project.UpdatedDate,
 	}
 	return domainCicdScope
diff --git a/backend/plugins/gitlab/tasks/project_extractor.go b/backend/plugins/gitlab/tasks/project_extractor.go
index ff3d548bd..d8fb39e56 100644
--- a/backend/plugins/gitlab/tasks/project_extractor.go
+++ b/backend/plugins/gitlab/tasks/project_extractor.go
@@ -36,7 +36,7 @@ func ConvertProject(gitlabApiProject *GitlabApiProject) *models.GitlabProject {
 		Visibility:        gitlabApiProject.Visibility,
 		OpenIssuesCount:   gitlabApiProject.OpenIssuesCount,
 		StarCount:         gitlabApiProject.StarCount,
-		CreatedDate:       gitlabApiProject.CreatedAt.ToTime(),
+		CreatedDate:       gitlabApiProject.CreatedAt.ToNullableTime(),
 		UpdatedDate:       helper.Iso8601TimeToTime(gitlabApiProject.LastActivityAt),
 	}
 	if gitlabApiProject.ForkedFromProject != nil {