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/07/27 04:18:23 UTC

[incubator-devlake] branch main updated: fix(framework): remove table.notes (#2614)

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 dfbc4b28 fix(framework): remove table.notes (#2614)
dfbc4b28 is described below

commit dfbc4b2893e2b17111e66b74078d7462154c9f12
Author: Warren Chen <yi...@merico.dev>
AuthorDate: Wed Jul 27 12:18:19 2022 +0800

    fix(framework): remove table.notes (#2614)
    
    closes #2613
---
 .../20220727_remove_notes.go}                      | 35 ++++----
 models/migrationscripts/register.go                |  1 +
 plugins/gitlab/e2e/mr_notes_test.go                | 22 -----
 plugins/gitlab/e2e/snapshot_tables/notes.csv       | 45 -----------
 plugins/gitlab/impl/impl.go                        |  1 -
 plugins/gitlab/tasks/note_convertor.go             | 93 ----------------------
 6 files changed, 21 insertions(+), 176 deletions(-)

diff --git a/models/domainlayer/code/note.go b/models/migrationscripts/20220727_remove_notes.go
similarity index 58%
rename from models/domainlayer/code/note.go
rename to models/migrationscripts/20220727_remove_notes.go
index b3c628cf..6d0ef72a 100644
--- a/models/domainlayer/code/note.go
+++ b/models/migrationscripts/20220727_remove_notes.go
@@ -15,25 +15,30 @@ See the License for the specific language governing permissions and
 limitations under the License.
 */
 
-package code
+package migrationscripts
 
 import (
-	"time"
-
-	"github.com/apache/incubator-devlake/models/domainlayer"
+	"context"
+	"github.com/apache/incubator-devlake/models/migrationscripts/archived"
+	"gorm.io/gorm"
 )
 
-type Note struct {
-	domainlayer.DomainEntity
-	PrId        string `gorm:"index;comment:References the pull request for this note;type:varchar(100)"`
-	Type        string `gorm:"type:varchar(100)"`
-	Author      string `gorm:"type:varchar(255)"`
-	Body        string
-	Resolvable  bool `gorm:"comment:Is or is not a review comment"`
-	IsSystem    bool `gorm:"comment:Is or is not auto-generated vs. human generated"`
-	CreatedDate time.Time
+type removeNotes struct{}
+
+func (*removeNotes) Up(ctx context.Context, db *gorm.DB) error {
+
+	err := db.Migrator().DropTable(archived.Note{})
+	if err != nil {
+		return err
+	}
+
+	return nil
+}
+
+func (*removeNotes) Version() uint64 {
+	return 20220727165805
 }
 
-func (Note) TableName() string {
-	return "notes"
+func (*removeNotes) Name() string {
+	return "remove notes from domain layer"
 }
diff --git a/models/migrationscripts/register.go b/models/migrationscripts/register.go
index 2142ec9a..332a8d01 100644
--- a/models/migrationscripts/register.go
+++ b/models/migrationscripts/register.go
@@ -30,5 +30,6 @@ func All() []migration.Script {
 		new(addDomainTables),
 		new(addTypeField),
 		new(commitfileComponent),
+		new(removeNotes),
 	}
 }
diff --git a/plugins/gitlab/e2e/mr_notes_test.go b/plugins/gitlab/e2e/mr_notes_test.go
index 7977d6b8..e00e93c2 100644
--- a/plugins/gitlab/e2e/mr_notes_test.go
+++ b/plugins/gitlab/e2e/mr_notes_test.go
@@ -130,28 +130,6 @@ func TestGitlabMrNoteDataFlow(t *testing.T) {
 		},
 	)
 
-	// verify conversion
-	dataflowTester.FlushTabler(&code.Note{})
-	dataflowTester.Subtask(tasks.ConvertApiNotesMeta, taskData)
-	dataflowTester.VerifyTable(
-		code.Note{},
-		fmt.Sprintf("./snapshot_tables/%s.csv", code.Note{}.TableName()),
-		[]string{
-			"_raw_data_params",
-			"_raw_data_table",
-			"_raw_data_id",
-			"_raw_data_remark",
-			"id",
-			"pr_id",
-			"type",
-			"author",
-			"body",
-			"resolvable",
-			"is_system",
-			"created_date",
-		},
-	)
-
 	// verify conversion
 	dataflowTester.FlushTabler(&code.PullRequestComment{})
 	dataflowTester.Subtask(tasks.ConvertMrCommentMeta, taskData)
diff --git a/plugins/gitlab/e2e/snapshot_tables/notes.csv b/plugins/gitlab/e2e/snapshot_tables/notes.csv
deleted file mode 100644
index 1c39e586..00000000
--- a/plugins/gitlab/e2e/snapshot_tables/notes.csv
+++ /dev/null
@@ -1,45 +0,0 @@
-id,_raw_data_params,_raw_data_table,_raw_data_id,_raw_data_remark,pr_id,type,author,body,resolvable,is_system,created_date
-gitlab:GitlabMrNote:1:186327072,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,1,,gitlab:GitlabMergeRequest:1:32348491,MergeRequest,gitlab:GitlabAccount:1:2295562,assigned to @emilie,0,1,2019-06-28T05:40:22.415+00:00
-gitlab:GitlabMrNote:1:186327158,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,2,,gitlab:GitlabMergeRequest:1:32348491,MergeRequest,gitlab:GitlabAccount:1:2295562,"added 1 commit
-
-<ul><li>abbe0ab2 - add first bit</li></ul>
-
-[Compare with previous version](/gitlab-data/snowflake_spend/merge_requests/1/diffs?diff_id=46674001&start_sha=8891924597600f608459fa9d981145d89add1161)",0,1,2019-06-28T05:40:58.739+00:00
-gitlab:GitlabMrNote:1:186434804,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,3,,gitlab:GitlabMergeRequest:1:32348491,MergeRequest,gitlab:GitlabAccount:1:2295562,"added 1 commit
-
-<ul><li>e01d4f03 - move analyses</li></ul>
-
-[Compare with previous version](/gitlab-data/snowflake_spend/merge_requests/1/diffs?diff_id=46703580&start_sha=abbe0ab2c7bb1dc2cfaa3ef3062f378fb908ba71)",0,1,2019-06-28T10:43:27.426+00:00
-gitlab:GitlabMrNote:1:186436608,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,4,,gitlab:GitlabMergeRequest:1:32348491,MergeRequest,gitlab:GitlabAccount:1:2295562,"added 1 commit
-
-<ul><li>3f04e0a6 - finish top level readme</li></ul>
-
-[Compare with previous version](/gitlab-data/snowflake_spend/merge_requests/1/diffs?diff_id=46704153&start_sha=e01d4f03811cd0da9949848731236e0aa261cf54)",0,1,2019-06-28T10:49:01.184+00:00
-gitlab:GitlabMrNote:1:186438503,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,5,,gitlab:GitlabMergeRequest:1:32348491,MergeRequest,gitlab:GitlabAccount:1:2295562,"added 1 commit
-
-<ul><li>382084b4 - add info on dashboard</li></ul>
-
-[Compare with previous version](/gitlab-data/snowflake_spend/merge_requests/1/diffs?diff_id=46705058&start_sha=3f04e0a61d0c4d2dd736a6bcaa3a06826269a533)",0,1,2019-06-28T10:54:45.674+00:00
-gitlab:GitlabMrNote:1:186438743,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,6,,gitlab:GitlabMergeRequest:1:32348491,MergeRequest,gitlab:GitlabAccount:1:2295562,unmarked as a **Work In Progress**,0,1,2019-06-28T10:55:26.170+00:00
-gitlab:GitlabMrNote:1:186439132,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,7,,gitlab:GitlabMergeRequest:1:32348491,MergeRequest,gitlab:GitlabAccount:1:2295562,"@tayloramurphy Once this is merged, let's make this a release version?",0,0,2019-06-28T10:56:46.646+00:00
-gitlab:GitlabMrNote:1:186439136,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,8,,gitlab:GitlabMergeRequest:1:32348491,MergeRequest,gitlab:GitlabAccount:1:2295562,assigned to @tayloramurphy and unassigned @emilie,0,1,2019-06-28T10:56:47.115+00:00
-gitlab:GitlabMrNote:1:186441803,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,9,,gitlab:GitlabMergeRequest:1:32348491,MergeRequest,gitlab:GitlabAccount:1:2295562,"added 1 commit
-
-<ul><li>ad25fcda - add more info to readme</li></ul>
-
-[Compare with previous version](/gitlab-data/snowflake_spend/merge_requests/1/diffs?diff_id=46705949&start_sha=382084b42697577d3a6adf71ce73d4b5ddd22977)",0,1,2019-06-28T11:04:01.697+00:00
-gitlab:GitlabMrNote:1:186537187,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,10,,gitlab:GitlabMergeRequest:1:32348491,MergeRequest,gitlab:GitlabAccount:1:1942272,mentioned in commit da1d6dea48f5972ffc683da6cff30934e7d6c52c,0,1,2019-06-28T14:32:06.002+00:00
-gitlab:GitlabMrNote:1:186537191,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,11,,gitlab:GitlabMergeRequest:1:32348491,MergeRequest,gitlab:GitlabAccount:1:1942272,merged,0,1,2019-06-28T14:32:06.279+00:00
-gitlab:GitlabMrNote:1:208061122,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,12,,gitlab:GitlabMergeRequest:1:35064956,MergeRequest,gitlab:GitlabAccount:1:2295562,@mg12 This looks good to me. Want me to merge?,0,0,2019-08-26T12:14:39.003+00:00
-gitlab:GitlabMrNote:1:208092969,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,13,,gitlab:GitlabMergeRequest:1:35064956,MergeRequest,gitlab:GitlabAccount:1:3871284,@emilie Let's do it!,0,0,2019-08-26T13:17:51.707+00:00
-gitlab:GitlabMrNote:1:208121492,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,14,,gitlab:GitlabMergeRequest:1:35064956,MergeRequest,gitlab:GitlabAccount:1:2295562,assigned to @emilie,0,1,2019-08-26T14:14:59.344+00:00
-gitlab:GitlabMrNote:1:208121682,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,15,,gitlab:GitlabMergeRequest:1:35064956,MergeRequest,gitlab:GitlabAccount:1:2295562,merged,0,1,2019-08-26T14:15:27.936+00:00
-gitlab:GitlabMrNote:1:208121722,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,16,,gitlab:GitlabMergeRequest:1:35064956,MergeRequest,gitlab:GitlabAccount:1:2295562,mentioned in commit d678bea9d47b42eb13512d1c9d6a592d80b432d4,0,1,2019-08-26T14:15:33.136+00:00
-gitlab:GitlabMrNote:1:208121781,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,17,,gitlab:GitlabMergeRequest:1:35064956,MergeRequest,gitlab:GitlabAccount:1:2295562,Merged! Thanks for your contribution @mg12!,0,0,2019-08-26T14:15:40.464+00:00
-gitlab:GitlabMrNote:1:208185588,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,18,,gitlab:GitlabMergeRequest:1:35841926,MergeRequest,gitlab:GitlabAccount:1:2295562,restored source branch `4-config-is-not-generic-enough`,0,1,2019-08-26T15:33:21.878+00:00
-gitlab:GitlabMrNote:1:208185663,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,19,,gitlab:GitlabMergeRequest:1:35841926,MergeRequest,gitlab:GitlabAccount:1:2295562,assigned to @emilie,0,1,2019-08-26T15:33:34.019+00:00
-gitlab:GitlabMrNote:1:208186075,"{""ConnectionId"":1,""ProjectId"":12345678}",_raw_gitlab_api_merge_request_notes,20,,gitlab:GitlabMergeRequest:1:35841926,MergeRequest,gitlab:GitlabAccount:1:2295562,"added 1 commit
-
-<ul><li>91e5666b - remove config</li></ul>
-
-[Compare with previous version](/gitlab-data/snowflake_spend/merge_requests/4/diffs?diff_id=52612655&start_sha=d678bea9d47b42eb13512d1c9d6a592d80b432d4)",0,1,2019-08-26T15:34:37.958+00:00
diff --git a/plugins/gitlab/impl/impl.go b/plugins/gitlab/impl/impl.go
index cf5e1bb0..4c62da6f 100644
--- a/plugins/gitlab/impl/impl.go
+++ b/plugins/gitlab/impl/impl.go
@@ -70,7 +70,6 @@ func (plugin Gitlab) SubTaskMetas() []core.SubTaskMeta {
 		tasks.ConvertAccountsMeta,
 		tasks.ConvertProjectMeta,
 		tasks.ConvertApiMergeRequestsMeta,
-		tasks.ConvertApiNotesMeta,
 		tasks.ConvertMrCommentMeta,
 		tasks.ConvertApiMrCommitsMeta,
 		tasks.ConvertIssuesMeta,
diff --git a/plugins/gitlab/tasks/note_convertor.go b/plugins/gitlab/tasks/note_convertor.go
deleted file mode 100644
index 7980fefd..00000000
--- a/plugins/gitlab/tasks/note_convertor.go
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
-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/plugins/core/dal"
-
-	"github.com/apache/incubator-devlake/models/domainlayer"
-	"github.com/apache/incubator-devlake/models/domainlayer/code"
-	"github.com/apache/incubator-devlake/models/domainlayer/didgen"
-	"github.com/apache/incubator-devlake/plugins/core"
-	"github.com/apache/incubator-devlake/plugins/gitlab/models"
-	"github.com/apache/incubator-devlake/plugins/helper"
-)
-
-var ConvertApiNotesMeta = core.SubTaskMeta{
-	Name:             "convertApiNotes",
-	EntryPoint:       ConvertApiNotes,
-	EnabledByDefault: true,
-	Description:      "Update domain layer Note according to GitlabMrNote",
-	DomainTypes:      []string{core.DOMAIN_TYPE_CODE_REVIEW},
-}
-
-func ConvertApiNotes(taskCtx core.SubTaskContext) error {
-	rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_PROJECT_TABLE)
-	db := taskCtx.GetDal()
-	clauses := []dal.Clause{
-		dal.From(&models.GitlabMrNote{}),
-		dal.Join(`left join _tool_gitlab_merge_requests 
-			on _tool_gitlab_merge_requests.gitlab_id = 
-			_tool_gitlab_mr_notes.merge_request_id`),
-		dal.Where(`_tool_gitlab_merge_requests.project_id = ? 
-			and _tool_gitlab_mr_notes.connection_id = ? `,
-			data.Options.ProjectId, data.Options.ConnectionId),
-	}
-
-	cursor, err := db.Cursor(clauses...)
-	if err != nil {
-		return err
-	}
-	defer cursor.Close()
-
-	domainIdGeneratorNote := didgen.NewDomainIdGenerator(&models.GitlabMrNote{})
-	prIdGen := didgen.NewDomainIdGenerator(&models.GitlabMergeRequest{})
-	accountIdGen := didgen.NewDomainIdGenerator(&models.GitlabAccount{})
-
-	converter, err := helper.NewDataConverter(helper.DataConverterArgs{
-		RawDataSubTaskArgs: *rawDataSubTaskArgs,
-		InputRowType:       reflect.TypeOf(models.GitlabMrNote{}),
-		Input:              cursor,
-
-		Convert: func(inputRow interface{}) ([]interface{}, error) {
-			gitlabNotes := inputRow.(*models.GitlabMrNote)
-			domainNote := &code.Note{
-				DomainEntity: domainlayer.DomainEntity{
-					Id: domainIdGeneratorNote.Generate(data.Options.ConnectionId, gitlabNotes.GitlabId),
-				},
-				PrId:        prIdGen.Generate(data.Options.ConnectionId, gitlabNotes.MergeRequestId),
-				Type:        gitlabNotes.NoteableType,
-				Author:      accountIdGen.Generate(data.Options.ConnectionId, gitlabNotes.AuthorUserId),
-				Body:        gitlabNotes.Body,
-				Resolvable:  gitlabNotes.Resolvable,
-				IsSystem:    gitlabNotes.IsSystem,
-				CreatedDate: gitlabNotes.GitlabCreatedAt,
-			}
-			return []interface{}{
-				domainNote,
-			}, nil
-		},
-	})
-	if err != nil {
-		return err
-	}
-
-	return converter.Execute()
-}