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

likyh 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 0128c2d0 feat: enable blueprint v200 on framework level (#3866)
0128c2d0 is described below

commit 0128c2d0943c9b9f0c1f3753b7056aa312534544
Author: Klesh Wong <[email protected]>
AuthorDate: Tue Dec 6 22:41:38 2022 +0800

    feat: enable blueprint v200 on framework level (#3866)
---
 scripts/pm/github/create-blueprint-v200.sh      | 50 +++++++++++++++++++++++++
 scripts/pm/github/create-transformationrules.sh | 28 ++++++++++++++
 scripts/pm/github/put-repo.sh                   | 42 +++++++++++++++++++++
 services/blueprint.go                           | 12 ++++++
 4 files changed, 132 insertions(+)

diff --git a/scripts/pm/github/create-blueprint-v200.sh 
b/scripts/pm/github/create-blueprint-v200.sh
new file mode 100755
index 00000000..8745c372
--- /dev/null
+++ b/scripts/pm/github/create-blueprint-v200.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+#
+# 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.
+#
+
+. "$(dirname $0)/../vars/active-vars.sh"
+
+PROJECT_NAME=${1-"testproject"}
+
+curl -sv $LAKE_ENDPOINT/blueprints \
+    -H "Content-Type: application/json" \
+    --data @- <<JSON | jq
+{
+       "cronConfig": "0 0 * * 1",
+       "enable": true,
+       "isManual": true,
+       "mode": "NORMAL",
+       "name": "My GitHub Blueprint",
+    "projectName": "$PROJECT_NAME",
+    "settings": {
+        "version": "2.0.0",
+        "skipOnFail": false,
+        "connections": [
+            {
+                "plugin": "github",
+                "connectionId": 1,
+                "scopes": [
+                    {
+                        "id": "384111310",
+                        "entities":["CODE","CODEREVIEW"]
+                    }
+                ]
+            }
+        ]
+    }
+}
+JSON
diff --git a/scripts/pm/github/create-transformationrules.sh 
b/scripts/pm/github/create-transformationrules.sh
new file mode 100755
index 00000000..627268d9
--- /dev/null
+++ b/scripts/pm/github/create-transformationrules.sh
@@ -0,0 +1,28 @@
+#!/bin/sh
+#
+# 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.
+#
+
+. "$(dirname $0)/../vars/active-vars.sh"
+
+PROJECT_NAME=${1-"testproject"}
+
+curl -sv $LAKE_ENDPOINT/plugins/github/transformation_rules \
+    -H "Content-Type: application/json" \
+    --data @- <<JSON | jq
+{
+}
+JSON
diff --git a/scripts/pm/github/put-repo.sh b/scripts/pm/github/put-repo.sh
new file mode 100755
index 00000000..ce35c349
--- /dev/null
+++ b/scripts/pm/github/put-repo.sh
@@ -0,0 +1,42 @@
+#!/bin/sh
+#
+# 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.
+#
+
+. "$(dirname $0)/../vars/active-vars.sh"
+
+CONN_ID=${1-1}
+SCOPE_ID=${2-384111310}
+TR_ID=${3-1}
+SCOPE_NAME=${4-"apache/incubator-devlake"}
+SCOPE_URL=${5-"https://github.com/apache/incubator-devlake"}
+
+curl -sv -XPUT $LAKE_ENDPOINT/plugins/github/connections/$CONN_ID/scopes \
+    -H "Content-Type: application/json" \
+    --data @- <<JSON | jq
+    {
+
+        "data": [
+            {
+                "connectionId": $CONN_ID,
+                "githubId": $SCOPE_ID,
+                "name": "$SCOPE_NAME",
+                "htmlUrl": "$SCOPE_URL",
+                "transformationRuleId": $TR_ID
+            }
+        ]
+    }
+JSON
diff --git a/services/blueprint.go b/services/blueprint.go
index 9a31d6c1..d85ddfa7 100644
--- a/services/blueprint.go
+++ b/services/blueprint.go
@@ -336,6 +336,18 @@ func MakePlanForBlueprint(blueprint *models.Blueprint) 
(core.PipelinePlan, error
        switch bpSettings.Version {
        case "1.0.0":
                plan, err = GeneratePlanJsonV100(bpSettings)
+       case "2.0.0":
+               if blueprint.ProjectName == "" {
+                       return nil, errors.BadInput.New("projectName is 
required for blueprint v2.0.0")
+               }
+               // load project metric plugins and convert it to a map
+               metrics := make(map[string]json.RawMessage)
+               projectMetrics := make([]models.ProjectMetric, 0)
+               db.Find(&projectMetrics, "project_name = ? AND enable = ?", 
blueprint.ProjectName, true)
+               for _, projectMetric := range projectMetrics {
+                       metrics[projectMetric.PluginName] = 
json.RawMessage(projectMetric.PluginOption)
+               }
+               plan, err = GeneratePlanJsonV200(blueprint.ProjectName, 
bpSettings, metrics)
        default:
                return nil, errors.Default.New(fmt.Sprintf("unknown version of 
blueprint settings: %s", bpSettings.Version))
        }

Reply via email to