likyh commented on code in PR #2641:
URL: https://github.com/apache/incubator-devlake/pull/2641#discussion_r934129653
##########
generator/cmd/create_plugin.go:
##########
@@ -112,30 +113,21 @@ Type in what the name of plugin is, then generator will
create a new plugin in p
values := map[string]string{}
templates := map[string]string{}
if withApiClient == `Yes` {
- prompt := promptui.Prompt{
- Label: "Endpoint (which host to request)",
- Default: `https://open.example.cn/api/v1`,
- Validate: func(input string) error {
- if input == `` {
- return errors.New("endpoint
require")
- }
- if !strings.HasPrefix(input, `http`) {
- return errors.New("endpoint
should start with http")
- }
- return nil
- },
- }
- endpoint, err := prompt.Run()
- cobra.CheckErr(err)
-
+ versionTimestamp := time.Now().Format(`20060102`)
+ values[`Date`] = versionTimestamp
// read template
templates = map[string]string{
- `plugin_main.go`:
util.ReadTemplate("generator/template/plugin/plugin_main_with_api_client.go-template"),
- `tasks/api_client.go`:
util.ReadTemplate("generator/template/plugin/tasks/api_client.go-template"),
- `tasks/task_data.go`:
util.ReadTemplate("generator/template/plugin/tasks/task_data_with_api_client.go-template"),
+ fmt.Sprintf(`%s.go`, pluginName):
util.ReadTemplate("generator/template/plugin/plugin_main_with_api_client.go-template"),
+ `impl/impl.go`:
util.ReadTemplate("generator/template/plugin/impl/impl_with_api_client.go-template"),
Review Comment:
it also related with:
https://github.com/apache/incubator-devlake/blob/main/generator/cmd/create_collector.go#L138
##########
generator/template/plugin/impl/impl_with_api_client.go-template:
##########
@@ -0,0 +1,123 @@
+/*
+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 (
+ "fmt"
+ "github.com/apache/incubator-devlake/migration"
+ "github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/plugins/{{ .plugin_name }}/api"
+ "github.com/apache/incubator-devlake/plugins/{{ .plugin_name }}/models"
+ "github.com/apache/incubator-devlake/plugins/{{ .plugin_name
}}/models/migrationscripts"
Review Comment:
let's use a tab instead of 4 spaces.
##########
generator/template/plugin/impl/impl_with_api_client.go-template:
##########
@@ -0,0 +1,123 @@
+/*
+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 (
+ "fmt"
+ "github.com/apache/incubator-devlake/migration"
+ "github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/plugins/{{ .plugin_name }}/api"
+ "github.com/apache/incubator-devlake/plugins/{{ .plugin_name }}/models"
+ "github.com/apache/incubator-devlake/plugins/{{ .plugin_name
}}/models/migrationscripts"
+ "github.com/apache/incubator-devlake/plugins/{{ .plugin_name }}/tasks"
+ "github.com/apache/incubator-devlake/plugins/helper"
+ "github.com/spf13/viper"
+ "gorm.io/gorm"
+)
+
+// make sure interface is implemented
+var _ core.PluginMeta = (*{{ .PluginName }})(nil)
+var _ core.PluginInit = (*{{ .PluginName }})(nil)
+var _ core.PluginTask = (*{{ .PluginName }})(nil)
+var _ core.PluginApi = (*{{ .PluginName }})(nil)
+var _ core.PluginBlueprintV100 = (*{{ .PluginName }})(nil)
+var _ core.CloseablePluginTask = (*{{ .PluginName }})(nil)
+
+
+
+type {{ .PluginName }} struct{}
+
+func (plugin {{ .PluginName }}) Description() string {
+ return "collect some {{ .PluginName }} data"
+}
+
+func (plugin {{ .PluginName }}) Init(config *viper.Viper, logger core.Logger,
db *gorm.DB) error {
+ api.Init(config, logger, db)
+ return nil
+}
+
+func (plugin {{ .PluginName }}) SubTaskMetas() []core.SubTaskMeta {
+ // TODO add your sub task here
+ return []core.SubTaskMeta{
+ }
+}
+
+func (plugin {{ .PluginName }}) PrepareTaskData(taskCtx core.TaskContext,
options map[string]interface{}) (interface{}, error) {
+ op, err := tasks.DecodeAndValidateTaskOptions(options)
+ if err != nil {
+ return nil, err
+ }
+ connectionHelper := helper.NewConnectionHelper(
+ taskCtx,
+ nil,
+ )
+ connection := &models.{{ .PluginName }}Connection{}
+ err = connectionHelper.FirstById(connection, op.ConnectionId)
+ if err != nil {
+ return nil, fmt.Errorf("unable to get {{ .PluginName }} connection by
the given connection ID: %v", err)
+ }
+
+ apiClient, err := tasks.New{{ .PluginName }}ApiClient(taskCtx, connection)
+ if err != nil {
+ return nil, fmt.Errorf("unable to get {{ .PluginName }} API client
instance: %v", err)
+ }
+
+ return &tasks.{{ .PluginName }}TaskData{
+ Options: op,
+ ApiClient: apiClient,
+ }, nil
+}
+
+// PkgPath information lost when compiled as plugin(.so)
+func (plugin {{ .PluginName }}) RootPkgPath() string {
+ return "github.com/apache/incubator-devlake/plugins/{{ .plugin-name }}"
+}
+
+func (plugin {{ .PluginName }}) MigrationScripts() []migration.Script {
+ return migrationscripts.All()
+}
+
+func (plugin {{ .PluginName }}) ApiResources()
map[string]map[string]core.ApiResourceHandler {
+ return map[string]map[string]core.ApiResourceHandler{
+ "test": {
+ "POST": api.TestConnection,
+ },
+ "connections": {
+ "POST": api.PostConnections,
+ "GET": api.ListConnections,
+ },
+ "connections/:connectionId": {
+ "GET": api.GetConnection,
+ "PATCH": api.PatchConnection,
+ "DELETE": api.DeleteConnection,
+ },
+ }
+}
+
+func (plugin {{ .PluginName }}) MakePipelinePlan(connectionId uint64, scope
[]*core.BlueprintScopeV100) (core.PipelinePlan, error) {
+ return api.MakePipelinePlan(plugin.SubTaskMetas(), connectionId, scope)
Review Comment:
where is the MakePipelinePlan?
##########
generator/template/plugin/api/connection.go-template:
##########
@@ -0,0 +1,155 @@
+/*
+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 api
+
+import (
+ "context"
+ "fmt"
+ "net/http"
+ "time"
+
+ "github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/plugins/helper"
+ "github.com/apache/incubator-devlake/plugins/{{ .PluginName }}/models"
Review Comment:
plugin_name
##########
generator/template/plugin/api/blueprint.go-template:
##########
@@ -0,0 +1,69 @@
+/*
+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 api
+
+import (
+ "encoding/json"
+
+ "github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/plugins/helper"
+ "github.com/apache/incubator-devlake/plugins/{{ .plugin-name }}/tasks"
Review Comment:
plugin_name
##########
generator/cmd/create_plugin.go:
##########
@@ -112,30 +113,21 @@ Type in what the name of plugin is, then generator will
create a new plugin in p
values := map[string]string{}
templates := map[string]string{}
if withApiClient == `Yes` {
Review Comment:
change `withApiClient` to `generateCompletePlugin` or other appropriate name?
##########
generator/template/plugin/models/connection.go-template:
##########
@@ -0,0 +1,50 @@
+/*
+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 models
+
+import "github.com/apache/incubator-devlake/plugins/helper"
+
+//TODO Please modify the following code to fit your needs
+// This object conforms to what the frontend currently sends.
+type {{ .PluginName }}Connection struct {
+ helper.RestConnection `mapstructure:",squash"`
+ helper.AccessToken `mapstructure:",squash"`
+}
+
+type TestConnectionRequest struct {
+ Endpoint string `json:"endpoint"`
+ Proxy string `json:"proxy"`
+ helper.AccessToken `mapstructure:",squash"`
+}
+
+// This object conforms to what the frontend currently expects.
+type {{ .PluginName }}Response struct {
+ Name string `json:"name"`
+ ID int `json:"id"`
+ {{ .PluginName }}Connection
+}
+
+// Using User because it requires authentication.
+type ApiUserResponse struct {
+ Id int
+ Name string `json:"name"`
+}
+
+func ({{ .PluginName }}Connection) TableName() string {
+ return "_tool_{{ .plugin-name }}_connections"
Review Comment:
Instead of `plugin-name`, it should be `plugin_name`
##########
generator/template/plugin/api/connection.go-template:
##########
@@ -0,0 +1,155 @@
+/*
+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 api
+
+import (
+ "context"
+ "fmt"
+ "net/http"
+ "time"
+
+ "github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/plugins/helper"
+ "github.com/apache/incubator-devlake/plugins/{{ .PluginName }}/models"
+ "github.com/mitchellh/mapstructure"
+)
+
+//TODO Please modify the following code to fit your needs
+func TestConnection(input *core.ApiResourceInput) (*core.ApiResourceOutput,
error) {
+ // decode
+ var err error
+ var connection models.TestConnectionRequest
Review Comment:
Where is `TestConnectionRequest` ?
##########
generator/template/plugin/api/blueprint.go-template:
##########
@@ -0,0 +1,69 @@
+/*
+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 api
+
+import (
+ "encoding/json"
+
+ "github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/plugins/helper"
+ "github.com/apache/incubator-devlake/plugins/{{ .plugin-name }}/tasks"
+)
+
+func MakePipelinePlan(subtaskMetas []core.SubTaskMeta, connectionId uint64,
scope []*core.BlueprintScopeV100) (core.PipelinePlan, error) {
+ var err error
+ plan := make(core.PipelinePlan, len(scope))
+ for i, scopeElem := range scope {
+ taskOptions := make(map[string]interface{})
+ err = json.Unmarshal(scopeElem.Options, &taskOptions)
+ if err != nil {
+ return nil, err
+ }
+ taskOptions["connectionId"] = connectionId
+
+ //TODO Add transformation rules to task options
+
+ /*
+ var transformationRules tasks.TransformationRules
+ if len(scopeElem.Transformation) > 0 {
+ err = json.Unmarshal(scopeElem.Transformation,
&transformationRules)
+ if err != nil {
+ return nil, err
+ }
+ }
+ */
+ //taskOptions["transformationRules"] = transformationRules
+ _, err := tasks.DecodeAndValidateTaskOptions(taskOptions)
+ if err != nil {
+ return nil, err
+ }
+ // subtasks
+ subtasks, err := helper.MakePipelinePlanSubtasks(subtaskMetas,
scopeElem.Entities)
+ if err != nil {
+ return nil, err
+ }
+ plan[i] = core.PipelineStage{
+ {
+ Plugin: "{{ .plugin-name }}",
Review Comment:
plugin_name
##########
generator/template/plugin/impl/impl_with_api_client.go-template:
##########
@@ -0,0 +1,123 @@
+/*
+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 (
+ "fmt"
+ "github.com/apache/incubator-devlake/migration"
+ "github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/plugins/{{ .plugin_name }}/api"
+ "github.com/apache/incubator-devlake/plugins/{{ .plugin_name }}/models"
+ "github.com/apache/incubator-devlake/plugins/{{ .plugin_name
}}/models/migrationscripts"
+ "github.com/apache/incubator-devlake/plugins/{{ .plugin_name }}/tasks"
+ "github.com/apache/incubator-devlake/plugins/helper"
+ "github.com/spf13/viper"
+ "gorm.io/gorm"
+)
+
+// make sure interface is implemented
+var _ core.PluginMeta = (*{{ .PluginName }})(nil)
+var _ core.PluginInit = (*{{ .PluginName }})(nil)
+var _ core.PluginTask = (*{{ .PluginName }})(nil)
+var _ core.PluginApi = (*{{ .PluginName }})(nil)
+var _ core.PluginBlueprintV100 = (*{{ .PluginName }})(nil)
+var _ core.CloseablePluginTask = (*{{ .PluginName }})(nil)
+
+
+
+type {{ .PluginName }} struct{}
+
+func (plugin {{ .PluginName }}) Description() string {
+ return "collect some {{ .PluginName }} data"
+}
+
+func (plugin {{ .PluginName }}) Init(config *viper.Viper, logger core.Logger,
db *gorm.DB) error {
+ api.Init(config, logger, db)
+ return nil
+}
+
+func (plugin {{ .PluginName }}) SubTaskMetas() []core.SubTaskMeta {
+ // TODO add your sub task here
+ return []core.SubTaskMeta{
+ }
+}
+
+func (plugin {{ .PluginName }}) PrepareTaskData(taskCtx core.TaskContext,
options map[string]interface{}) (interface{}, error) {
+ op, err := tasks.DecodeAndValidateTaskOptions(options)
+ if err != nil {
+ return nil, err
+ }
+ connectionHelper := helper.NewConnectionHelper(
+ taskCtx,
+ nil,
+ )
+ connection := &models.{{ .PluginName }}Connection{}
+ err = connectionHelper.FirstById(connection, op.ConnectionId)
+ if err != nil {
+ return nil, fmt.Errorf("unable to get {{ .PluginName }} connection by
the given connection ID: %v", err)
+ }
+
+ apiClient, err := tasks.New{{ .PluginName }}ApiClient(taskCtx, connection)
+ if err != nil {
+ return nil, fmt.Errorf("unable to get {{ .PluginName }} API client
instance: %v", err)
+ }
+
+ return &tasks.{{ .PluginName }}TaskData{
+ Options: op,
+ ApiClient: apiClient,
+ }, nil
+}
+
+// PkgPath information lost when compiled as plugin(.so)
+func (plugin {{ .PluginName }}) RootPkgPath() string {
+ return "github.com/apache/incubator-devlake/plugins/{{ .plugin-name }}"
Review Comment:
plugin_name
##########
generator/template/plugin/api/blueprint.go-template:
##########
@@ -0,0 +1,69 @@
+/*
Review Comment:
This file seems not used.
##########
generator/template/plugin/plugin_main_with_api_client.go-template:
##########
@@ -18,70 +18,13 @@ limitations under the License.
package main
import (
- "github.com/apache/incubator-devlake/plugins/core"
- "github.com/apache/incubator-devlake/plugins/{{ .pluginName }}/tasks"
+ "github.com/apache/incubator-devlake/plugins/{{ .PluginName }}/impl"
Review Comment:
plugin_name
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]