From 4ce4a06fdc58a14e2634e2e093f798d702da0cf9 Mon Sep 17 00:00:00 2001 From: abeizn Date: Tue, 19 Dec 2023 19:33:10 +0800 Subject: [PATCH] fix: convert rules index out of range (#6670) * fix: convert rules index out of range * fix: update trans rule * fix: bug --- .../api/api_collector_with_state.go | 22 ++++++++++++------- .../plugins/gitee/tasks/issue_extractor.go | 6 ++--- backend/plugins/gitee/tasks/pr_extractor.go | 4 ++-- .../plugins/github/tasks/issue_extractor.go | 12 +++++----- backend/plugins/github/tasks/pr_extractor.go | 4 ++-- .../tasks/pr_review_comment_extractor.go | 2 +- .../github_graphql/tasks/issue_extractor.go | 12 +++++----- .../github_graphql/tasks/pr_extractor.go | 4 ++-- .../plugins/gitlab/tasks/issue_extractor.go | 12 +++++----- .../gitlab/tasks/mr_detail_extractor.go | 8 +++---- backend/plugins/gitlab/tasks/mr_extractor.go | 8 +++---- 11 files changed, 50 insertions(+), 44 deletions(-) diff --git a/backend/helpers/pluginhelper/api/api_collector_with_state.go b/backend/helpers/pluginhelper/api/api_collector_with_state.go index 89315fb013a..95b4051fcef 100644 --- a/backend/helpers/pluginhelper/api/api_collector_with_state.go +++ b/backend/helpers/pluginhelper/api/api_collector_with_state.go @@ -103,20 +103,26 @@ func NewStatefulApiCollector(args RawDataSubTaskArgs) (*ApiCollectorStateManager var isIncremental bool var since *time.Time - if syncPolicy == nil || (syncPolicy != nil && syncPolicy.TimeAfter == nil) { - // 1. If no syncPolicy TimeAfter, incremental and since is oldState.LatestSuccessStart + if oldLatestSuccessStart == nil { + // 1. If no oldState.LatestSuccessStart, not incremental and since is syncPolicy.TimeAfter + isIncremental = false + if syncPolicy != nil { + since = syncPolicy.TimeAfter + } + } else if syncPolicy == nil { + // 2. If no syncPolicy, incremental and since is oldState.LatestSuccessStart isIncremental = true since = oldLatestSuccessStart - } else if oldLatestSuccessStart == nil { - // 2. If no oldState.LatestSuccessStart, not incremental and since is syncPolicy.TimeAfter - isIncremental = false - since = syncPolicy.TimeAfter } else if syncPolicy.FullSync { // 3. If fullSync true, not incremental and since is syncPolicy.TimeAfter isIncremental = false since = syncPolicy.TimeAfter - } else if syncPolicy.TimeAfter != nil { - // 4. If syncPolicy.TimeAfter not nil + } else if syncPolicy.TimeAfter == nil { + // 4. If no syncPolicy TimeAfter, incremental and since is oldState.LatestSuccessStart + isIncremental = true + since = oldLatestSuccessStart + } else { + // 5. If syncPolicy.TimeAfter not nil if oldTimeAfter != nil && syncPolicy.TimeAfter.Before(*oldTimeAfter) { // 4.1 If oldTimeAfter not nil and syncPolicy.TimeAfter before oldTimeAfter, incremental is false and since is syncPolicy.TimeAfter isIncremental = false diff --git a/backend/plugins/gitee/tasks/issue_extractor.go b/backend/plugins/gitee/tasks/issue_extractor.go index 83f6dfc43af..175fd7a5a64 100644 --- a/backend/plugins/gitee/tasks/issue_extractor.go +++ b/backend/plugins/gitee/tasks/issue_extractor.go @@ -180,21 +180,21 @@ func ExtractApiIssues(taskCtx plugin.SubTaskContext) errors.Error { if issueSeverityRegex != nil { groups := issueSeverityRegex.FindStringSubmatch(label.Name) if len(groups) > 0 { - giteeIssue.Severity = groups[1] + giteeIssue.Severity = groups[0] } } if issueComponentRegex != nil { groups := issueComponentRegex.FindStringSubmatch(label.Name) if len(groups) > 0 { - giteeIssue.Component = groups[1] + giteeIssue.Component = groups[0] } } if issuePriorityRegex != nil { groups := issuePriorityRegex.FindStringSubmatch(label.Name) if len(groups) > 0 { - giteeIssue.Priority = groups[1] + giteeIssue.Priority = groups[0] } } diff --git a/backend/plugins/gitee/tasks/pr_extractor.go b/backend/plugins/gitee/tasks/pr_extractor.go index 50532c1c223..462fe2e5d8d 100644 --- a/backend/plugins/gitee/tasks/pr_extractor.go +++ b/backend/plugins/gitee/tasks/pr_extractor.go @@ -127,7 +127,7 @@ func ExtractApiPullRequests(taskCtx plugin.SubTaskContext) errors.Error { if labelTypeRegex != nil { groups := labelTypeRegex.FindStringSubmatch(label.Name) if len(groups) > 0 { - giteePr.Type = groups[1] + giteePr.Type = groups[0] } } @@ -135,7 +135,7 @@ func ExtractApiPullRequests(taskCtx plugin.SubTaskContext) errors.Error { if labelComponentRegex != nil { groups := labelComponentRegex.FindStringSubmatch(label.Name) if len(groups) > 0 { - giteePr.Component = groups[1] + giteePr.Component = groups[0] } } } diff --git a/backend/plugins/github/tasks/issue_extractor.go b/backend/plugins/github/tasks/issue_extractor.go index 85c1408d113..0801302fba1 100644 --- a/backend/plugins/github/tasks/issue_extractor.go +++ b/backend/plugins/github/tasks/issue_extractor.go @@ -214,20 +214,20 @@ func convertGithubLabels(issueRegexes *IssueRegexes, issue *IssuesResponse, gith if issueRegexes.SeverityRegex != nil { groups := issueRegexes.SeverityRegex.FindStringSubmatch(label.Name) - if len(groups) > 1 { - githubIssue.Severity = groups[1] + if len(groups) > 0 { + githubIssue.Severity = groups[0] } } if issueRegexes.ComponentRegex != nil { groups := issueRegexes.ComponentRegex.FindStringSubmatch(label.Name) - if len(groups) > 1 { - githubIssue.Component = groups[1] + if len(groups) > 0 { + githubIssue.Component = groups[0] } } if issueRegexes.PriorityRegex != nil { groups := issueRegexes.PriorityRegex.FindStringSubmatch(label.Name) - if len(groups) > 1 { - githubIssue.Priority = groups[1] + if len(groups) > 0 { + githubIssue.Priority = groups[0] } } if issueRegexes.TypeRequirementRegex != nil && issueRegexes.TypeRequirementRegex.MatchString(label.Name) { diff --git a/backend/plugins/github/tasks/pr_extractor.go b/backend/plugins/github/tasks/pr_extractor.go index 8805cb943b7..e2226582118 100644 --- a/backend/plugins/github/tasks/pr_extractor.go +++ b/backend/plugins/github/tasks/pr_extractor.go @@ -146,7 +146,7 @@ func ExtractApiPullRequests(taskCtx plugin.SubTaskContext) errors.Error { if labelTypeRegex != nil { groups := labelTypeRegex.FindStringSubmatch(label.Name) if len(groups) > 0 { - githubPr.Type = groups[1] + githubPr.Type = groups[0] } } @@ -154,7 +154,7 @@ func ExtractApiPullRequests(taskCtx plugin.SubTaskContext) errors.Error { if labelComponentRegex != nil { groups := labelComponentRegex.FindStringSubmatch(label.Name) if len(groups) > 0 { - githubPr.Component = groups[1] + githubPr.Component = groups[0] } } } diff --git a/backend/plugins/github/tasks/pr_review_comment_extractor.go b/backend/plugins/github/tasks/pr_review_comment_extractor.go index 5759b1346cc..8daeb8920ae 100644 --- a/backend/plugins/github/tasks/pr_review_comment_extractor.go +++ b/backend/plugins/github/tasks/pr_review_comment_extractor.go @@ -127,7 +127,7 @@ func ExtractApiPrReviewComments(taskCtx plugin.SubTaskContext) errors.Error { func enrichGithubPrComment(data *GithubTaskData, db dal.Dal, prUrlRegex *regexp.Regexp, prUrl string) (int, errors.Error) { groups := prUrlRegex.FindStringSubmatch(prUrl) - if len(groups) > 0 { + if len(groups) > 1 { prNumber, err := strconv.Atoi(groups[1]) if err != nil { return 0, errors.Default.Wrap(err, "parse prId failed") diff --git a/backend/plugins/github_graphql/tasks/issue_extractor.go b/backend/plugins/github_graphql/tasks/issue_extractor.go index 3dc61b4189c..deb54974ba7 100644 --- a/backend/plugins/github_graphql/tasks/issue_extractor.go +++ b/backend/plugins/github_graphql/tasks/issue_extractor.go @@ -175,20 +175,20 @@ func convertGithubLabels(issueRegexes *githubTasks.IssueRegexes, issue GraphqlQu if issueRegexes.SeverityRegex != nil { groups := issueRegexes.SeverityRegex.FindStringSubmatch(label.Name) - if len(groups) > 1 { - githubIssue.Severity = groups[1] + if len(groups) > 0 { + githubIssue.Severity = groups[0] } } if issueRegexes.ComponentRegex != nil { groups := issueRegexes.ComponentRegex.FindStringSubmatch(label.Name) - if len(groups) > 1 { - githubIssue.Component = groups[1] + if len(groups) > 0 { + githubIssue.Component = groups[0] } } if issueRegexes.PriorityRegex != nil { groups := issueRegexes.PriorityRegex.FindStringSubmatch(label.Name) - if len(groups) > 1 { - githubIssue.Priority = groups[1] + if len(groups) > 0 { + githubIssue.Priority = groups[0] } } if issueRegexes.TypeRequirementRegex != nil && issueRegexes.TypeRequirementRegex.MatchString(label.Name) { diff --git a/backend/plugins/github_graphql/tasks/pr_extractor.go b/backend/plugins/github_graphql/tasks/pr_extractor.go index 4ae3fb61409..11bace53f4c 100644 --- a/backend/plugins/github_graphql/tasks/pr_extractor.go +++ b/backend/plugins/github_graphql/tasks/pr_extractor.go @@ -91,7 +91,7 @@ func ExtractPrs(taskCtx plugin.SubTaskContext) errors.Error { if labelTypeRegex != nil { groups := labelTypeRegex.FindStringSubmatch(label.Name) if len(groups) > 0 { - githubPr.Type = groups[1] + githubPr.Type = groups[0] } } @@ -99,7 +99,7 @@ func ExtractPrs(taskCtx plugin.SubTaskContext) errors.Error { if labelComponentRegex != nil { groups := labelComponentRegex.FindStringSubmatch(label.Name) if len(groups) > 0 { - githubPr.Component = groups[1] + githubPr.Component = groups[0] } } } diff --git a/backend/plugins/gitlab/tasks/issue_extractor.go b/backend/plugins/gitlab/tasks/issue_extractor.go index 8991b3bb6ae..2ae75e7733f 100644 --- a/backend/plugins/gitlab/tasks/issue_extractor.go +++ b/backend/plugins/gitlab/tasks/issue_extractor.go @@ -211,22 +211,22 @@ func ExtractApiIssues(taskCtx plugin.SubTaskContext) errors.Error { }) if issueSeverityRegex != nil { groups := issueSeverityRegex.FindStringSubmatch(label) - if len(groups) > 1 { - gitlabIssue.Severity = groups[1] + if len(groups) > 0 { + gitlabIssue.Severity = groups[0] } } if issueComponentRegex != nil { groups := issueComponentRegex.FindStringSubmatch(label) - if len(groups) > 1 { - gitlabIssue.Component = groups[1] + if len(groups) > 0 { + gitlabIssue.Component = groups[0] } } if issuePriorityRegex != nil { groups := issuePriorityRegex.FindStringSubmatch(label) - if len(groups) > 1 { - gitlabIssue.Priority = groups[1] + if len(groups) > 0 { + gitlabIssue.Priority = groups[0] } } diff --git a/backend/plugins/gitlab/tasks/mr_detail_extractor.go b/backend/plugins/gitlab/tasks/mr_detail_extractor.go index 8a590d53ed2..b4666f7eaff 100644 --- a/backend/plugins/gitlab/tasks/mr_detail_extractor.go +++ b/backend/plugins/gitlab/tasks/mr_detail_extractor.go @@ -86,16 +86,16 @@ func ExtractApiMergeRequestDetails(taskCtx plugin.SubTaskContext) errors.Error { // 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) > 1 { - gitlabMergeRequest.Type = groups[1] + if len(groups) > 0 { + gitlabMergeRequest.Type = groups[0] } } // if pr.Component has not been set and prComponent is set in .env, process if labelComponentRegex != nil { groups := labelComponentRegex.FindStringSubmatch(label) - if len(groups) > 1 { - gitlabMergeRequest.Component = groups[1] + if len(groups) > 0 { + gitlabMergeRequest.Component = groups[0] } } } diff --git a/backend/plugins/gitlab/tasks/mr_extractor.go b/backend/plugins/gitlab/tasks/mr_extractor.go index 4468afc01fd..2f59a03adc7 100644 --- a/backend/plugins/gitlab/tasks/mr_extractor.go +++ b/backend/plugins/gitlab/tasks/mr_extractor.go @@ -143,16 +143,16 @@ func ExtractApiMergeRequests(taskCtx plugin.SubTaskContext) errors.Error { // 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) > 1 { - gitlabMergeRequest.Type = groups[1] + if len(groups) > 0 { + gitlabMergeRequest.Type = groups[0] } } // if pr.Component has not been set and prComponent is set in .env, process if labelComponentRegex != nil { groups := labelComponentRegex.FindStringSubmatch(label) - if len(groups) > 1 { - gitlabMergeRequest.Component = groups[1] + if len(groups) > 0 { + gitlabMergeRequest.Component = groups[0] } } }