Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type trans rules #6679

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 12 additions & 33 deletions backend/plugins/gitee/tasks/issue_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 4 additions & 11 deletions backend/plugins/gitee/tasks/pr_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

Large diffs are not rendered by default.

25 changes: 9 additions & 16 deletions backend/plugins/github/tasks/issue_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 4 additions & 11 deletions backend/plugins/github/tasks/pr_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 9 additions & 16 deletions backend/plugins/github_graphql/tasks/issue_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 7 additions & 11 deletions backend/plugins/github_graphql/tasks/pr_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package tasks

import (
"encoding/json"
"fmt"
"regexp"

"github.com/apache/incubator-devlake/core/errors"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
58 changes: 21 additions & 37 deletions backend/plugins/gitlab/tasks/issue_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
15 changes: 4 additions & 11 deletions backend/plugins/gitlab/tasks/mr_detail_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 4 additions & 11 deletions backend/plugins/gitlab/tasks/mr_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading