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 a0d7355cb Feat dora implement plugin blueprint v200 (#3791)
a0d7355cb is described below

commit a0d7355cbf69e7252b75f8e02babf531883cab99
Author: Warren Chen <[email protected]>
AuthorDate: Thu Nov 24 15:25:09 2022 +0800

    Feat dora implement plugin blueprint v200 (#3791)
    
    * feat(dora): implement blueprint V200
    
    * fix(dora): update according to review
---
 plugins/dora/impl/impl.go      | 32 ++++++++++++++++++++++++-
 plugins/dora/impl/impl_test.go | 54 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 1 deletion(-)

diff --git a/plugins/dora/impl/impl.go b/plugins/dora/impl/impl.go
index fd45d58da..1bcb3168a 100644
--- a/plugins/dora/impl/impl.go
+++ b/plugins/dora/impl/impl.go
@@ -18,8 +18,8 @@ limitations under the License.
 package impl
 
 import (
+       "encoding/json"
        "fmt"
-
        "github.com/apache/incubator-devlake/errors"
        "github.com/apache/incubator-devlake/plugins/core"
        
"github.com/apache/incubator-devlake/plugins/dora/models/migrationscripts"
@@ -36,6 +36,7 @@ var _ core.PluginModel = (*Dora)(nil)
 var _ core.PluginMetric = (*Dora)(nil)
 var _ core.CloseablePluginTask = (*Dora)(nil)
 var _ core.PluginMigration = (*Dora)(nil)
+var _ core.MetricPluginBlueprintV200 = (*Dora)(nil)
 
 type Dora struct{}
 
@@ -114,6 +115,35 @@ func (plugin Dora) MigrationScripts() 
[]core.MigrationScript {
        return migrationscripts.All()
 }
 
+func (plugin Dora) MakeMetricPluginPipelinePlanV200(projectName string, 
options json.RawMessage) (core.PipelinePlan, errors.Error) {
+       plan := core.PipelinePlan{}
+       op := &tasks.DoraOptions{}
+       err := json.Unmarshal(options, op)
+       if err != nil {
+               return nil, errors.Default.WrapRaw(err)
+       }
+       stageDeploymentCommitdiff := core.PipelineStage{
+               {
+                       Plugin:   "refdiff",
+                       Subtasks: []string{"calculateDeploymentDiffs"},
+                       Options: map[string]interface{}{
+                               "projectName": projectName,
+                       },
+               },
+       }
+       stageDora := core.PipelineStage{
+               {
+                       Plugin: "dora",
+                       Options: map[string]interface{}{
+                               "projectName": projectName,
+                       },
+               },
+       }
+       plan = append(plan, stageDeploymentCommitdiff, stageDora)
+
+       return plan, nil
+}
+
 func (plugin Dora) Close(taskCtx core.TaskContext) errors.Error {
        data, ok := taskCtx.GetData().(*tasks.DoraTaskData)
        if !ok {
diff --git a/plugins/dora/impl/impl_test.go b/plugins/dora/impl/impl_test.go
new file mode 100644
index 000000000..7f66d112e
--- /dev/null
+++ b/plugins/dora/impl/impl_test.go
@@ -0,0 +1,54 @@
+/*
+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 impl
+
+import (
+       "encoding/json"
+       "github.com/apache/incubator-devlake/plugins/core"
+       "github.com/stretchr/testify/assert"
+       "testing"
+)
+
+func TestMakeMetricPluginPipelinePlanV200(t *testing.T) {
+       var dora Dora
+       const projectName = "TestMakePlanV200-project"
+       // mock dora plugin as a metric plugin
+       option := map[string]interface{}{
+               "projectName": projectName,
+       }
+
+       optionJson, err := json.Marshal(option)
+       assert.Nil(t, err)
+       plan, err := dora.MakeMetricPluginPipelinePlanV200(projectName, 
optionJson)
+       doraOutputPlan := core.PipelinePlan{
+               core.PipelineStage{
+                       {
+                               Plugin:   "refdiff",
+                               Subtasks: []string{"calculateDeploymentDiffs"},
+                               Options:  map[string]interface{}{"projectName": 
projectName},
+                       },
+               },
+               core.PipelineStage{
+                       {
+                               Plugin:  "dora",
+                               Options: map[string]interface{}{"projectName": 
projectName},
+                       },
+               },
+       }
+       assert.Equal(t, doraOutputPlan, plan)
+}

Reply via email to