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 3a8f5d240 fix: opsgenie scope without project (#6829)
3a8f5d240 is described below
commit 3a8f5d2402f1815b7682e93486a2c7ef95c452c8
Author: abeizn <[email protected]>
AuthorDate: Wed Jan 17 17:00:07 2024 +0800
fix: opsgenie scope without project (#6829)
* fix: opsgenie scope without project
* fix: remove log
---
backend/plugins/opsgenie/api/blueprint_v200.go | 84 ++++++++++++--------------
backend/plugins/opsgenie/api/init.go | 17 ------
backend/plugins/opsgenie/api/scope.go | 12 ++--
backend/plugins/opsgenie/models/service.go | 10 +--
4 files changed, 47 insertions(+), 76 deletions(-)
diff --git a/backend/plugins/opsgenie/api/blueprint_v200.go
b/backend/plugins/opsgenie/api/blueprint_v200.go
index d2b53b2fa..3f691ddba 100644
--- a/backend/plugins/opsgenie/api/blueprint_v200.go
+++ b/backend/plugins/opsgenie/api/blueprint_v200.go
@@ -25,9 +25,9 @@ import (
"github.com/apache/incubator-devlake/core/models/domainlayer/ticket"
"github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/core/utils"
- "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+ helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+ "github.com/apache/incubator-devlake/helpers/srvhelper"
"github.com/apache/incubator-devlake/plugins/opsgenie/models"
- "github.com/apache/incubator-devlake/plugins/opsgenie/tasks"
)
func MakeDataSourcePipelinePlanV200(
@@ -41,13 +41,16 @@ func MakeDataSourcePipelinePlanV200(
if err != nil {
return nil, nil, err
}
+ scopeDetails, err := dsHelper.ScopeSrv.MapScopeDetails(connectionId,
bpScopes)
+ if err != nil {
+ return nil, nil, err
+ }
- plan := make(coreModels.PipelinePlan, len(bpScopes))
- plan, err = makeDataSourcePipelinePlanV200(subtaskMetas, plan,
bpScopes, connection)
+ plan, err := makeDataSourcePipelinePlanV200(subtaskMetas, scopeDetails,
connection)
if err != nil {
return nil, nil, err
}
- scopes, err := makeScopesV200(bpScopes, connection)
+ scopes, err := makeScopesV200(scopeDetails, connection)
if err != nil {
return nil, nil, err
}
@@ -57,63 +60,56 @@ func MakeDataSourcePipelinePlanV200(
func makeDataSourcePipelinePlanV200(
subtaskMetas []plugin.SubTaskMeta,
- plan coreModels.PipelinePlan,
- bpScopes []*coreModels.BlueprintScope,
+ scopeDetails []*srvhelper.ScopeDetail[models.Service,
models.OpsenieScopeConfig],
connection *models.OpsgenieConnection,
) (coreModels.PipelinePlan, errors.Error) {
- for i, bpScope := range bpScopes {
- // get board and scope config from db
- service, scopeConfig, err :=
scopeHelper.DbHelper().GetScopeAndConfig(connection.ID, bpScope.ScopeId)
- if err != nil {
- return nil, err
- }
- // construct task options for opsgenie
- op := &tasks.OpsgenieOptions{
- ConnectionId: service.ConnectionId,
- ServiceId: service.Id,
- ServiceName: service.Name,
+ plan := make(coreModels.PipelinePlan, len(scopeDetails))
+ for i, scopeDetail := range scopeDetails {
+ stage := plan[i]
+ if stage == nil {
+ stage = coreModels.PipelineStage{}
}
- var options map[string]any
- options, err = tasks.EncodeTaskOptions(op)
- if err != nil {
- return nil, err
- }
- var subtasks []string
- subtasks, err = api.MakePipelinePlanSubtasks(subtaskMetas,
scopeConfig.Entities)
+ scope, scopeConfig := scopeDetail.Scope, scopeDetail.ScopeConfig
+ // construct task options for opsgenie
+ task, err := helper.MakePipelinePlanTask(
+ "opsgenie",
+ subtaskMetas,
+ scopeConfig.Entities,
+ OpsgenieTaskOptions{
+ ConnectionId: scope.ConnectionId,
+ ServiceId: scope.Id,
+ ServiceName: scope.Name,
+ },
+ )
if err != nil {
return nil, err
}
- stage := []*coreModels.PipelineTask{
- {
- Plugin: "opsgenie",
- Subtasks: subtasks,
- Options: options,
- },
- }
+
+ stage = append(stage, task)
plan[i] = stage
}
+
return plan, nil
}
-func makeScopesV200(bpScopes []*coreModels.BlueprintScope, connection
*models.OpsgenieConnection) ([]plugin.Scope, errors.Error) {
+func makeScopesV200(
+ scopeDetails []*srvhelper.ScopeDetail[models.Service,
models.OpsenieScopeConfig],
+ connection *models.OpsgenieConnection) ([]plugin.Scope, errors.Error) {
scopes := make([]plugin.Scope, 0)
- for _, bpScope := range bpScopes {
- // get board and scope config from db
- service, scopeConfig, err :=
scopeHelper.DbHelper().GetScopeAndConfig(connection.ID, bpScope.ScopeId)
- if err != nil {
- return nil, err
- }
- // add board to scopes
+ for _, scopeDetail := range scopeDetails {
+ opService, scopeConfig := scopeDetail.Scope,
scopeDetail.ScopeConfig
+ // add service to scopes
if utils.StringsContains(scopeConfig.Entities,
plugin.DOMAIN_TYPE_TICKET) {
- scopeTicket := &ticket.Board{
+ domainBoard := &ticket.Board{
DomainEntity: domainlayer.DomainEntity{
- Id:
didgen.NewDomainIdGenerator(&models.Service{}).Generate(connection.ID,
service.Id),
+ Id:
didgen.NewDomainIdGenerator(&models.Service{}).Generate(opService.ConnectionId,
opService.Id),
},
- Name: service.Name,
+ Name: opService.Name,
}
- scopes = append(scopes, scopeTicket)
+ scopes = append(scopes, domainBoard)
}
}
+
return scopes, nil
}
diff --git a/backend/plugins/opsgenie/api/init.go
b/backend/plugins/opsgenie/api/init.go
index fdcb4ea10..3641eab40 100644
--- a/backend/plugins/opsgenie/api/init.go
+++ b/backend/plugins/opsgenie/api/init.go
@@ -27,8 +27,6 @@ import (
var vld *validator.Validate
var connectionHelper *api.ConnectionApiHelper
-
-var scopeHelper *api.ScopeApiHelper[models.OpsgenieConnection, models.Service,
models.OpsenieScopeConfig]
var dsHelper *api.DsHelper[models.OpsgenieConnection, models.Service,
models.OpsenieScopeConfig]
var basicRes context.BasicRes
@@ -41,21 +39,6 @@ func Init(br context.BasicRes, p plugin.PluginMeta) {
vld,
p.Name(),
)
- params := &api.ReflectionParameters{
- ScopeIdFieldName: "Id",
- ScopeIdColumnName: "id",
- RawScopeParamName: "ScopeId",
- SearchScopeParamName: "name",
- }
- scopeHelper = api.NewScopeHelper[models.OpsgenieConnection,
models.Service, models.OpsenieScopeConfig](
- basicRes,
- vld,
- connectionHelper,
- api.NewScopeDatabaseHelperImpl[models.OpsgenieConnection,
models.Service, models.OpsenieScopeConfig](
- basicRes, connectionHelper, params),
- params,
- &api.ScopeHelperOptions{},
- )
dsHelper = api.NewDataSourceHelper[
models.OpsgenieConnection, models.Service,
models.OpsenieScopeConfig,
diff --git a/backend/plugins/opsgenie/api/scope.go
b/backend/plugins/opsgenie/api/scope.go
index 071d6d361..4e0cb2f76 100644
--- a/backend/plugins/opsgenie/api/scope.go
+++ b/backend/plugins/opsgenie/api/scope.go
@@ -26,7 +26,7 @@ import (
type ScopeRes struct {
models.Service
- api.ScopeResDoc[any]
+ api.ScopeResDoc[models.Service]
}
type ScopeReq api.ScopeReq[models.Service]
@@ -43,7 +43,7 @@ type ScopeReq api.ScopeReq[models.Service]
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/opsgenie/connections/{connectionId}/scopes [PUT]
func PutScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
errors.Error) {
- return scopeHelper.Put(input)
+ return dsHelper.ScopeApi.PutMultiple(input)
}
// UpdateScope patch to opsgenie service
@@ -59,7 +59,7 @@ func PutScope(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, errors
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/opsgenie/connections/{connectionId}/scopes/{serviceId}
[PATCH]
func UpdateScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
errors.Error) {
- return scopeHelper.Update(input)
+ return dsHelper.ScopeApi.Patch(input)
}
// GetScopeList get Opsgenie repos
@@ -76,7 +76,7 @@ func UpdateScope(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, err
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/opsgenie/connections/{connectionId}/scopes/ [GET]
func GetScopeList(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
errors.Error) {
- return scopeHelper.GetScopeList(input)
+ return dsHelper.ScopeApi.GetPage(input)
}
// GetScope get one Opsgenie service
@@ -91,7 +91,7 @@ func GetScopeList(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, er
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/opsgenie/connections/{connectionId}/scopes/{serviceId}
[GET]
func GetScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
errors.Error) {
- return scopeHelper.GetScope(input)
+ return dsHelper.ScopeApi.GetScopeDetail(input)
}
// DeleteScope delete plugin data associated with the scope and optionally the
scope itself
@@ -107,5 +107,5 @@ func GetScope(input *plugin.ApiResourceInput)
(*plugin.ApiResourceOutput, errors
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/opsgenie/connections/{connectionId}/scopes/{serviceId}
[DELETE]
func DeleteScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
errors.Error) {
- return scopeHelper.Delete(input)
+ return dsHelper.ScopeApi.Delete(input)
}
diff --git a/backend/plugins/opsgenie/models/service.go
b/backend/plugins/opsgenie/models/service.go
index 71fd68420..7c7b62db5 100644
--- a/backend/plugins/opsgenie/models/service.go
+++ b/backend/plugins/opsgenie/models/service.go
@@ -36,17 +36,9 @@ type Service struct {
}
func (s Service) ScopeId() string {
- return s.Name
+ return s.Id
}
-// func (s Service) ScopeConnectionId() uint64 {
-// return s.ConnectionId
-// }
-
-// func (s Service) ScopeScopeConfigId() uint64 {
-// return 0
-// }
-
func (s Service) ScopeName() string {
return s.Name
}