You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2023/12/20 11:31:41 UTC

(incubator-devlake) branch fix-types updated: fix: type trans rules

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

abeizn pushed a commit to branch fix-types
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/fix-types by this push:
     new c02315db1 fix: type trans rules
c02315db1 is described below

commit c02315db13d786b818758aa715f9bbc908fa2e25
Author: abeizn <zi...@merico.dev>
AuthorDate: Wed Dec 20 19:31:30 2023 +0800

    fix: type trans rules
---
 backend/plugins/gitee/tasks/issue_extractor.go     | 45 +++++------------
 backend/plugins/gitee/tasks/pr_extractor.go        | 15 ++----
 backend/plugins/github/tasks/issue_extractor.go    | 25 ++++------
 backend/plugins/github/tasks/pr_extractor.go       | 15 ++----
 .../github_graphql/tasks/issue_extractor.go        | 25 ++++------
 .../plugins/github_graphql/tasks/pr_extractor.go   | 18 +++----
 backend/plugins/gitlab/tasks/issue_extractor.go    | 58 ++++++++--------------
 .../plugins/gitlab/tasks/mr_detail_extractor.go    | 15 ++----
 backend/plugins/gitlab/tasks/mr_extractor.go       | 15 ++----
 9 files changed, 74 insertions(+), 157 deletions(-)

diff --git a/backend/plugins/gitee/tasks/issue_extractor.go b/backend/plugins/gitee/tasks/issue_extractor.go
index 175fd7a5a..5f20ec8fa 100644
--- a/backend/plugins/gitee/tasks/issue_extractor.go
+++ b/backend/plugins/gitee/tasks/issue_extractor.go
@@ -177,43 +177,22 @@ func ExtractApiIssues(taskCtx plugin.SubTaskContext) errors.Error {
 					IssueId:      giteeIssue.GiteeId,
 					LabelName:    label.Name,
 				})
-				if issueSeverityRegex != nil {
-					groups := issueSeverityRegex.FindStringSubmatch(label.Name)
-					if len(groups) > 0 {
-						giteeIssue.Severity = groups[0]
-					}
+				if issueSeverityRegex != nil && issueSeverityRegex.MatchString(label.Name) {
+					giteeIssue.Severity = label.Name
 				}
-
-				if issueComponentRegex != nil {
-					groups := issueComponentRegex.FindStringSubmatch(label.Name)
-					if len(groups) > 0 {
-						giteeIssue.Component = groups[0]
-					}
-				}
-
-				if issuePriorityRegex != nil {
-					groups := issuePriorityRegex.FindStringSubmatch(label.Name)
-					if len(groups) > 0 {
-						giteeIssue.Priority = groups[0]
-					}
+				if issueComponentRegex != nil && issueComponentRegex.MatchString(label.Name) {
+					giteeIssue.Component = label.Name
 				}
-
-				if issueTypeBugRegex != nil {
-					if ok := issueTypeBugRegex.MatchString(label.Name); ok {
-						giteeIssue.Type = ticket.BUG
-					}
-				}
-
-				if issueTypeRequirementRegex != nil {
-					if ok := issueTypeRequirementRegex.MatchString(label.Name); ok {
-						giteeIssue.Type = ticket.REQUIREMENT
-					}
+				if issuePriorityRegex != nil && issuePriorityRegex.MatchString(label.Name) {
+					giteeIssue.Priority = label.Name
 				}
 
-				if issueTypeIncidentRegex != nil {
-					if ok := issueTypeIncidentRegex.MatchString(label.Name); ok {
-						giteeIssue.Type = ticket.INCIDENT
-					}
+				if issueTypeRequirementRegex != nil && issueTypeRequirementRegex.MatchString(label.Name) {
+					giteeIssue.Type = ticket.REQUIREMENT
+				} else if issueTypeBugRegex != nil && issueTypeBugRegex.MatchString(label.Name) {
+					giteeIssue.Type = ticket.BUG
+				} else if issueTypeIncidentRegex != nil && issueTypeIncidentRegex.MatchString(label.Name) {
+					giteeIssue.Type = ticket.INCIDENT
 				}
 			}
 			results = append(results, giteeIssue)
diff --git a/backend/plugins/gitee/tasks/pr_extractor.go b/backend/plugins/gitee/tasks/pr_extractor.go
index 462fe2e5d..94b84c271 100644
--- a/backend/plugins/gitee/tasks/pr_extractor.go
+++ b/backend/plugins/gitee/tasks/pr_extractor.go
@@ -124,19 +124,12 @@ func ExtractApiPullRequests(taskCtx plugin.SubTaskContext) errors.Error {
 					LabelName:    label.Name,
 				})
 				// if pr.Type has not been set and prType is set in .env, process the below
-				if labelTypeRegex != nil {
-					groups := labelTypeRegex.FindStringSubmatch(label.Name)
-					if len(groups) > 0 {
-						giteePr.Type = groups[0]
-					}
+				if labelTypeRegex != nil && labelTypeRegex.MatchString(label.Name) {
+					giteePr.Type = label.Name
 				}
-
 				// if pr.Component has not been set and prComponent is set in .env, process
-				if labelComponentRegex != nil {
-					groups := labelComponentRegex.FindStringSubmatch(label.Name)
-					if len(groups) > 0 {
-						giteePr.Component = groups[0]
-					}
+				if labelComponentRegex != nil && labelComponentRegex.MatchString(label.Name) {
+					giteePr.Component = label.Name
 				}
 			}
 			results = append(results, giteePr)
diff --git a/backend/plugins/github/tasks/issue_extractor.go b/backend/plugins/github/tasks/issue_extractor.go
index 0801302fb..974ad397d 100644
--- a/backend/plugins/github/tasks/issue_extractor.go
+++ b/backend/plugins/github/tasks/issue_extractor.go
@@ -210,32 +210,25 @@ func convertGithubLabels(issueRegexes *IssueRegexes, issue *IssuesResponse, gith
 			IssueId:      githubIssue.GithubId,
 			LabelName:    label.Name,
 		})
-		joinedLabels = append(joinedLabels, label.Name)
 
-		if issueRegexes.SeverityRegex != nil {
-			groups := issueRegexes.SeverityRegex.FindStringSubmatch(label.Name)
-			if len(groups) > 0 {
-				githubIssue.Severity = groups[0]
-			}
+		if issueRegexes.SeverityRegex != nil && issueRegexes.SeverityRegex.MatchString(label.Name) {
+			githubIssue.Severity = label.Name
 		}
-		if issueRegexes.ComponentRegex != nil {
-			groups := issueRegexes.ComponentRegex.FindStringSubmatch(label.Name)
-			if len(groups) > 0 {
-				githubIssue.Component = groups[0]
-			}
+		if issueRegexes.ComponentRegex != nil && issueRegexes.ComponentRegex.MatchString(label.Name) {
+			githubIssue.Component = label.Name
 		}
-		if issueRegexes.PriorityRegex != nil {
-			groups := issueRegexes.PriorityRegex.FindStringSubmatch(label.Name)
-			if len(groups) > 0 {
-				githubIssue.Priority = groups[0]
-			}
+		if issueRegexes.PriorityRegex != nil && issueRegexes.PriorityRegex.MatchString(label.Name) {
+			githubIssue.Priority = label.Name
 		}
 		if issueRegexes.TypeRequirementRegex != nil && issueRegexes.TypeRequirementRegex.MatchString(label.Name) {
 			githubIssue.StdType = ticket.REQUIREMENT
+			joinedLabels = append(joinedLabels, label.Name)
 		} else if issueRegexes.TypeBugRegex != nil && issueRegexes.TypeBugRegex.MatchString(label.Name) {
 			githubIssue.StdType = ticket.BUG
+			joinedLabels = append(joinedLabels, label.Name)
 		} else if issueRegexes.TypeIncidentRegex != nil && issueRegexes.TypeIncidentRegex.MatchString(label.Name) {
 			githubIssue.StdType = ticket.INCIDENT
+			joinedLabels = append(joinedLabels, label.Name)
 		}
 	}
 	if len(joinedLabels) > 0 {
diff --git a/backend/plugins/github/tasks/pr_extractor.go b/backend/plugins/github/tasks/pr_extractor.go
index e22265821..17fec4a45 100644
--- a/backend/plugins/github/tasks/pr_extractor.go
+++ b/backend/plugins/github/tasks/pr_extractor.go
@@ -143,19 +143,12 @@ func ExtractApiPullRequests(taskCtx plugin.SubTaskContext) errors.Error {
 					LabelName:    label.Name,
 				})
 				// if pr.Type has not been set and prType is set in .env, process the below
-				if labelTypeRegex != nil {
-					groups := labelTypeRegex.FindStringSubmatch(label.Name)
-					if len(groups) > 0 {
-						githubPr.Type = groups[0]
-					}
+				if labelTypeRegex != nil && labelTypeRegex.MatchString(label.Name) {
+					githubPr.Type = label.Name
 				}
-
 				// if pr.Component has not been set and prComponent is set in .env, process
-				if labelComponentRegex != nil {
-					groups := labelComponentRegex.FindStringSubmatch(label.Name)
-					if len(groups) > 0 {
-						githubPr.Component = groups[0]
-					}
+				if labelComponentRegex != nil && labelComponentRegex.MatchString(label.Name) {
+					githubPr.Component = label.Name
 				}
 			}
 			results = append(results, githubPr)
diff --git a/backend/plugins/github_graphql/tasks/issue_extractor.go b/backend/plugins/github_graphql/tasks/issue_extractor.go
index deb54974b..355343e0c 100644
--- a/backend/plugins/github_graphql/tasks/issue_extractor.go
+++ b/backend/plugins/github_graphql/tasks/issue_extractor.go
@@ -171,32 +171,25 @@ func convertGithubLabels(issueRegexes *githubTasks.IssueRegexes, issue GraphqlQu
 			IssueId:      githubIssue.GithubId,
 			LabelName:    label.Name,
 		})
-		joinedLabels = append(joinedLabels, label.Name)
 
-		if issueRegexes.SeverityRegex != nil {
-			groups := issueRegexes.SeverityRegex.FindStringSubmatch(label.Name)
-			if len(groups) > 0 {
-				githubIssue.Severity = groups[0]
-			}
+		if issueRegexes.SeverityRegex != nil && issueRegexes.SeverityRegex.MatchString(label.Name) {
+			githubIssue.Severity = label.Name
 		}
-		if issueRegexes.ComponentRegex != nil {
-			groups := issueRegexes.ComponentRegex.FindStringSubmatch(label.Name)
-			if len(groups) > 0 {
-				githubIssue.Component = groups[0]
-			}
+		if issueRegexes.ComponentRegex != nil && issueRegexes.ComponentRegex.MatchString(label.Name) {
+			githubIssue.Component = label.Name
 		}
-		if issueRegexes.PriorityRegex != nil {
-			groups := issueRegexes.PriorityRegex.FindStringSubmatch(label.Name)
-			if len(groups) > 0 {
-				githubIssue.Priority = groups[0]
-			}
+		if issueRegexes.PriorityRegex != nil && issueRegexes.PriorityRegex.MatchString(label.Name) {
+			githubIssue.Priority = label.Name
 		}
 		if issueRegexes.TypeRequirementRegex != nil && issueRegexes.TypeRequirementRegex.MatchString(label.Name) {
 			githubIssue.StdType = ticket.REQUIREMENT
+			joinedLabels = append(joinedLabels, label.Name)
 		} else if issueRegexes.TypeBugRegex != nil && issueRegexes.TypeBugRegex.MatchString(label.Name) {
 			githubIssue.StdType = ticket.BUG
+			joinedLabels = append(joinedLabels, label.Name)
 		} else if issueRegexes.TypeIncidentRegex != nil && issueRegexes.TypeIncidentRegex.MatchString(label.Name) {
 			githubIssue.StdType = ticket.INCIDENT
+			joinedLabels = append(joinedLabels, label.Name)
 		}
 	}
 	if len(joinedLabels) > 0 {
diff --git a/backend/plugins/github_graphql/tasks/pr_extractor.go b/backend/plugins/github_graphql/tasks/pr_extractor.go
index 11bace53f..9abcc4a06 100644
--- a/backend/plugins/github_graphql/tasks/pr_extractor.go
+++ b/backend/plugins/github_graphql/tasks/pr_extractor.go
@@ -19,6 +19,7 @@ package tasks
 
 import (
 	"encoding/json"
+	"fmt"
 	"regexp"
 
 	"github.com/apache/incubator-devlake/core/errors"
@@ -52,6 +53,7 @@ func ExtractPrs(taskCtx plugin.SubTaskContext) errors.Error {
 		}
 	}
 	if config != nil && len(config.PrComponent) > 0 {
+		fmt.Println("config.PrComponent1", config.PrComponent)
 		labelComponentRegex, err = errors.Convert01(regexp.Compile(config.PrComponent))
 		if err != nil {
 			return errors.Default.Wrap(err, "regexp Compile prComponent failed")
@@ -88,19 +90,13 @@ func ExtractPrs(taskCtx plugin.SubTaskContext) errors.Error {
 						LabelName:    label.Name,
 					})
 					// if pr.Type has not been set and prType is set in .env, process the below
-					if labelTypeRegex != nil {
-						groups := labelTypeRegex.FindStringSubmatch(label.Name)
-						if len(groups) > 0 {
-							githubPr.Type = groups[0]
-						}
+					if labelTypeRegex != nil && labelTypeRegex.MatchString(label.Name) {
+						githubPr.Type = label.Name
 					}
-
 					// if pr.Component has not been set and prComponent is set in .env, process
-					if labelComponentRegex != nil {
-						groups := labelComponentRegex.FindStringSubmatch(label.Name)
-						if len(groups) > 0 {
-							githubPr.Component = groups[0]
-						}
+					if labelComponentRegex != nil && labelComponentRegex.MatchString(label.Name) {
+						githubPr.Component = label.Name
+
 					}
 				}
 				results = append(results, githubPr)
diff --git a/backend/plugins/gitlab/tasks/issue_extractor.go b/backend/plugins/gitlab/tasks/issue_extractor.go
index 2ae75e773..116dc9aca 100644
--- a/backend/plugins/gitlab/tasks/issue_extractor.go
+++ b/backend/plugins/gitlab/tasks/issue_extractor.go
@@ -20,6 +20,7 @@ package tasks
 import (
 	"encoding/json"
 	"regexp"
+	"strings"
 
 	"github.com/apache/incubator-devlake/core/errors"
 	"github.com/apache/incubator-devlake/core/models/common"
@@ -202,55 +203,38 @@ func ExtractApiIssues(taskCtx plugin.SubTaskContext) errors.Error {
 			if err != nil {
 				return nil, err
 			}
-
+			var joinedLabels []string
 			for _, label := range body.Labels {
 				results = append(results, &models.GitlabIssueLabel{
 					IssueId:      gitlabIssue.GitlabId,
 					LabelName:    label,
 					ConnectionId: data.Options.ConnectionId,
 				})
-				if issueSeverityRegex != nil {
-					groups := issueSeverityRegex.FindStringSubmatch(label)
-					if len(groups) > 0 {
-						gitlabIssue.Severity = groups[0]
-					}
+				if issueSeverityRegex != nil && issueSeverityRegex.MatchString(label) {
+					gitlabIssue.Severity = label
 				}
-
-				if issueComponentRegex != nil {
-					groups := issueComponentRegex.FindStringSubmatch(label)
-					if len(groups) > 0 {
-						gitlabIssue.Component = groups[0]
-					}
+				if issueComponentRegex != nil && issueComponentRegex.MatchString(label) {
+					gitlabIssue.Component = label
 				}
-
-				if issuePriorityRegex != nil {
-					groups := issuePriorityRegex.FindStringSubmatch(label)
-					if len(groups) > 0 {
-						gitlabIssue.Priority = groups[0]
-					}
-				}
-
-				if issueTypeBugRegex != nil {
-					if ok := issueTypeBugRegex.MatchString(label); ok {
-						gitlabIssue.StdType = ticket.BUG
-						gitlabIssue.Type = label
-					}
+				if issuePriorityRegex != nil && issuePriorityRegex.MatchString(label) {
+					gitlabIssue.Priority = label
 				}
 
-				if issueTypeRequirementRegex != nil {
-					if ok := issueTypeRequirementRegex.MatchString(label); ok {
-						gitlabIssue.StdType = ticket.REQUIREMENT
-						gitlabIssue.Type = label
-					}
-				}
-
-				if issueTypeIncidentRegex != nil {
-					if ok := issueTypeIncidentRegex.MatchString(label); ok {
-						gitlabIssue.StdType = ticket.INCIDENT
-						gitlabIssue.Type = label
-					}
+				if issueTypeRequirementRegex != nil && issueTypeRequirementRegex.MatchString(label) {
+					gitlabIssue.StdType = ticket.REQUIREMENT
+					joinedLabels = append(joinedLabels, label)
+				} else if issueTypeBugRegex != nil && issueTypeBugRegex.MatchString(label) {
+					gitlabIssue.StdType = ticket.BUG
+					joinedLabels = append(joinedLabels, label)
+				} else if issueTypeIncidentRegex != nil && issueTypeIncidentRegex.MatchString(label) {
+					gitlabIssue.StdType = ticket.INCIDENT
+					joinedLabels = append(joinedLabels, label)
 				}
 			}
+			if len(joinedLabels) > 0 {
+				gitlabIssue.Type = strings.Join(joinedLabels, ",")
+			}
+
 			gitlabIssue.ConnectionId = data.Options.ConnectionId
 			if body.Author != nil {
 				gitlabAuthor, err := convertGitlabAuthor(body, data.Options.ConnectionId)
diff --git a/backend/plugins/gitlab/tasks/mr_detail_extractor.go b/backend/plugins/gitlab/tasks/mr_detail_extractor.go
index b4666f7ea..9453a59fc 100644
--- a/backend/plugins/gitlab/tasks/mr_detail_extractor.go
+++ b/backend/plugins/gitlab/tasks/mr_detail_extractor.go
@@ -84,19 +84,12 @@ func ExtractApiMergeRequestDetails(taskCtx plugin.SubTaskContext) errors.Error {
 					ConnectionId: data.Options.ConnectionId,
 				})
 				// if pr.Type has not been set and prType is set in .env, process the below
-				if labelTypeRegex != nil {
-					groups := labelTypeRegex.FindStringSubmatch(label)
-					if len(groups) > 0 {
-						gitlabMergeRequest.Type = groups[0]
-					}
+				if labelTypeRegex != nil && labelTypeRegex.MatchString(label) {
+					gitlabMergeRequest.Type = label
 				}
-
 				// if pr.Component has not been set and prComponent is set in .env, process
-				if labelComponentRegex != nil {
-					groups := labelComponentRegex.FindStringSubmatch(label)
-					if len(groups) > 0 {
-						gitlabMergeRequest.Component = groups[0]
-					}
+				if labelComponentRegex != nil && labelComponentRegex.MatchString(label) {
+					gitlabMergeRequest.Component = label
 				}
 			}
 			for _, reviewer := range mr.Reviewers {
diff --git a/backend/plugins/gitlab/tasks/mr_extractor.go b/backend/plugins/gitlab/tasks/mr_extractor.go
index 2f59a03ad..92bfccfa3 100644
--- a/backend/plugins/gitlab/tasks/mr_extractor.go
+++ b/backend/plugins/gitlab/tasks/mr_extractor.go
@@ -141,19 +141,12 @@ func ExtractApiMergeRequests(taskCtx plugin.SubTaskContext) errors.Error {
 					ConnectionId: data.Options.ConnectionId,
 				})
 				// if pr.Type has not been set and prType is set in .env, process the below
-				if labelTypeRegex != nil {
-					groups := labelTypeRegex.FindStringSubmatch(label)
-					if len(groups) > 0 {
-						gitlabMergeRequest.Type = groups[0]
-					}
+				if labelTypeRegex != nil && labelTypeRegex.MatchString(label) {
+					gitlabMergeRequest.Type = label
 				}
-
 				// if pr.Component has not been set and prComponent is set in .env, process
-				if labelComponentRegex != nil {
-					groups := labelComponentRegex.FindStringSubmatch(label)
-					if len(groups) > 0 {
-						gitlabMergeRequest.Component = groups[0]
-					}
+				if labelComponentRegex != nil && labelComponentRegex.MatchString(label) {
+					gitlabMergeRequest.Component = label
 				}
 			}
 			for _, reviewer := range mr.Reviewers {