You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by zh...@apache.org on 2022/08/16 13:37:01 UTC

[incubator-devlake] branch main updated: docs(plugins): add fake api to describe specific-plugin blueprint and pipeline (#2739)

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

zhangliang2022 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 28aa097b docs(plugins): add fake api to describe specific-plugin blueprint and pipeline (#2739)
28aa097b is described below

commit 28aa097b002902096483f00fee11d5afc736e2c1
Author: Warren Chen <yi...@merico.dev>
AuthorDate: Tue Aug 16 21:36:56 2022 +0800

    docs(plugins): add fake api to describe specific-plugin blueprint and pipeline (#2739)
    
    relate to #2734 #2735
---
 api/blueprints/blueprints.go      |  2 +-
 api/pipelines/pipelines.go        |  8 -------
 models/blueprint.go               | 16 ++++++-------
 models/pipeline.go                |  2 +-
 plugins/jenkins/api/connection.go | 43 +++++++++++++++++++++++++++++++++
 plugins/jira/api/connection.go    | 49 ++++++++++++++++++++++++++++++++++++++
 plugins/tapd/api/connection.go    | 50 +++++++++++++++++++++++++++++++++++++++
 7 files changed, 152 insertions(+), 18 deletions(-)

diff --git a/api/blueprints/blueprints.go b/api/blueprints/blueprints.go
index dc1bd9ed..b6e9c612 100644
--- a/api/blueprints/blueprints.go
+++ b/api/blueprints/blueprints.go
@@ -31,7 +31,7 @@ import (
 // @Description post blueprints
 // @Tags framework/blueprints
 // @Accept application/json
-// @Param blueprint body string true "json"
+// @Param blueprint body models.Blueprint true "json"
 // @Success 200  {object} models.Blueprint
 // @Failure 400  {string} errcode.Error "Bad Request"
 // @Failure 500  {string} errcode.Error "Internel Error"
diff --git a/api/pipelines/pipelines.go b/api/pipelines/pipelines.go
index d5a5ab2c..c5cc259c 100644
--- a/api/pipelines/pipelines.go
+++ b/api/pipelines/pipelines.go
@@ -41,14 +41,6 @@ POST /pipelines
 */
 // @Summary Create and run a new pipeline
 // @Description Create and run a new pipeline
-// @Description RETURN SAMPLE
-// @Description {
-// @Description 	"name": "name-of-pipeline",
-// @Description 	"tasks": [
-// @Description 		[ {"plugin": "gitlab", ...}, {"plugin": "jira"} ],
-// @Description 		[ {"plugin": "github", ...}],
-// @Description 	]
-// @Description }
 // @Tags framework/pipelines
 // @Accept application/json
 // @Param pipeline body models.NewPipeline true "json"
diff --git a/models/blueprint.go b/models/blueprint.go
index 2913a8a0..d99ab575 100644
--- a/models/blueprint.go
+++ b/models/blueprint.go
@@ -30,14 +30,14 @@ const (
 )
 
 type Blueprint struct {
-	Name       string          `json:"name" validate:"required"`
-	Mode       string          `json:"mode" gorm:"varchar(20)" validate:"required,oneof=NORMAL ADVANCED"`
-	Plan       json.RawMessage `json:"plan"`
-	Enable     bool            `json:"enable"`
-	CronConfig string          `json:"cronConfig"`
-	IsManual   bool            `json:"isManual"`
-	Settings   json.RawMessage `json:"settings"`
-	common.Model
+	Name         string          `json:"name" validate:"required"`
+	Mode         string          `json:"mode" gorm:"varchar(20)" validate:"required,oneof=NORMAL ADVANCED"`
+	Plan         json.RawMessage `json:"plan"`
+	Enable       bool            `json:"enable"`
+	CronConfig   string          `json:"cronConfig" format:"* * * * *" example:"0 0 * * 1; please check https://crontab.guru/ for detail"`
+	IsManual     bool            `json:"isManual"`
+	Settings     json.RawMessage `json:"settings" swaggertype:"array,string" example:"please check api: /blueprints/<PLUGIN_NAME>/blueprint-setting"`
+	common.Model `swaggerignore:"true"`
 }
 
 func (Blueprint) TableName() string {
diff --git a/models/pipeline.go b/models/pipeline.go
index 3f8d882d..f8d16e76 100644
--- a/models/pipeline.go
+++ b/models/pipeline.go
@@ -45,7 +45,7 @@ type Pipeline struct {
 // to be executed concurrently, while each set is to be executed sequentially.
 type NewPipeline struct {
 	Name        string            `json:"name"`
-	Plan        core.PipelinePlan `json:"plan"`
+	Plan        core.PipelinePlan `json:"plan" swaggertype:"array,string" example:"please check api /pipelines/<PLUGIN_NAME>/pipeline-plan"`
 	BlueprintId uint64
 }
 
diff --git a/plugins/jenkins/api/connection.go b/plugins/jenkins/api/connection.go
index 62b0e874..edd72385 100644
--- a/plugins/jenkins/api/connection.go
+++ b/plugins/jenkins/api/connection.go
@@ -163,3 +163,46 @@ func GetConnection(input *core.ApiResourceInput) (*core.ApiResourceOutput, error
 	err := connectionHelper.First(connection, input.Params)
 	return &core.ApiResourceOutput{Body: connection}, err
 }
+
+// @Summary blueprints setting for jenkins
+// @Description blueprint setting for jenkins
+// @Tags plugins/jenkins
+// @Accept application/json
+// @Param blueprint body JenkinsBlueprintSetting true "json"
+// @Router /blueprints/jenkins/blueprint-setting [post]
+func PostJenkinsBluePrint(input *core.ApiResourceInput) (*core.ApiResourceOutput, error) {
+	blueprint := &JenkinsBlueprintSetting{}
+	return &core.ApiResourceOutput{Body: blueprint, Status: http.StatusOK}, nil
+}
+
+type JenkinsBlueprintSetting []struct {
+	Version     string `json:"version"`
+	Connections []struct {
+		Plugin       string `json:"plugin"`
+		ConnectionID int    `json:"connectionId"`
+		Scope        []struct {
+			Options struct {
+			} `json:"options"`
+			Entities []string `json:"entities"`
+		} `json:"scope"`
+	} `json:"connections"`
+}
+
+// @Summary pipelines plan for jenkins
+// @Description pipelines plan for jenkins
+// @Tags plugins/jenkins
+// @Accept application/json
+// @Param blueprint body JenkinsPipelinePlan true "json"
+// @Router /pipelines/jenkins/pipeline-plan [post]
+func PostJenkinsPipeline(input *core.ApiResourceInput) (*core.ApiResourceOutput, error) {
+	blueprint := &JenkinsPipelinePlan{}
+	return &core.ApiResourceOutput{Body: blueprint, Status: http.StatusOK}, nil
+}
+
+type JenkinsPipelinePlan [][]struct {
+	Plugin   string   `json:"plugin"`
+	Subtasks []string `json:"subtasks"`
+	Options  struct {
+		ConnectionID int `json:"connectionId"`
+	} `json:"options"`
+}
diff --git a/plugins/jira/api/connection.go b/plugins/jira/api/connection.go
index 0289d50d..4b4f09c0 100644
--- a/plugins/jira/api/connection.go
+++ b/plugins/jira/api/connection.go
@@ -20,6 +20,7 @@ package api
 import (
 	"context"
 	"fmt"
+	"github.com/apache/incubator-devlake/plugins/jira/tasks"
 	"net/http"
 	"net/url"
 	"strings"
@@ -212,3 +213,51 @@ func GetConnection(input *core.ApiResourceInput) (*core.ApiResourceOutput, error
 	err := connectionHelper.First(connection, input.Params)
 	return &core.ApiResourceOutput{Body: connection}, err
 }
+
+// @Summary blueprints setting for jira
+// @Description blueprint setting for jira
+// @Tags plugins/jira
+// @Accept application/json
+// @Param blueprint-setting body JiraBlueprintSetting true "json"
+// @Router /blueprints/jira/blueprint-setting [post]
+func PostJiraBlueprintSetting(input *core.ApiResourceInput) (*core.ApiResourceOutput, error) {
+	blueprint := &JiraBlueprintSetting{}
+	return &core.ApiResourceOutput{Body: blueprint, Status: http.StatusOK}, nil
+}
+
+type JiraBlueprintSetting []struct {
+	Version     string `json:"version"`
+	Connections []struct {
+		Plugin       string `json:"plugin"`
+		ConnectionID int    `json:"connectionId"`
+		Scope        []struct {
+			Transformation tasks.TransformationRules `json:"transformation"`
+			Options        struct {
+				BoardId uint64 `json:"boardId"`
+				Since   string `json:"since"`
+			} `json:"options"`
+			Entities []string `json:"entities"`
+		} `json:"scope"`
+	} `json:"connections"`
+}
+
+// @Summary pipelines plan for jira
+// @Description pipelines plan for jira
+// @Tags plugins/jira
+// @Accept application/json
+// @Param pipeline-plan body JiraPipelinePlan true "json"
+// @Router /pipelines/jira/pipeline-plan [post]
+func PostJiraPipeline(input *core.ApiResourceInput) (*core.ApiResourceOutput, error) {
+	blueprint := &JiraPipelinePlan{}
+	return &core.ApiResourceOutput{Body: blueprint, Status: http.StatusOK}, nil
+}
+
+type JiraPipelinePlan [][]struct {
+	Plugin   string   `json:"plugin"`
+	Subtasks []string `json:"subtasks"`
+	Options  struct {
+		BoardID             int                       `json:"boardId"`
+		ConnectionID        int                       `json:"connectionId"`
+		TransformationRules tasks.TransformationRules `json:"transformationRules"`
+	} `json:"options"`
+}
diff --git a/plugins/tapd/api/connection.go b/plugins/tapd/api/connection.go
index 4b1f3609..a8a2ce4c 100644
--- a/plugins/tapd/api/connection.go
+++ b/plugins/tapd/api/connection.go
@@ -166,3 +166,53 @@ func GetConnection(input *core.ApiResourceInput) (*core.ApiResourceOutput, error
 	err := connectionHelper.First(connection, input.Params)
 	return &core.ApiResourceOutput{Body: connection}, err
 }
+
+// @Summary blueprints setting for tapd
+// @Description blueprint setting for tapd
+// @Tags plugins/tapd
+// @Accept application/json
+// @Param blueprint body TapdBlueprintSetting true "json"
+// @Router /blueprints/tapd/blueprint-setting [post]
+func PostTapdBlueprintSetting(input *core.ApiResourceInput) (*core.ApiResourceOutput, error) {
+	blueprint := &TapdBlueprintSetting{}
+	return &core.ApiResourceOutput{Body: blueprint, Status: http.StatusOK}, nil
+}
+
+type TapdBlueprintSetting []struct {
+	Version     string `json:"version"`
+	Connections []struct {
+		Plugin       string `json:"plugin"`
+		ConnectionID int    `json:"connectionId"`
+		Scope        []struct {
+			Options struct {
+				WorkspaceId uint64   `mapstruct:"workspaceId"`
+				CompanyId   uint64   `mapstruct:"companyId"`
+				Tasks       []string `mapstruct:"tasks,omitempty"`
+				Since       string
+			} `json:"options"`
+			Entities []string `json:"entities"`
+		} `json:"scope"`
+	} `json:"connections"`
+}
+
+// @Summary pipelines plan for tapd
+// @Description pipelines plan for tapd
+// @Tags plugins/tapd
+// @Accept application/json
+// @Param blueprint body TapdPipelinePlan true "json"
+// @Router /pipelines/tapd/pipeline-plan [post]
+func PostTapdPipelinePlan(input *core.ApiResourceInput) (*core.ApiResourceOutput, error) {
+	blueprint := &TapdPipelinePlan{}
+	return &core.ApiResourceOutput{Body: blueprint, Status: http.StatusOK}, nil
+}
+
+type TapdPipelinePlan [][]struct {
+	Plugin   string   `json:"plugin"`
+	Subtasks []string `json:"subtasks"`
+	Options  struct {
+		WorkspaceId uint64   `mapstruct:"workspaceId"`
+		CompanyId   uint64   `mapstruct:"companyId"`
+		Tasks       []string `mapstruct:"tasks,omitempty"`
+		Since       string
+	} `json:"options"`
+}