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 8e06e4cb feat: add webhook plugin and implement connection save (#3051)
8e06e4cb is described below
commit 8e06e4cb364aa6783ac735133f3efc48441a259b
Author: likyh <[email protected]>
AuthorDate: Thu Sep 15 10:50:46 2022 +0800
feat: add webhook plugin and implement connection save (#3051)
* feat: add webhook plugin and implement connection save
* fix: fix a typo
* fix: fix for ci
* feat: add swag for webhook
* fix: fix for error pr
* fix: fix for review
Co-authored-by: linyh <[email protected]>
---
.../plugin/plugin_main_complete_plugin.go-template | 2 +-
plugins/helper/api_async_client.go | 2 +-
plugins/webhook/api/cicd_pipeline.go | 58 ++++++++++
plugins/webhook/api/connection.go | 121 +++++++++++++++++++++
.../webhook/api/init.go | 38 +++----
plugins/webhook/api/issue.go | 93 ++++++++++++++++
plugins/webhook/impl/impl.go | 76 +++++++++++++
.../webhook/models/connection.go | 29 ++---
.../migrationscripts/20220908_add_init_tables.go | 34 +++---
.../models/migrationscripts/archived/connection.go | 30 ++---
.../webhook/models/migrationscripts/register.go | 28 +----
.../webhook/webhook.go | 24 ++--
12 files changed, 419 insertions(+), 116 deletions(-)
diff --git a/generator/template/plugin/plugin_main_complete_plugin.go-template
b/generator/template/plugin/plugin_main_complete_plugin.go-template
index ee2d4a56..3d325964 100644
--- a/generator/template/plugin/plugin_main_complete_plugin.go-template
+++ b/generator/template/plugin/plugin_main_complete_plugin.go-template
@@ -18,7 +18,7 @@ limitations under the License.
package main
import (
- "github.com/apache/incubator-devlake/plugins/{{ .PluginName }}/impl"
+ "github.com/apache/incubator-devlake/plugins/{{ .pluginName }}/impl"
"github.com/apache/incubator-devlake/runner"
"github.com/spf13/cobra"
)
diff --git a/plugins/helper/api_async_client.go
b/plugins/helper/api_async_client.go
index 094fdfdf..90119c02 100644
--- a/plugins/helper/api_async_client.go
+++ b/plugins/helper/api_async_client.go
@@ -169,7 +169,7 @@ func (apiClient *ApiAsyncClient) DoAsync(
}
if err == ErrIgnoreAndContinue {
// make sure defer func got be executed
- err = nil //nolint:all
+ err = nil //nolint
return nil
}
diff --git a/plugins/webhook/api/cicd_pipeline.go
b/plugins/webhook/api/cicd_pipeline.go
new file mode 100644
index 00000000..c15cf63c
--- /dev/null
+++ b/plugins/webhook/api/cicd_pipeline.go
@@ -0,0 +1,58 @@
+/*
+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 (
+ "github.com/apache/incubator-devlake/errors"
+ "github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/plugins/webhook/models"
+ "net/http"
+ "time"
+)
+
+type WebhookPipelineRequest struct {
+ Id string `validate:"required"`
+ Result string `validate:"oneof=SUCCESS FAILURE ABORT"`
+ Status string `validate:"oneof=IN_PROGRESS DONE"`
+ Type string `validate:"oneof=CI CD CI/CD"`
+ CreatedDate time.Time `mapstructure:"created_date"
validate:"required"`
+ FinishedDate *time.Time `mapstructure:"finished_date"`
+
+ Repo string `validate:"required"`
+ Branch string
+ CommitSha string `mapstructure:"commit_sha"`
+}
+
+// PostCicdPipeline
+// @Summary create pipeline by webhook
+// @Description Create pipeline by webhook, example:
{"id":"A123123","result":"one of SUCCESS/FAILURE/ABORT","status":"one of
IN_PROGRESS/DONE","type":"CI/CD","created_date":"2020-01-01T12:00:00+00:00","finished_date":"2020-01-01T12:59:59+00:00","repo":"devlake","branch":"main","commit_sha":"015e3d3b480e417aede5a1293bd61de9b0fd051d"}
+// @Tags plugins/webhook
+// @Param body body WebhookPipelineRequest true "json body"
+// @Success 200
+// @Failure 400 {string} errcode.Error "Bad Request"
+// @Failure 500 {string} errcode.Error "Internal Error"
+// @Router /plugins/webhook/:connectionId/cicd_pipelines [POST]
+func PostCicdPipeline(input *core.ApiResourceInput) (*core.ApiResourceOutput,
errors.Error) {
+ connection := &models.WebhookConnection{}
+ err := connectionHelper.First(connection, input.Params)
+ if err != nil {
+ return nil, err
+ }
+ // TODO save pipeline
+ return &core.ApiResourceOutput{Body: nil, Status: http.StatusOK}, nil
+}
diff --git a/plugins/webhook/api/connection.go
b/plugins/webhook/api/connection.go
new file mode 100644
index 00000000..48afd592
--- /dev/null
+++ b/plugins/webhook/api/connection.go
@@ -0,0 +1,121 @@
+/*
+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 (
+ "fmt"
+ "github.com/apache/incubator-devlake/errors"
+ "github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/plugins/webhook/models"
+ "net/http"
+)
+
+// PostConnections
+// @Summary create webhook connection
+// @Description Create webhook connection, example: {"name":"Webhook data
connection name"}
+// @Tags plugins/webhook
+// @Param body body models.WebhookConnection true "json body"
+// @Success 200 {object} models.WebhookConnection
+// @Failure 400 {string} errcode.Error "Bad Request"
+// @Failure 500 {string} errcode.Error "Internal Error"
+// @Router /plugins/webhook/connections [POST]
+func PostConnections(input *core.ApiResourceInput) (*core.ApiResourceOutput,
errors.Error) {
+ // update from request and save to database
+ connection := &models.WebhookConnection{}
+ err := connectionHelper.Create(connection, input)
+ if err != nil {
+ return nil, err
+ }
+ return &core.ApiResourceOutput{Body: connection, Status:
http.StatusOK}, nil
+}
+
+// PatchConnection
+// @Summary patch webhook connection
+// @Description Patch webhook connection
+// @Tags plugins/webhook
+// @Param body body models.WebhookConnection true "json body"
+// @Success 200 {object} models.WebhookConnection
+// @Failure 400 {string} errcode.Error "Bad Request"
+// @Failure 500 {string} errcode.Error "Internal Error"
+// @Router /plugins/webhook/connections/{connectionId} [PATCH]
+func PatchConnection(input *core.ApiResourceInput) (*core.ApiResourceOutput,
errors.Error) {
+ connection := &models.WebhookConnection{}
+ err := connectionHelper.Patch(connection, input)
+ if err != nil {
+ return nil, err
+ }
+ return &core.ApiResourceOutput{Body: connection}, nil
+}
+
+// DeleteConnection
+// @Summary delete a webhook connection
+// @Description Delete a webhook connection
+// @Tags plugins/webhook
+// @Success 200 {object} models.WebhookConnection
+// @Failure 400 {string} errcode.Error "Bad Request"
+// @Failure 500 {string} errcode.Error "Internal Error"
+// @Router /plugins/webhook/connections/{connectionId} [DELETE]
+func DeleteConnection(input *core.ApiResourceInput) (*core.ApiResourceOutput,
errors.Error) {
+ connection := &models.WebhookConnection{}
+ err := connectionHelper.First(connection, input.Params)
+ if err != nil {
+ return nil, err
+ }
+ err = connectionHelper.Delete(connection)
+ return &core.ApiResourceOutput{Body: connection}, err
+}
+
+// ListConnections
+// @Summary get all webhook connections
+// @Description Get all webhook connections
+// @Tags plugins/webhook
+// @Success 200 {object} []models.WebhookConnection
+// @Failure 400 {string} errcode.Error "Bad Request"
+// @Failure 500 {string} errcode.Error "Internal Error"
+// @Router /plugins/webhook/connections [GET]
+func ListConnections(input *core.ApiResourceInput) (*core.ApiResourceOutput,
errors.Error) {
+ var connections []models.WebhookConnection
+ err := connectionHelper.List(&connections)
+ if err != nil {
+ return nil, err
+ }
+ return &core.ApiResourceOutput{Body: connections, Status:
http.StatusOK}, nil
+}
+
+type WebhookConnectionResponse struct {
+ models.WebhookConnection
+ IssuesEndpoint string
+ CicdPipelineEndpoint string
+}
+
+// GetConnection
+// @Summary get webhook connection detail
+// @Description Get webhook connection detail
+// @Tags plugins/webhook
+// @Success 200 {object} WebhookConnectionResponse
+// @Failure 400 {string} errcode.Error "Bad Request"
+// @Failure 500 {string} errcode.Error "Internal Error"
+// @Router /plugins/webhook/connections/{connectionId} [GET]
+func GetConnection(input *core.ApiResourceInput) (*core.ApiResourceOutput,
errors.Error) {
+ connection := &models.WebhookConnection{}
+ err := connectionHelper.First(connection, input.Params)
+ response := &WebhookConnectionResponse{WebhookConnection: *connection}
+ response.IssuesEndpoint = fmt.Sprintf(`/plugins/webhook/%d/issues`,
connection.ID)
+ response.CicdPipelineEndpoint =
fmt.Sprintf(`/plugins/webhook/%d/cicd_pipeline`, connection.ID)
+ return &core.ApiResourceOutput{Body: response}, err
+}
diff --git a/generator/template/plugin/plugin_main_complete_plugin.go-template
b/plugins/webhook/api/init.go
similarity index 51%
copy from generator/template/plugin/plugin_main_complete_plugin.go-template
copy to plugins/webhook/api/init.go
index ee2d4a56..6774e148 100644
--- a/generator/template/plugin/plugin_main_complete_plugin.go-template
+++ b/plugins/webhook/api/init.go
@@ -15,29 +15,25 @@ See the License for the specific language governing
permissions and
limitations under the License.
*/
-package main
+package api
import (
- "github.com/apache/incubator-devlake/plugins/{{ .PluginName }}/impl"
- "github.com/apache/incubator-devlake/runner"
- "github.com/spf13/cobra"
+ "github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/plugins/helper"
+ "github.com/go-playground/validator/v10"
+ "github.com/spf13/viper"
+ "gorm.io/gorm"
)
-// Export a variable named PluginEntry for Framework to search and load
-var PluginEntry impl.{{ .PluginName }} //nolint
-
-// standalone mode for debugging
-func main() {
- cmd := &cobra.Command{Use: "{{ .pluginName }}"}
-
- // TODO add your cmd flag if necessary
- // yourFlag := cmd.Flags().IntP("yourFlag", "y", 8, "TODO add
description here")
- // _ = cmd.MarkFlagRequired("yourFlag")
-
- cmd.Run = func(cmd *cobra.Command, args []string) {
- runner.DirectRun(cmd, args, PluginEntry, map[string]interface{}{
- // TODO add more custom params here
- })
- }
- runner.RunCmd(cmd)
+var vld *validator.Validate
+var connectionHelper *helper.ConnectionApiHelper
+var basicRes core.BasicRes
+
+func Init(config *viper.Viper, logger core.Logger, database *gorm.DB) {
+ basicRes = helper.NewDefaultBasicRes(config, logger, database)
+ vld = validator.New()
+ connectionHelper = helper.NewConnectionHelper(
+ basicRes,
+ vld,
+ )
}
diff --git a/plugins/webhook/api/issue.go b/plugins/webhook/api/issue.go
new file mode 100644
index 00000000..93cfea37
--- /dev/null
+++ b/plugins/webhook/api/issue.go
@@ -0,0 +1,93 @@
+/*
+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 (
+ "github.com/apache/incubator-devlake/errors"
+ "github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/plugins/webhook/models"
+ "net/http"
+ "time"
+)
+
+type WebhookIssueRequest struct {
+ BoardKey string `mapstructure:"board_key"
validate:"required"`
+ Url string `mapstructure:"url"`
+ IssueKey string `mapstructure:"issue_key"
validate:"required"`
+ Title string `mapstructure:"title"
validate:"required"`
+ Description string `mapstructure:"description"`
+ EpicKey string `mapstructure:"epic_key"`
+ Type string `mapstructure:"type"`
+ Status string `mapstructure:"status"
validate:"oneof=TODO DONE IN_PROGRESS"`
+ OriginalStatus string `mapstructure:"original_status"
validate:"required"`
+ StoryPoint int64 `mapstructure:"story_point"`
+ ResolutionDate *time.Time `mapstructure:"resolution_date"`
+ CreatedDate *time.Time `mapstructure:"created_date"
validate:"required"`
+ UpdatedDate *time.Time `mapstructure:"updated_date"`
+ LeadTimeMinutes uint `mapstructure:"lead_time_minutes"`
+ ParentIssueKey string `mapstructure:"parent_issue_key"`
+ Priority string `mapstructure:"priority"`
+ OriginalEstimateMinutes int64
`mapstructure:"original_estimate_minutes"`
+ TimeSpentMinutes int64 `mapstructure:"time_spent_minutes"`
+ TimeRemainingMinutes int64
`mapstructure:"time_remaining_minutes"`
+ CreatorId string `mapstructure:"creator_id"`
+ CreatorName string `mapstructure:"creator_name"`
+ AssigneeId string `mapstructure:"assignee_id"`
+ AssigneeName string `mapstructure:"assignee_name"`
+ Severity string `mapstructure:"severity"`
+ Component string `mapstructure:"component"`
+ //IconURL string
+ //DeploymentId string
+}
+
+// PostIssue
+// @Summary receive a record as defined and save it
+// @Description receive a record as follow and save it, example:
{"board_key":"DLK","url":"","issue_key":"DLK-1234","title":"a feature from
DLK","description":"","epic_key":"","type":"BUG","status":"TODO","original_status":"created","story_point":0,"resolution_date":null,"created_date":"2020-01-01T12:00:00+00:00","updated_date":null,"lead_time_minutes":0,"parent_issue_key":"DLK-1200","priority":"","original_estimate_minutes":0,"time_spent_minutes":0,"time_remaining_minutes":0,"creator_id
[...]
+// @Tags plugins/webhook
+// @Param body body WebhookPipelineRequest true "json body"
+// @Success 200 {string} noResponse ""
+// @Failure 400 {string} errcode.Error "Bad Request"
+// @Failure 500 {string} errcode.Error "Internal Error"
+// @Router /plugins/webhook/:connectionId/issues [POST]
+func PostIssue(input *core.ApiResourceInput) (*core.ApiResourceOutput,
errors.Error) {
+ connection := &models.WebhookConnection{}
+ err := connectionHelper.First(connection, input.Params)
+ if err != nil {
+ return nil, err
+ }
+ // TODO save issue
+ return &core.ApiResourceOutput{Body: nil, Status: http.StatusOK}, nil
+}
+
+// CloseIssue
+// @Summary set issue's status to DONE
+// @Description set issue's status to DONE
+// @Tags plugins/webhook
+// @Success 200 {string} noResponse ""
+// @Failure 400 {string} errcode.Error "Bad Request"
+// @Failure 500 {string} errcode.Error "Internal Error"
+// @Router /plugins/webhook/:connectionId/issue/:boardKey/:issueId/close [POST]
+func CloseIssue(input *core.ApiResourceInput) (*core.ApiResourceOutput,
errors.Error) {
+ connection := &models.WebhookConnection{}
+ err := connectionHelper.First(connection, input.Params)
+ if err != nil {
+ return nil, err
+ }
+ // TODO close issue
+ return &core.ApiResourceOutput{Body: nil, Status: http.StatusOK}, nil
+}
diff --git a/plugins/webhook/impl/impl.go b/plugins/webhook/impl/impl.go
new file mode 100644
index 00000000..670423e3
--- /dev/null
+++ b/plugins/webhook/impl/impl.go
@@ -0,0 +1,76 @@
+/*
+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 (
+ "github.com/apache/incubator-devlake/errors"
+ "github.com/apache/incubator-devlake/migration"
+ "github.com/apache/incubator-devlake/plugins/core"
+ "github.com/apache/incubator-devlake/plugins/webhook/api"
+
"github.com/apache/incubator-devlake/plugins/webhook/models/migrationscripts"
+ "github.com/spf13/viper"
+ "gorm.io/gorm"
+)
+
+// make sure interface is implemented
+var _ core.PluginMeta = (*Webhook)(nil)
+var _ core.PluginInit = (*Webhook)(nil)
+var _ core.PluginApi = (*Webhook)(nil)
+
+type Webhook struct{}
+
+func (plugin Webhook) Description() string {
+ return "collect some Webhook data"
+}
+
+func (plugin Webhook) Init(config *viper.Viper, logger core.Logger, db
*gorm.DB) errors.Error {
+ api.Init(config, logger, db)
+ return nil
+}
+
+// PkgPath information lost when compiled as plugin(.so)
+func (plugin Webhook) RootPkgPath() string {
+ return "github.com/apache/incubator-devlake/plugins/webhook"
+}
+
+func (plugin Webhook) MigrationScripts() []migration.Script {
+ return migrationscripts.All()
+}
+
+func (plugin Webhook) ApiResources()
map[string]map[string]core.ApiResourceHandler {
+ return map[string]map[string]core.ApiResourceHandler{
+ "connections": {
+ "POST": api.PostConnections,
+ "GET": api.ListConnections,
+ },
+ "connections/:connectionId": {
+ "GET": api.GetConnection,
+ "PATCH": api.PatchConnection,
+ "DELETE": api.DeleteConnection,
+ },
+ ":connectionId/cicd_pipelines": {
+ "POST": api.PostCicdPipeline,
+ },
+ ":connectionId/issues": {
+ "POST": api.PostIssue,
+ },
+ ":connectionId/issue/:boardKey/:issueId/close": {
+ "POST": api.CloseIssue,
+ },
+ }
+}
diff --git a/generator/template/plugin/plugin_main_complete_plugin.go-template
b/plugins/webhook/models/connection.go
similarity index 51%
copy from generator/template/plugin/plugin_main_complete_plugin.go-template
copy to plugins/webhook/models/connection.go
index ee2d4a56..b554c822 100644
--- a/generator/template/plugin/plugin_main_complete_plugin.go-template
+++ b/plugins/webhook/models/connection.go
@@ -15,29 +15,14 @@ See the License for the specific language governing
permissions and
limitations under the License.
*/
-package main
+package models
-import (
- "github.com/apache/incubator-devlake/plugins/{{ .PluginName }}/impl"
- "github.com/apache/incubator-devlake/runner"
- "github.com/spf13/cobra"
-)
+import "github.com/apache/incubator-devlake/plugins/helper"
-// Export a variable named PluginEntry for Framework to search and load
-var PluginEntry impl.{{ .PluginName }} //nolint
-
-// standalone mode for debugging
-func main() {
- cmd := &cobra.Command{Use: "{{ .pluginName }}"}
-
- // TODO add your cmd flag if necessary
- // yourFlag := cmd.Flags().IntP("yourFlag", "y", 8, "TODO add
description here")
- // _ = cmd.MarkFlagRequired("yourFlag")
+type WebhookConnection struct {
+ helper.BaseConnection `mapstructure:",squash"`
+}
- cmd.Run = func(cmd *cobra.Command, args []string) {
- runner.DirectRun(cmd, args, PluginEntry, map[string]interface{}{
- // TODO add more custom params here
- })
- }
- runner.RunCmd(cmd)
+func (WebhookConnection) TableName() string {
+ return "_tool_webhook_connections"
}
diff --git a/generator/template/plugin/plugin_main_complete_plugin.go-template
b/plugins/webhook/models/migrationscripts/20220908_add_init_tables.go
similarity index 51%
copy from generator/template/plugin/plugin_main_complete_plugin.go-template
copy to plugins/webhook/models/migrationscripts/20220908_add_init_tables.go
index ee2d4a56..c8bf323b 100644
--- a/generator/template/plugin/plugin_main_complete_plugin.go-template
+++ b/plugins/webhook/models/migrationscripts/20220908_add_init_tables.go
@@ -15,29 +15,27 @@ See the License for the specific language governing
permissions and
limitations under the License.
*/
-package main
+package migrationscripts
import (
- "github.com/apache/incubator-devlake/plugins/{{ .PluginName }}/impl"
- "github.com/apache/incubator-devlake/runner"
- "github.com/spf13/cobra"
+ "context"
+ "github.com/apache/incubator-devlake/errors"
+
"github.com/apache/incubator-devlake/plugins/webhook/models/migrationscripts/archived"
+ "gorm.io/gorm"
)
-// Export a variable named PluginEntry for Framework to search and load
-var PluginEntry impl.{{ .PluginName }} //nolint
+type addInitTables struct{}
-// standalone mode for debugging
-func main() {
- cmd := &cobra.Command{Use: "{{ .pluginName }}"}
+func (u *addInitTables) Up(ctx context.Context, db *gorm.DB) errors.Error {
+ return errors.Convert(db.Migrator().AutoMigrate(
+ &archived.WebhookConnection{},
+ ))
+}
- // TODO add your cmd flag if necessary
- // yourFlag := cmd.Flags().IntP("yourFlag", "y", 8, "TODO add
description here")
- // _ = cmd.MarkFlagRequired("yourFlag")
+func (*addInitTables) Version() uint64 {
+ return 20220908000001
+}
- cmd.Run = func(cmd *cobra.Command, args []string) {
- runner.DirectRun(cmd, args, PluginEntry, map[string]interface{}{
- // TODO add more custom params here
- })
- }
- runner.RunCmd(cmd)
+func (*addInitTables) Name() string {
+ return "webhook init schemas"
}
diff --git a/generator/template/plugin/plugin_main_complete_plugin.go-template
b/plugins/webhook/models/migrationscripts/archived/connection.go
similarity index 51%
copy from generator/template/plugin/plugin_main_complete_plugin.go-template
copy to plugins/webhook/models/migrationscripts/archived/connection.go
index ee2d4a56..796f931c 100644
--- a/generator/template/plugin/plugin_main_complete_plugin.go-template
+++ b/plugins/webhook/models/migrationscripts/archived/connection.go
@@ -15,29 +15,21 @@ See the License for the specific language governing
permissions and
limitations under the License.
*/
-package main
+package archived
import (
- "github.com/apache/incubator-devlake/plugins/{{ .PluginName }}/impl"
- "github.com/apache/incubator-devlake/runner"
- "github.com/spf13/cobra"
+ "github.com/apache/incubator-devlake/models/migrationscripts/archived"
)
-// Export a variable named PluginEntry for Framework to search and load
-var PluginEntry impl.{{ .PluginName }} //nolint
-
-// standalone mode for debugging
-func main() {
- cmd := &cobra.Command{Use: "{{ .pluginName }}"}
+type BaseConnection struct {
+ Name string `gorm:"type:varchar(100);uniqueIndex" json:"name"
validate:"required"`
+ archived.Model
+}
- // TODO add your cmd flag if necessary
- // yourFlag := cmd.Flags().IntP("yourFlag", "y", 8, "TODO add
description here")
- // _ = cmd.MarkFlagRequired("yourFlag")
+type WebhookConnection struct {
+ BaseConnection `mapstructure:",squash"`
+}
- cmd.Run = func(cmd *cobra.Command, args []string) {
- runner.DirectRun(cmd, args, PluginEntry, map[string]interface{}{
- // TODO add more custom params here
- })
- }
- runner.RunCmd(cmd)
+func (WebhookConnection) TableName() string {
+ return "_tool_webhook_connections"
}
diff --git a/generator/template/plugin/plugin_main_complete_plugin.go-template
b/plugins/webhook/models/migrationscripts/register.go
similarity index 51%
copy from generator/template/plugin/plugin_main_complete_plugin.go-template
copy to plugins/webhook/models/migrationscripts/register.go
index ee2d4a56..92e20c01 100644
--- a/generator/template/plugin/plugin_main_complete_plugin.go-template
+++ b/plugins/webhook/models/migrationscripts/register.go
@@ -15,29 +15,13 @@ See the License for the specific language governing
permissions and
limitations under the License.
*/
-package main
+package migrationscripts
-import (
- "github.com/apache/incubator-devlake/plugins/{{ .PluginName }}/impl"
- "github.com/apache/incubator-devlake/runner"
- "github.com/spf13/cobra"
-)
+import "github.com/apache/incubator-devlake/migration"
-// Export a variable named PluginEntry for Framework to search and load
-var PluginEntry impl.{{ .PluginName }} //nolint
-
-// standalone mode for debugging
-func main() {
- cmd := &cobra.Command{Use: "{{ .pluginName }}"}
-
- // TODO add your cmd flag if necessary
- // yourFlag := cmd.Flags().IntP("yourFlag", "y", 8, "TODO add
description here")
- // _ = cmd.MarkFlagRequired("yourFlag")
-
- cmd.Run = func(cmd *cobra.Command, args []string) {
- runner.DirectRun(cmd, args, PluginEntry, map[string]interface{}{
- // TODO add more custom params here
- })
+// All return all the migration scripts
+func All() []migration.Script {
+ return []migration.Script{
+ new(addInitTables),
}
- runner.RunCmd(cmd)
}
diff --git a/generator/template/plugin/plugin_main_complete_plugin.go-template
b/plugins/webhook/webhook.go
similarity index 61%
copy from generator/template/plugin/plugin_main_complete_plugin.go-template
copy to plugins/webhook/webhook.go
index ee2d4a56..cf282e3a 100644
--- a/generator/template/plugin/plugin_main_complete_plugin.go-template
+++ b/plugins/webhook/webhook.go
@@ -18,26 +18,26 @@ limitations under the License.
package main
import (
- "github.com/apache/incubator-devlake/plugins/{{ .PluginName }}/impl"
- "github.com/apache/incubator-devlake/runner"
"github.com/spf13/cobra"
+
+ "github.com/apache/incubator-devlake/plugins/webhook/impl"
)
-// Export a variable named PluginEntry for Framework to search and load
-var PluginEntry impl.{{ .PluginName }} //nolint
+// PluginEntry is a variable named for Framework to search and load
+var PluginEntry impl.Webhook //nolint
// standalone mode for debugging
func main() {
- cmd := &cobra.Command{Use: "{{ .pluginName }}"}
+ cmd := &cobra.Command{Use: "webhook"}
- // TODO add your cmd flag if necessary
- // yourFlag := cmd.Flags().IntP("yourFlag", "y", 8, "TODO add
description here")
- // _ = cmd.MarkFlagRequired("yourFlag")
+ //connectionId := cmd.Flags().Uint64P("connection", "c", 0, "webhook
connection id")
+ //_ = cmd.MarkFlagRequired("connection")
cmd.Run = func(cmd *cobra.Command, args []string) {
- runner.DirectRun(cmd, args, PluginEntry, map[string]interface{}{
- // TODO add more custom params here
- })
+ println(`webhook plugin can only run in API`)
+ }
+ err := cmd.Execute()
+ if err != nil {
+ panic(err)
}
- runner.RunCmd(cmd)
}