You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ma...@apache.org on 2022/07/21 07:17:19 UTC

[incubator-devlake] branch main updated: refactor: organize api inspecting scripts (#2563)

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

mappjzc 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 5a50687f refactor: organize api inspecting scripts (#2563)
5a50687f is described below

commit 5a50687f4afaec9ef3880cf110f2457898fdd45f
Author: Klesh Wong <zh...@merico.dev>
AuthorDate: Thu Jul 21 15:17:16 2022 +0800

    refactor: organize api inspecting scripts (#2563)
---
 .gitignore                                         |   8 +-
 scripts/api.sh                                     |  34 --
 scripts/pm.sh                                      | 369 ---------------------
 scripts/pm/framework/pipeline-create.sh            |  24 ++
 scripts/pm/framework/pipeline-get-detail.sh        |   7 +
 scripts/pm/framework/pipeline-get-tasks.sh         |   7 +
 scripts/pm/framework/proceed-db-migration.sh       |   6 +
 scripts/pm/jira/board-issues.sh                    |   9 +
 .../vars/active-vars.sh.example}                   |  12 +-
 9 files changed, 61 insertions(+), 415 deletions(-)

diff --git a/.gitignore b/.gitignore
index b47c22b6..dda6d767 100644
--- a/.gitignore
+++ b/.gitignore
@@ -73,6 +73,7 @@ web_modules/
 .env
 .env.*
 !.env.example
+scripts/pm/vars/*-vars.sh
 
 # parcel-bundler cache (https://parceljs.org/)
 .cache
@@ -151,10 +152,9 @@ bin
 libgit2
 .air.toml
 
-# swagger .json and .yaml
-api/docs/swagger.json
-api/docs/swagger.yaml
-
 # auto generated code
 mocks/
+api/docs/swagger.json
+api/docs/swagger.yaml
 api/docs/docs.go
+*.result/
diff --git a/scripts/api.sh b/scripts/api.sh
deleted file mode 100755
index dc2e9106..00000000
--- a/scripts/api.sh
+++ /dev/null
@@ -1,34 +0,0 @@
-#!/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.
-#
-
-set -e
-
-notes() {
-    curl -v "$GITLAB_ENDPOINT/projects/8967944/merge_requests/1349/notes?system=false&per_page=100&page=1" \
-        -H "Authorization: Bearer $GITLAB_AUTH"
-}
-
-commits() {
-    SIZE=${1-100}
-    PAGE=${2-1}
-    PROJ=${3-8967944}
-    curl -v "$GITLAB_ENDPOINT/projects/$PROJ/repository/commits?with_stats=true&per_page=$SIZE&page=$PAGE" \
-        -H "Authorization: Bearer $GITLAB_AUTH"
-}
-
-"$@"
diff --git a/scripts/pm.sh b/scripts/pm.sh
deleted file mode 100755
index f9972755..00000000
--- a/scripts/pm.sh
+++ /dev/null
@@ -1,369 +0,0 @@
-#!/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.
-#
-
-set -e
-
-SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
-
-LAKE_ENDPOINT=${LAKE_ENDPOINT-'http://localhost:8080'}
-LAKE_PIPELINE_URL=$LAKE_ENDPOINT/pipelines
-
-debug() {
-    $SCRIPT_DIR/compile-plugins.sh -gcflags=all="-N -l"
-    dlv debug
-}
-
-run() {
-    $SCRIPT_DIR/compile-plugins.sh
-    go run $SCRIPT_DIR/../main.go
-}
-
-jira_source_post() {
-    curl -v -XPOST "$LAKE_ENDPOINT/plugins/jira/connections" --data '
-    {
-        "name": "test-jira-connection",
-        "endpoint": "'"$JIRA_ENDPOINT"'",
-        "basicAuthEncoded": "'"$JIRA_BASIC_AUTH_ENCODED"'",
-        "epicKeyField": "'"$JIRA_ENDPOINT"'",
-        "storyPointField": "'"$JIRA_ISSUE_STORYPOINT_FIELD"'",
-    }
-    ' | jq
-}
-
-jira_source_post_full() {
-    curl -v -XPOST "$LAKE_ENDPOINT/plugins/jira/connections" --data '
-    {
-        "name": "test-jira-connection",
-        "endpoint": "'"$JIRA_ENDPOINT"'",
-        "basicAuthEncoded": "'"$JIRA_BASIC_AUTH_ENCODED"'",
-        "epicKeyField": "'"$JIRA_ENDPOINT"'",
-        "storyPointField": "'"$JIRA_ISSUE_STORYPOINT_FIELD"'",
-        "typeMappings": {
-            "Story": {
-                "standardType": "Requirement",
-                "statusMappings": {
-                    "已完成": {
-                        "standardStatus": "Resolved"
-                    },
-                    "已解决": {
-                        "standardStatus": "Resolved"
-                    }
-                }
-            },
-            "Incident": {
-                "standardType": "Incident",
-                "statusMappings": {
-                    "已完成": {
-                        "standardStatus": "Resolved"
-                    }
-                }
-            },
-            "Bug": {
-                "standardType": "Bug",
-                "statusMappings": {
-                    "已完成": {
-                        "standardStatus": "Resolved"
-                    }
-                }
-            }
-        }
-    }' | jq
-}
-
-jira_source_post_fail() {
-    curl -v -XPOST "$LAKE_ENDPOINT/plugins/jira/connections" --data @- <<'    JSON' | jq
-    {
-        "name": "test-jira-connection-fail",
-        "endpoint": "https://merico.atlassian.net/rest",
-        "basicAuthEncoded": "basicAuth",
-        "epicKeyField": "epicKeyField",
-        "storyPointField": "storyPointField",
-        "typeMappings": "ehhlow"
-    }
-    JSON
-}
-
-jira_source_put() {
-    curl -v -XPUT "$LAKE_ENDPOINT/plugins/jira/connections/$1" --data @- <<'    JSON' | jq
-    {
-        "name": "test-jira-connection-updated",
-        "endpoint": "https://merico.atlassian.net/rest",
-        "basicAuthEncoded": "basicAuth",
-        "epicKeyField": "epicKeyField",
-        "storyPointField": "storyPointField",
-    }
-    JSON
-}
-
-jira_source_put_full() {
-    curl -v -XPUT "$LAKE_ENDPOINT/plugins/jira/connections/$1" --data '
-    {
-        "name": "test-jira-connection-updated",
-        "endpoint": "'"$JIRA_ENDPOINT"'",
-        "basicAuthEncoded": "'"$JIRA_BASIC_AUTH_ENCODED"'",
-        "epicKeyField": "'"$JIRA_ENDPOINT"'",
-        "storyPointField": "'"$JIRA_ISSUE_STORYPOINT_FIELD"'",
-        "typeMappings": {
-            "Story": {
-                "standardType": "Requirement",
-                "statusMappings": {
-                    "已完成": {
-                        "standardStatus": "Resolved"
-                    },
-                    "已解决": {
-                        "standardStatus": "Resolved"
-                    }
-                }
-            },
-            "Incident": {
-                "standardType": "Incident",
-                "statusMappings": {
-                    "已完成": {
-                        "standardStatus": "Resolved"
-                    }
-                }
-            },
-            "Bug": {
-                "standardType": "Bug",
-                "statusMappings": {
-                    "已完成": {
-                        "standardStatus": "Resolved"
-                    }
-                }
-            }
-        }
-    }' | jq
-}
-
-jira_source_list() {
-    curl -v "$LAKE_ENDPOINT/plugins/jira/connections" | jq
-}
-
-jira_source_get() {
-    curl -v "$LAKE_ENDPOINT/plugins/jira/connections/$1" | jq
-}
-
-jira_source_delete() {
-    curl -v -XDELETE "$LAKE_ENDPOINT/plugins/jira/connections/$1"
-}
-
-jira_typemapping_post() {
-    curl -v -XPOST "$LAKE_ENDPOINT/plugins/jira/connections/$1/type-mappings" --data @- <<'    JSON' | jq
-    {
-        "userType": "userType",
-        "standardType": "standardType"
-    }
-    JSON
-}
-
-jira_typemapping_put() {
-    curl -v -XPUT "$LAKE_ENDPOINT/plugins/jira/connections/$1/type-mappings/$2" --data @- <<'    JSON' | jq
-    {
-        "standardType": "standardTypeUpdated"
-    }
-    JSON
-}
-
-jira_typemapping_delete() {
-    curl -v -XDELETE "$LAKE_ENDPOINT/plugins/jira/connections/$1/type-mappings/$2"
-}
-
-jira_typemapping_list() {
-    curl -v "$LAKE_ENDPOINT/plugins/jira/connections/$1/type-mappings" | jq
-}
-
-jira_statusmapping_post() {
-    curl -v -XPOST "$LAKE_ENDPOINT/plugins/jira/connections/$1/type-mappings/$2/status-mappings" --data @- <<'    JSON' | jq
-    {
-        "userStatus": "userStatus",
-        "standardStatus": "standardStatus"
-    }
-    JSON
-}
-
-jira_statusmapping_put() {
-    curl -v -XPUT "$LAKE_ENDPOINT/plugins/jira/connections/$1/type-mappings/$2/status-mappings/$3" --data @- <<'    JSON' | jq
-    {
-        "standardStatus": "standardStatusUpdated"
-    }
-    JSON
-}
-
-jira_statusmapping_delete() {
-    curl -v -XDELETE "$LAKE_ENDPOINT/plugins/jira/connections/$1/type-mappings/$2/status-mappings/$3"
-}
-
-jira_statusmapping_list() {
-    curl -v "$LAKE_ENDPOINT/plugins/jira/connections/$1/type-mappings/$2/status-mappings" | jq
-}
-
-jira_echo() {
-    curl -v -XPOST "$LAKE_ENDPOINT/plugins/jira/echo" --data @- <<'    JSON' | jq
-    {
-        "plugin": "jira",
-        "options": {
-            "boardId": 8
-        }
-    }
-    JSON
-}
-
-pipeline_new() {
-    curl -v -XPOST $LAKE_PIPELINE_URL --data @- <<'    JSON' | jq
-    {
-        "name": "test-all",
-        "tasks": [
-            [
-                {
-                    "plugin": "jira",
-                    "options": {
-                        "connectionId": 1,
-                        "boardId": 8
-                    }
-                },
-                {
-                    "plugin": "jenkins",
-                    "options": {}
-                }
-            ]
-        ]
-    }
-    JSON
-}
-
-pipelines() {
-    curl -v $LAKE_PIPELINE_URL'?'$1 | jq
-}
-
-pipeline() {
-    curl -v $LAKE_PIPELINE_URL/$1 | jq
-}
-
-pipeline_cancel() {
-    curl -v -XDELETE $LAKE_PIPELINE_URL/$1
-}
-
-pipeline_tasks() {
-    curl -v $LAKE_PIPELINE_URL/$1/tasks'?'$2 | jq
-}
-
-jira() {
-    curl -v -XPOST $LAKE_PIPELINE_URL --data '
-    {
-        "name": "test-jira",
-        "tasks": [
-            [
-                {
-                    "plugin": "jira",
-                    "options": {
-                        "connectionId": '$1',
-                        "boardId": '$2',
-                        "tasks": ['"$3"']
-                    }
-                }
-            ]
-        ]
-    }
-    ' | jq
-}
-
-gitlab() {
-    curl -v -XPOST $LAKE_PIPELINE_URL --data @- <<'    JSON'
-    {
-        "name": "test-gitlab",
-        "tasks": [
-            [
-                {
-                    "plugin": "gitlab",
-                    "options": {
-                        "projectId": 8967944,
-                        "tasks": ["collectMrs"]
-                    }
-                }
-            ]
-        ]
-    }
-    JSON
-}
-
-github() {
-    curl -v -XPOST $LAKE_PIPELINE_URL --data @- <<'    JSON'
-    {
-        "name": "test-github",
-        "tasks": [
-            [
-                {
-                    "plugin": "github",
-                    "options": {
-                        "repo": "lake",
-                        "owner": "merico-dev",
-                        "tasks": ["collectCommits"]
-                    }
-                }
-            ]
-        ]
-    }
-    JSON
-}
-
-jenkins() {
-    curl -v -XPOST $LAKE_PIPELINE_URL --data @- <<'    JSON'
-    {
-        "name": "test-jenkins",
-        "tasks": [
-            [
-                {
-                    "plugin": "jenkins",
-                    "options": {}
-                }
-            ]
-        ]
-    }
-    JSON
-}
-
-ae() {
-    curl -v -XPOST $LAKE_PIPELINE_URL --data @- <<'    JSON'
-    {
-        "name": "test-ae",
-        "tasks": [
-            [
-                {
-                    "plugin": "ae",
-                    "options": {
-                        "projectId": 13
-                    }
-                }
-            ]
-        ]
-    }
-    JSON
-}
-
-truncate() {
-    SQL=$()
-    echo "SET FOREIGN_KEY_CHECKS=0;"
-    echo 'show tables' | mycli local-lake | tail -n +2 | xargs -I{} -n 1 echo "truncate table {};"
-    echo "SET FOREIGN_KEY_CHECKS=1;"
-}
-
-lint() {
-    golangci-lint run -v
-}
-
-"$@"
diff --git a/scripts/pm/framework/pipeline-create.sh b/scripts/pm/framework/pipeline-create.sh
new file mode 100755
index 00000000..16e13f7f
--- /dev/null
+++ b/scripts/pm/framework/pipeline-create.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+. "$(dirname $0)/../vars/active-vars.sh"
+
+curl -sv $LAKE_ENDPOINT/pipelines --data @- <<JSON | jq
+{
+    "name": "test-all",
+    "plan": [
+        [
+            {
+                "plugin": "jira",
+                "options": {
+                    "connectionId": 1,
+                    "boardId": 8
+                }
+            },
+            {
+                "plugin": "jenkins",
+                "options": {}
+            }
+        ]
+    ]
+}
+JSON
diff --git a/scripts/pm/framework/pipeline-get-detail.sh b/scripts/pm/framework/pipeline-get-detail.sh
new file mode 100755
index 00000000..424ca8e2
--- /dev/null
+++ b/scripts/pm/framework/pipeline-get-detail.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+. "$(dirname $0)/../vars/active-vars.sh"
+
+pipeline_id=${1-"2"}
+
+curl -sv $LAKE_ENDPOINT/pipelines/$pipeline_id | jq
diff --git a/scripts/pm/framework/pipeline-get-tasks.sh b/scripts/pm/framework/pipeline-get-tasks.sh
new file mode 100755
index 00000000..2ec5028a
--- /dev/null
+++ b/scripts/pm/framework/pipeline-get-tasks.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+. "$(dirname $0)/../vars/active-vars.sh"
+
+pipeline_id=${1-"2"}
+
+curl -sv $LAKE_ENDPOINT/pipelines/$pipeline_id/tasks | jq
diff --git a/scripts/pm/framework/proceed-db-migration.sh b/scripts/pm/framework/proceed-db-migration.sh
new file mode 100755
index 00000000..d88599ab
--- /dev/null
+++ b/scripts/pm/framework/proceed-db-migration.sh
@@ -0,0 +1,6 @@
+
+#!/bin/sh
+
+sh "$(dirname $0)/../vars/active-vars.sh"
+
+curl -v $LAKE_ENDPOINT/proceed-db-migration | jq
diff --git a/scripts/pm/jira/board-issues.sh b/scripts/pm/jira/board-issues.sh
new file mode 100755
index 00000000..1728c691
--- /dev/null
+++ b/scripts/pm/jira/board-issues.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+. "$(dirname $0)/../vars/active-vars.sh"
+
+board_id=${1-"8"}
+
+curl -sv $JIRA_ENDPOINT/agile/1.0/board/$board_id/issue \
+    -H "Authorization: Basic $JIRA_BASIC_AUTH" \
+    | jq
diff --git a/scripts/export-env.sh b/scripts/pm/vars/active-vars.sh.example
old mode 100755
new mode 100644
similarity index 80%
rename from scripts/export-env.sh
rename to scripts/pm/vars/active-vars.sh.example
index c0fa4c94..5be19151
--- a/scripts/export-env.sh
+++ b/scripts/pm/vars/active-vars.sh.example
@@ -16,11 +16,7 @@
 # limitations under the License.
 #
 
-SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
-FILE=$SCRIPT_DIR/../.env
-
-if [ -f "$FILE" ]; then
-    export $(grep -v '^#' $FILE | sed 's/#.*$//g' | xargs)
-else 
-    echo "$FILE does not exist."
-fi
+# ln -s local-vars.sh active-vars.sh
+LAKE_ENDPOINT=${LAKE_ENDPOINT-'http://localhost:8080'}
+JIRA_ENDPOINT=https://merico.atlassian.net/rest
+JIRA_BASIC_AUTH=