Skip to content

fix(framework): update code generator templates#2641

Merged
warren830 merged 2 commits into
apache:mainfrom
merico-ai:fix-code-generator
Aug 18, 2022
Merged

fix(framework): update code generator templates#2641
warren830 merged 2 commits into
apache:mainfrom
merico-ai:fix-code-generator

Conversation

@warren830
Copy link
Copy Markdown
Contributor

@warren830 warren830 commented Jul 30, 2022

closes #2640

Summary

modify templates in package generator

Does this close any open issues?

closes #2640

Screenshots

image

Other Information

Any other information that is important to this PR.

@warren830 warren830 force-pushed the fix-code-generator branch from 5a869af to ea841b3 Compare July 30, 2022 07:56
token := taskCtx.GetConfig("{{ .PLUGIN_NAME }}_TOKEN")
if token == "" {
println("invalid {{ .PLUGIN_NAME }}_TOKEN, but ignore this error now")
import (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import duplicate with Line 20~25

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

"strconv"
"time"

"github.com/apache/incubator-devlake/plugins/{{ .pluginName }}/models"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plugin_name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

"github.com/apache/incubator-devlake/plugins/helper"
)

func New{{ .PluginName }}ApiClient(taskCtx core.TaskContext, connection *models.{{ .PluginName }}Connection) (*helper.ApiAsyncClient, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must the new plugin use the connection? Is there any simple way to deal with it?

Comment thread generator/cmd/create_plugin.go Outdated
// read template
templates = map[string]string{
`plugin_main.go`: util.ReadTemplate("generator/template/plugin/plugin_main_with_api_client.go-template"),
`impl/impl.go`: util.ReadTemplate("generator/template/plugin/impl/impl.go-template"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

impl_with_api_client.go-template ?

Comment thread generator/template/plugin/tasks/api_client.go-template
"github.com/apache/incubator-devlake/migration"
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/helper"
"github.com/apache/incubator-devlake/plugins/{{ .plugin_name }}/api"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no api/models/migrationscripts package

@warren830 warren830 force-pushed the fix-code-generator branch from ea841b3 to e854832 Compare August 1, 2022 04:28
Comment thread generator/cmd/create_plugin.go Outdated
`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"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"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"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use a tab instead of 4 spaces.

}

func ({{ .PluginName }}Connection) TableName() string {
return "_tool_{{ .plugin-name }}_connections"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of plugin-name, it should be plugin_name

import (
"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/{{ .pluginName }}/tasks"
"github.com/apache/incubator-devlake/plugins/{{ .PluginName }}/impl"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plugin_name

}

func (plugin {{ .PluginName }}) MakePipelinePlan(connectionId uint64, scope []*core.BlueprintScopeV100) (core.PipelinePlan, error) {
return api.MakePipelinePlan(plugin.SubTaskMetas(), connectionId, scope)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the MakePipelinePlan?


"github.com/apache/incubator-devlake/plugins/core"
"github.com/apache/incubator-devlake/plugins/helper"
"github.com/apache/incubator-devlake/plugins/{{ .plugin-name }}/tasks"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plugin_name


// PkgPath information lost when compiled as plugin(.so)
func (plugin {{ .PluginName }}) RootPkgPath() string {
return "github.com/apache/incubator-devlake/plugins/{{ .plugin-name }}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plugin_name

}
plan[i] = core.PipelineStage{
{
Plugin: "{{ .plugin-name }}",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plugin_name

@@ -0,0 +1,69 @@
/*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file seems not used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -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` {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change withApiClient to generateCompletePlugin or other appropriate name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

@warren830 warren830 force-pushed the fix-code-generator branch 3 times, most recently from 561116d to 2c9050e Compare August 1, 2022 05:58
@likyh
Copy link
Copy Markdown
Contributor

likyh commented Aug 3, 2022

LGTM

@warren830 warren830 force-pushed the fix-code-generator branch from 2c9050e to 46713da Compare August 3, 2022 07:28
Copy link
Copy Markdown
Contributor

@abeizn abeizn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@warren830 warren830 merged commit 107a5d3 into apache:main Aug 18, 2022
@warren830 warren830 deleted the fix-code-generator branch August 18, 2022 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][Generator] generator template needs to be updated

3 participants