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

cherry-pick #6670 fix: convert rules index out of range #6674

Merged
merged 1 commit 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
22 changes: 14 additions & 8 deletions backend/helpers/pluginhelper/api/api_collector_with_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions backend/plugins/gitee/tasks/issue_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}

Expand Down
4 changes: 2 additions & 2 deletions backend/plugins/gitee/tasks/pr_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ 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]
}
}

// 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[1]
giteePr.Component = groups[0]
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions backend/plugins/github/tasks/issue_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions backend/plugins/github/tasks/pr_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ 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]
}
}

// 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[1]
githubPr.Component = groups[0]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 6 additions & 6 deletions backend/plugins/github_graphql/tasks/issue_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions backend/plugins/github_graphql/tasks/pr_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ 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]
}
}

// 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[1]
githubPr.Component = groups[0]
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions backend/plugins/gitlab/tasks/issue_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}

Expand Down
8 changes: 4 additions & 4 deletions backend/plugins/gitlab/tasks/mr_detail_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions backend/plugins/gitlab/tasks/mr_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
}
}
Expand Down