Skip to content

Commit

Permalink
fix: convert rules index out of range (#6670) (#6674)
Browse files Browse the repository at this point in the history
* fix: convert rules index out of range

* fix: update trans rule

* fix: bug

Co-authored-by: abeizn <[email protected]>
  • Loading branch information
github-actions[bot] and abeizn authored Dec 21, 2023
1 parent 79e1f91 commit 75c4c33
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 44 deletions.
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

0 comments on commit 75c4c33

Please sign in to comment.