You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ly...@apache.org on 2024/07/31 09:46:29 UTC

(incubator-devlake) branch add-new-fields-to-incidents created (now 7de9d3396)

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

lynwee pushed a change to branch add-new-fields-to-incidents
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


      at 7de9d3396 Merge branch 'main' into add-new-fields-to-incidents

This branch includes the following new commits:

     new 351af9d74 feat(domainlayer): add new fiels to incidents
     new 7de9d3396 Merge branch 'main' into add-new-fields-to-incidents

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(incubator-devlake) 02/02: Merge branch 'main' into add-new-fields-to-incidents

Posted by ly...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lynwee pushed a commit to branch add-new-fields-to-incidents
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 7de9d339641c069ccd3318e682756b6c5f1ef235
Merge: 351af9d74 3a31a7561
Author: d4x1 <15...@qq.com>
AuthorDate: Wed Jul 31 17:46:14 2024 +0800

    Merge branch 'main' into add-new-fields-to-incidents

 .../domainlayer/crossdomain/project_pr_metric.go   |  8 +++
 ...0240731_add_datefields_to_project_pr_metrics.go | 58 ++++++++++++++++++++++
 backend/core/models/migrationscripts/register.go   |  1 +
 .../e2e/change_lead_time/project_pr_metrics.csv    | 14 +++---
 .../dora/tasks/change_lead_time_calculator.go      |  6 +++
 backend/plugins/pagerduty/api/blueprint_v200.go    |  4 +-
 backend/plugins/trello/api/blueprint_v200.go       |  6 +--
 7 files changed, 85 insertions(+), 12 deletions(-)

diff --cc backend/core/models/migrationscripts/register.go
index f4bb46cb5,1856571d9..8da02dbbb
--- a/backend/core/models/migrationscripts/register.go
+++ b/backend/core/models/migrationscripts/register.go
@@@ -128,6 -128,6 +128,7 @@@ func All() []plugin.MigrationScript 
  		new(addChangesToPr),
  		new(addMergedByToPr),
  		new(addIsDraftToPr),
 +		new(addTableScopeIdToIncident),
+ 		new(addDateFieldsToProjectPrMetric),
  	}
  }


(incubator-devlake) 01/02: feat(domainlayer): add new fiels to incidents

Posted by ly...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lynwee pushed a commit to branch add-new-fields-to-incidents
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 351af9d74c784387fe376ec7800bb469ea25f59f
Author: d4x1 <15...@qq.com>
AuthorDate: Wed Jul 31 17:45:30 2024 +0800

    feat(domainlayer): add new fiels to incidents
---
 .../core/models/domainlayer/code/pull_request.go   |  2 +
 backend/core/models/domainlayer/ticket/incident.go |  2 +
 backend/core/models/domainlayer/ticket/issue.go    |  4 +-
 .../20240725_add_table_scope_id_to_incidents.go    | 49 ++++++++++++++++++++++
 backend/core/models/migrationscripts/register.go   |  1 +
 .../dora/tasks/incident_from_issue_generator.go    | 15 ++++---
 6 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/backend/core/models/domainlayer/code/pull_request.go b/backend/core/models/domainlayer/code/pull_request.go
index 6649d6508..3610bc5d2 100644
--- a/backend/core/models/domainlayer/code/pull_request.go
+++ b/backend/core/models/domainlayer/code/pull_request.go
@@ -102,6 +102,8 @@ func (pr PullRequest) ToIncident() (*ticket.Incident, error) {
 		Urgency:                 "",
 		Component:               pr.Component,
 		OriginalProject:         "",
+		ScopeId:                 pr.BaseRepoId,
+		Table:                   "repos",
 	}
 
 	if pr.MergedDate != nil {
diff --git a/backend/core/models/domainlayer/ticket/incident.go b/backend/core/models/domainlayer/ticket/incident.go
index b565cd3b9..781b59072 100644
--- a/backend/core/models/domainlayer/ticket/incident.go
+++ b/backend/core/models/domainlayer/ticket/incident.go
@@ -48,6 +48,8 @@ type Incident struct {
 	Urgency                 string `gorm:"type:varchar(255)"`
 	Component               string `gorm:"type:varchar(255)"`
 	OriginalProject         string `gorm:"type:varchar(255)"`
+	Table                   string `gorm:"index:idx_table_scope_id;type:varchar(255)"`
+	ScopeId                 string `gorm:"index:idx_table_scope_id;type:varchar(255)"`
 }
 
 func (Incident) TableName() string {
diff --git a/backend/core/models/domainlayer/ticket/issue.go b/backend/core/models/domainlayer/ticket/issue.go
index 25039e8df..715bee648 100644
--- a/backend/core/models/domainlayer/ticket/issue.go
+++ b/backend/core/models/domainlayer/ticket/issue.go
@@ -118,7 +118,7 @@ func (issue Issue) ToIncidentAssignee() (*IncidentAssignee, error) {
 	}, nil
 }
 
-func (issue Issue) ToIncident() (*Incident, error) {
+func (issue Issue) ToIncident(boardId string) (*Incident, error) {
 	incident := &Incident{
 		DomainEntity:            issue.DomainEntity,
 		Url:                     issue.Url,
@@ -142,6 +142,8 @@ func (issue Issue) ToIncident() (*Incident, error) {
 		Urgency:                 issue.Urgency,
 		Component:               issue.Component,
 		OriginalProject:         issue.OriginalProject,
+		ScopeId:                 boardId,
+		Table:                   "boards",
 	}
 	return incident, nil
 }
diff --git a/backend/core/models/migrationscripts/20240725_add_table_scope_id_to_incidents.go b/backend/core/models/migrationscripts/20240725_add_table_scope_id_to_incidents.go
new file mode 100644
index 000000000..a9d4b7f34
--- /dev/null
+++ b/backend/core/models/migrationscripts/20240725_add_table_scope_id_to_incidents.go
@@ -0,0 +1,49 @@
+/*
+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 migrationscripts
+
+import (
+	"github.com/apache/incubator-devlake/core/context"
+	"github.com/apache/incubator-devlake/core/errors"
+	"github.com/apache/incubator-devlake/core/plugin"
+)
+
+var _ plugin.MigrationScript = (*addTableScopeIdToIncident)(nil)
+
+type incident20240731 struct {
+	Table   string `gorm:"index:idx_table_scope_id;type:varchar(255)"`
+	ScopeId string `gorm:"index:idx_table_scope_id;type:varchar(255)"`
+}
+
+func (incident20240731) TableName() string {
+	return "incidents"
+}
+
+type addTableScopeIdToIncident struct{}
+
+func (*addTableScopeIdToIncident) Up(basicRes context.BasicRes) errors.Error {
+	return basicRes.GetDal().AutoMigrate(&incident20240731{})
+}
+
+func (*addTableScopeIdToIncident) Version() uint64 {
+	return 20240731180000
+}
+
+func (*addTableScopeIdToIncident) Name() string {
+	return "add table and scope_id to incidents"
+}
diff --git a/backend/core/models/migrationscripts/register.go b/backend/core/models/migrationscripts/register.go
index b2df0bd08..f4bb46cb5 100644
--- a/backend/core/models/migrationscripts/register.go
+++ b/backend/core/models/migrationscripts/register.go
@@ -128,5 +128,6 @@ func All() []plugin.MigrationScript {
 		new(addChangesToPr),
 		new(addMergedByToPr),
 		new(addIsDraftToPr),
+		new(addTableScopeIdToIncident),
 	}
 }
diff --git a/backend/plugins/dora/tasks/incident_from_issue_generator.go b/backend/plugins/dora/tasks/incident_from_issue_generator.go
index c84c890b4..bb3610898 100644
--- a/backend/plugins/dora/tasks/incident_from_issue_generator.go
+++ b/backend/plugins/dora/tasks/incident_from_issue_generator.go
@@ -37,6 +37,11 @@ var IssuesToIncidentsMeta = plugin.SubTaskMeta{
 	DomainTypes:      []string{plugin.DOMAIN_TYPE_TICKET},
 }
 
+type issueWithBoardId struct {
+	ticket.Issue
+	BoardId string
+}
+
 func ConvertIssuesToIncidents(taskCtx plugin.SubTaskContext) errors.Error {
 	db := taskCtx.GetDal()
 	data := taskCtx.GetData().(*DoraTaskData)
@@ -78,7 +83,7 @@ func ConvertIssuesToIncidents(taskCtx plugin.SubTaskContext) errors.Error {
 
 	// select all issues belongs to the board
 	clauses := []dal.Clause{
-		dal.Select("i.*"),
+		dal.Select("i.*, bi.board_id as board_id"),
 		dal.From(`issues i`),
 		dal.Join(`left join board_issues bi on bi.issue_id = i.id`),
 		dal.Join(`left join project_mapping pm on pm.row_id = bi.board_id`),
@@ -101,15 +106,15 @@ func ConvertIssuesToIncidents(taskCtx plugin.SubTaskContext) errors.Error {
 			},
 			Table: ticket.Issue{}.TableName(),
 		},
-		InputRowType: reflect.TypeOf(ticket.Issue{}),
+		InputRowType: reflect.TypeOf(issueWithBoardId{}),
 		Input:        cursor,
 		Convert: func(inputRow interface{}) ([]interface{}, errors.Error) {
-			issue := inputRow.(*ticket.Issue)
-			incident, err := issue.ToIncident()
+			issueWithBoardId := inputRow.(*issueWithBoardId)
+			incident, err := issueWithBoardId.ToIncident(issueWithBoardId.BoardId)
 			if err != nil {
 				return nil, errors.Convert(err)
 			}
-			incidentAssignees, err := generateIncidentAssigneeFromIssue(db, taskCtx.GetLogger(), issue)
+			incidentAssignees, err := generateIncidentAssigneeFromIssue(db, taskCtx.GetLogger(), &issueWithBoardId.Issue)
 			if err != nil {
 				return nil, errors.Convert(err)
 			}