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 10:36:42 UTC
(incubator-devlake) branch cp10 created (now 179e2019f)
This is an automated email from the ASF dual-hosted git repository.
lynwee pushed a change to branch cp10
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
at 179e2019f fix(webhook): fix compile errors
This branch includes the following new commits:
new 3c3b122d5 feat(domainlayer): add new fiels to incidents
new 179e2019f fix(webhook): fix compile errors
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: fix(webhook): fix compile errors
Posted by ly...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lynwee pushed a commit to branch cp10
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit 179e2019fe6e847d2b36336c8fa3d89dbf30a662
Author: d4x1 <15...@qq.com>
AuthorDate: Wed Jul 31 17:48:04 2024 +0800
fix(webhook): fix compile errors
---
backend/plugins/webhook/api/issues.go | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/backend/plugins/webhook/api/issues.go b/backend/plugins/webhook/api/issues.go
index a73b60e67..7ee19e062 100644
--- a/backend/plugins/webhook/api/issues.go
+++ b/backend/plugins/webhook/api/issues.go
@@ -64,8 +64,8 @@ type WebhookIssueRequest struct {
//DeploymentId string
}
-func saveIncidentRelatedRecordsFromIssue(db dal.Transaction, logger log.Logger, issue *ticket.Issue) error {
- incident, err := issue.ToIncident()
+func saveIncidentRelatedRecordsFromIssue(db dal.Transaction, logger log.Logger, issueBoarId string, issue *ticket.Issue) error {
+ incident, err := issue.ToIncident(issueBoarId)
if err != nil {
return err
}
@@ -185,7 +185,7 @@ func PostIssue(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, error
return nil, err
}
if domainIssue.IsIncident() {
- if err := saveIncidentRelatedRecordsFromIssue(tx, logger, domainIssue); err != nil {
+ if err := saveIncidentRelatedRecordsFromIssue(tx, logger, domainBoardId, domainIssue); err != nil {
logger.Error(err, "failed to save incident related records")
return nil, errors.Convert(err)
}
(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 cp10
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
commit 3c3b122d5c89041be94802d486294e244e642e57
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 997ab2bbb..3cf9f2a8a 100644
--- a/backend/core/models/domainlayer/code/pull_request.go
+++ b/backend/core/models/domainlayer/code/pull_request.go
@@ -101,6 +101,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 eeaa83c70..2c06d3b7f 100644
--- a/backend/core/models/migrationscripts/register.go
+++ b/backend/core/models/migrationscripts/register.go
@@ -129,5 +129,6 @@ func All() []plugin.MigrationScript {
new(initIncidentRelatedTables),
new(renameProjectIssueMetrics),
new(addDateFieldsToProjectPrMetric),
+ 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)
}