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

hez 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 88d7dfea8 [fix-5233]: Pagerduty MTTR computation fix (#5229)
88d7dfea8 is described below

commit 88d7dfea80034650993b64b6df86722e7731fc4b
Author: Keon Amini <[email protected]>
AuthorDate: Thu May 18 17:06:43 2023 -0500

    [fix-5233]: Pagerduty MTTR computation fix (#5229)
    
    * fix: Pagerduty now writes to the boards tables to correctly compute MTTR 
for DORA
    
    * fix: remove cicd scope
---
 backend/plugins/pagerduty/impl/impl.go             |  1 +
 .../plugins/pagerduty/tasks/incidents_converter.go |  6 ++
 .../plugins/pagerduty/tasks/service_converter.go   | 81 ++++++++++++++++++++++
 3 files changed, 88 insertions(+)

diff --git a/backend/plugins/pagerduty/impl/impl.go 
b/backend/plugins/pagerduty/impl/impl.go
index 01b11285b..e3f438299 100644
--- a/backend/plugins/pagerduty/impl/impl.go
+++ b/backend/plugins/pagerduty/impl/impl.go
@@ -57,6 +57,7 @@ func (p PagerDuty) SubTaskMetas() []plugin.SubTaskMeta {
                tasks.CollectIncidentsMeta,
                tasks.ExtractIncidentsMeta,
                tasks.ConvertIncidentsMeta,
+               tasks.ConvertServicesMeta,
        }
 }
 
diff --git a/backend/plugins/pagerduty/tasks/incidents_converter.go 
b/backend/plugins/pagerduty/tasks/incidents_converter.go
index dda345389..3bb7e9fd8 100644
--- a/backend/plugins/pagerduty/tasks/incidents_converter.go
+++ b/backend/plugins/pagerduty/tasks/incidents_converter.go
@@ -66,6 +66,7 @@ func ConvertIncidents(taskCtx plugin.SubTaskContext) 
errors.Error {
        defer cursor.Close()
        seenIncidents := map[int]*IncidentWithUser{}
        idGen := didgen.NewDomainIdGenerator(&models.Incident{})
+       serviceIdGen := didgen.NewDomainIdGenerator(&models.Service{})
        converter, err := api.NewDataConverter(api.DataConverterArgs{
                RawDataSubTaskArgs: api.RawDataSubTaskArgs{
                        Ctx:     taskCtx,
@@ -105,7 +106,12 @@ func ConvertIncidents(taskCtx plugin.SubTaskContext) 
errors.Error {
                                AssigneeName:    user.Name,
                        }
                        seenIncidents[incident.Number] = combined
+                       boardIssue := &ticket.BoardIssue{
+                               BoardId: 
serviceIdGen.Generate(data.Options.ConnectionId, data.Options.ServiceId),
+                               IssueId: domainIssue.Id,
+                       }
                        return []interface{}{
+                               boardIssue,
                                domainIssue,
                        }, nil
                },
diff --git a/backend/plugins/pagerduty/tasks/service_converter.go 
b/backend/plugins/pagerduty/tasks/service_converter.go
new file mode 100644
index 000000000..4a6fca4c5
--- /dev/null
+++ b/backend/plugins/pagerduty/tasks/service_converter.go
@@ -0,0 +1,81 @@
+/*
+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/dal"
+       "github.com/apache/incubator-devlake/core/errors"
+       "github.com/apache/incubator-devlake/core/models/domainlayer"
+       "github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
+       "github.com/apache/incubator-devlake/core/models/domainlayer/ticket"
+       "github.com/apache/incubator-devlake/core/plugin"
+       helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
+       "github.com/apache/incubator-devlake/plugins/pagerduty/models"
+       "reflect"
+)
+
+func ConvertServices(taskCtx plugin.SubTaskContext) errors.Error {
+       db := taskCtx.GetDal()
+       data := taskCtx.GetData().(*PagerDutyTaskData)
+       rawDataSubTaskArgs := &helper.RawDataSubTaskArgs{
+               Ctx:     taskCtx,
+               Options: data.Options,
+               Table:   "pagerduty_services",
+       }
+       clauses := []dal.Clause{
+               dal.Select("services.*"),
+               dal.From("_tool_pagerduty_services services"),
+               dal.Where("id = ? and connection_id = ?", 
data.Options.ServiceId, data.Options.ConnectionId),
+       }
+       cursor, err := db.Cursor(clauses...)
+       if err != nil {
+               return err
+       }
+       defer cursor.Close()
+
+       converter, err := helper.NewDataConverter(helper.DataConverterArgs{
+               RawDataSubTaskArgs: *rawDataSubTaskArgs,
+               InputRowType:       reflect.TypeOf(models.Service{}),
+               Input:              cursor,
+               Convert: func(inputRow interface{}) ([]interface{}, 
errors.Error) {
+                       service := inputRow.(*models.Service)
+                       domainBoard := &ticket.Board{
+                               DomainEntity: domainlayer.DomainEntity{
+                                       Id: 
didgen.NewDomainIdGenerator(service).Generate(service.ConnectionId, service.Id),
+                               },
+                               Name: service.Name,
+                               Url:  service.Url,
+                       }
+                       return []interface{}{
+                               domainBoard,
+                       }, nil
+               },
+       })
+       if err != nil {
+               return err
+       }
+       return converter.Execute()
+}
+
+var ConvertServicesMeta = plugin.SubTaskMeta{
+       Name:             "convertServices",
+       EntryPoint:       ConvertServices,
+       EnabledByDefault: true,
+       Description:      "Convert PagerDuty services",
+       DomainTypes:      []string{plugin.DOMAIN_TYPE_TICKET},
+}

Reply via email to