From 5fdba2ac89efff9c872382c9c6fa0f16b4547850 Mon Sep 17 00:00:00 2001 From: d4x1 <1507509064@qq.com> Date: Thu, 25 Jul 2024 12:48:43 +0800 Subject: [PATCH 1/2] feat(dora): add new option `DisableIssueToIncidentGenerator` --- backend/plugins/dora/impl/impl.go | 2 - .../tasks/incident_from_issue_generator.go | 3 + .../incident_from_pull_request_generator.go | 59 ------------------- backend/plugins/dora/tasks/task_data.go | 3 +- 4 files changed, 5 insertions(+), 62 deletions(-) delete mode 100644 backend/plugins/dora/tasks/incident_from_pull_request_generator.go diff --git a/backend/plugins/dora/impl/impl.go b/backend/plugins/dora/impl/impl.go index 530a9b486cc..a0764a96272 100644 --- a/backend/plugins/dora/impl/impl.go +++ b/backend/plugins/dora/impl/impl.go @@ -96,7 +96,6 @@ func (p Dora) SubTaskMetas() []plugin.SubTaskMeta { tasks.CalculateChangeLeadTimeMeta, tasks.ConnectIncidentToDeploymentMeta, tasks.IssuesToIncidentsMeta, - tasks.PullRequestToIncidentsMeta, } } @@ -163,7 +162,6 @@ func (p Dora) MakeMetricPluginPipelinePlanV200(projectName string, options json. "calculateChangeLeadTime", "ConnectIncidentToDeployment", tasks.IssuesToIncidentsMeta.Name, - tasks.PullRequestToIncidentsMeta.Name, }, }, }, diff --git a/backend/plugins/dora/tasks/incident_from_issue_generator.go b/backend/plugins/dora/tasks/incident_from_issue_generator.go index 21ffbd36423..c84c890b462 100644 --- a/backend/plugins/dora/tasks/incident_from_issue_generator.go +++ b/backend/plugins/dora/tasks/incident_from_issue_generator.go @@ -40,6 +40,9 @@ var IssuesToIncidentsMeta = plugin.SubTaskMeta{ func ConvertIssuesToIncidents(taskCtx plugin.SubTaskContext) errors.Error { db := taskCtx.GetDal() data := taskCtx.GetData().(*DoraTaskData) + if data.DisableIssueToIncidentGenerator { + return nil + } // clear previous incidents and incident_assignees from the project deleteIncidentsSql := ` DELETE diff --git a/backend/plugins/dora/tasks/incident_from_pull_request_generator.go b/backend/plugins/dora/tasks/incident_from_pull_request_generator.go deleted file mode 100644 index 029aaa777f7..00000000000 --- a/backend/plugins/dora/tasks/incident_from_pull_request_generator.go +++ /dev/null @@ -1,59 +0,0 @@ -/* -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 tasks - -import ( - "github.com/apache/incubator-devlake/core/errors" - "github.com/apache/incubator-devlake/core/plugin" -) - -var PullRequestToIncidentsMeta = plugin.SubTaskMeta{ - Name: "ConvertPullRequestToIncidents", - EntryPoint: ConvertPullRequestToIncidents, - EnabledByDefault: true, - Description: "Connect pull_request to incident", - DomainTypes: []string{plugin.DOMAIN_TYPE_TICKET, plugin.DOMAIN_TYPE_CICD, plugin.DOMAIN_TYPE_CROSS}, -} - -func ConvertPullRequestToIncidents(taskCtx plugin.SubTaskContext) errors.Error { - // TODO - return nil -} - -// lint:ignore U1000 -//func generateIncidentAssigneeFromPullRequest(db dal.Dal, logger log.Logger, pullRequest *code.PullRequest) ([]*ticket.IncidentAssignee, error) { -// if pullRequest == nil { -// return nil, goerrors.New("pull request is nil") -// } -// var pullRequestAssignees []*code.PullRequestAssignee -// if err := db.All(&pullRequestAssignees, dal.Where("pull_request_id = ?", pullRequest.Id)); err != nil { -// logger.Error(err, "Failed to fetch pull request assignees") -// return nil, err -// } -// -// var incidentAssignees []*ticket.IncidentAssignee -// for _, pullRequestAssignee := range pullRequestAssignees { -// incidentAssignees = append(incidentAssignees, &ticket.IncidentAssignee{ -// IncidentId: pullRequestAssignee.PullRequestId, -// AssigneeId: pullRequestAssignee.AssigneeId, -// AssigneeName: pullRequestAssignee.Name, -// NoPKModel: common.NewNoPKModel(), -// }) -// } -// return incidentAssignees, nil -//} diff --git a/backend/plugins/dora/tasks/task_data.go b/backend/plugins/dora/tasks/task_data.go index 0af005446d4..3beaf339f6b 100644 --- a/backend/plugins/dora/tasks/task_data.go +++ b/backend/plugins/dora/tasks/task_data.go @@ -34,7 +34,8 @@ type DoraOptions struct { } type DoraTaskData struct { - Options *DoraOptions + Options *DoraOptions + DisableIssueToIncidentGenerator bool } func DecodeAndValidateTaskOptions(options map[string]interface{}) (*DoraOptions, errors.Error) { From a2df7dce8602b7cf638add9167589c6fccd4bebb Mon Sep 17 00:00:00 2001 From: d4x1 <1507509064@qq.com> Date: Thu, 25 Jul 2024 13:16:51 +0800 Subject: [PATCH 2/2] fix(dora): fix test --- backend/plugins/dora/impl/impl_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/plugins/dora/impl/impl_test.go b/backend/plugins/dora/impl/impl_test.go index af9cc43f4b8..54cc7d5c41c 100644 --- a/backend/plugins/dora/impl/impl_test.go +++ b/backend/plugins/dora/impl/impl_test.go @@ -63,7 +63,6 @@ func TestMakeMetricPluginPipelinePlanV200(t *testing.T) { "calculateChangeLeadTime", "ConnectIncidentToDeployment", tasks.IssuesToIncidentsMeta.Name, - tasks.PullRequestToIncidentsMeta.Name, }, Options: map[string]interface{}{"projectName": projectName}, },