d4x1 commented on code in PR #6507: URL: https://github.com/apache/incubator-devlake/pull/6507#discussion_r1407048567
##########
backend/plugins/sonarqube/tasks/issues_collector.go:
##########
@@ -133,17 +148,62 @@ func CollectIssues(taskCtx plugin.SubTaskContext) (err
errors.Error) {
createdBeforeUnix = createdBefore.Unix()
}
- // can not split it any more
- if createdBeforeUnix-createdAfterUnix <= 10 {
- return 100, nil
+ // can not split it by time
+ if createdBeforeUnix-createdAfterUnix <=
MININTERVAL {
+ // split it by dir/fil
+ for _, facet := range body.Facets {
+ for _, value := range
facet.Values {
+ if value.Count <=
MAXISSUECOUNT {
+
iterator.Push(&SonarqubeIssueIteratorNode{
+
Severity: severity,
+ Status:
status,
+ Type:
typ,
+
CreatedAfter: createdAfter,
+
CreatedBefore: createdBefore,
+
FilePath: value.Val,
+ })
+
logger.Info("split by dir, and it's issue count:[%d] and file path:[%s]",
value.Count, value.Val)
+ } else {
+ // split it by
dir when it's issue count > 10000
+ res2, err :=
data.ApiClient.Get("issues/search", url.Values{
Review Comment:
res2 and body2 values2 should have better names.
##########
backend/plugins/sonarqube/tasks/issues_collector.go:
##########
@@ -133,17 +148,62 @@ func CollectIssues(taskCtx plugin.SubTaskContext) (err
errors.Error) {
createdBeforeUnix = createdBefore.Unix()
}
- // can not split it any more
- if createdBeforeUnix-createdAfterUnix <= 10 {
- return 100, nil
+ // can not split it by time
+ if createdBeforeUnix-createdAfterUnix <=
MININTERVAL {
+ // split it by dir/fil
+ for _, facet := range body.Facets {
+ for _, value := range
facet.Values {
+ if value.Count <=
MAXISSUECOUNT {
+
iterator.Push(&SonarqubeIssueIteratorNode{
+
Severity: severity,
+ Status:
status,
+ Type:
typ,
+
CreatedAfter: createdAfter,
+
CreatedBefore: createdBefore,
+
FilePath: value.Val,
+ })
+
logger.Info("split by dir, and it's issue count:[%d] and file path:[%s]",
value.Count, value.Val)
+ } else {
+ // split it by
dir when it's issue count > 10000
+ res2, err :=
data.ApiClient.Get("issues/search", url.Values{
+
"componentKeys": {fmt.Sprintf("%v", data.Options.ProjectKey)},
+
"directories": {value.Val},
+
"facets": {"files"},
+ "ps":
{"1"},
+ }, nil)
+ if err != nil {
+ return
0, err
+ }
+ body2 :=
&SonarqubePageInfo{}
+ err =
helper.UnmarshalResponse(res2, body2)
+ if err != nil {
+ return
0, err
+ }
+ if
len(body2.Facets) != 1 {
+ return
0, errors.Default.New(fmt.Sprintf("the facets count [%d] is not 1",
len(body2.Facets)))
+ }
+ for _, value2
:= range body2.Facets[0].Values {
+ if
value2.Count > MAXISSUECOUNT {
+
logger.Warn(fmt.Errorf("the issue count [%d] exceeds the maximum page size",
value2.Count), "")
+ }
+
iterator.Push(&SonarqubeIssueIteratorNode{
+
Severity: severity,
+
Status: status,
+
Type: typ,
+
CreatedAfter: createdAfter,
+
CreatedBefore: createdBefore,
+
FilePath: value2.Val,
+ })
+
logger.Info(fmt.Sprintf("split by fil, and it's issue count:[%d] and file
path:[%s]", value2.Count, value2.Val))
Review Comment:
no need to use fmt.Sprintf. logger.Info has a format parameter.
##########
backend/plugins/sonarqube/tasks/issues_collector.go:
##########
@@ -133,17 +148,62 @@ func CollectIssues(taskCtx plugin.SubTaskContext) (err
errors.Error) {
createdBeforeUnix = createdBefore.Unix()
}
- // can not split it any more
- if createdBeforeUnix-createdAfterUnix <= 10 {
- return 100, nil
+ // can not split it by time
+ if createdBeforeUnix-createdAfterUnix <=
MININTERVAL {
+ // split it by dir/fil
+ for _, facet := range body.Facets {
+ for _, value := range
facet.Values {
+ if value.Count <=
MAXISSUECOUNT {
+
iterator.Push(&SonarqubeIssueIteratorNode{
+
Severity: severity,
+ Status:
status,
+ Type:
typ,
+
CreatedAfter: createdAfter,
+
CreatedBefore: createdBefore,
+
FilePath: value.Val,
+ })
+
logger.Info("split by dir, and it's issue count:[%d] and file path:[%s]",
value.Count, value.Val)
+ } else {
+ // split it by
dir when it's issue count > 10000
+ res2, err :=
data.ApiClient.Get("issues/search", url.Values{
+
"componentKeys": {fmt.Sprintf("%v", data.Options.ProjectKey)},
+
"directories": {value.Val},
+
"facets": {"files"},
+ "ps":
{"1"},
Review Comment:
Can this work? I think it should be `"ps": {}string{"1"}`.
##########
backend/plugins/sonarqube/tasks/issues_collector.go:
##########
@@ -239,3 +299,24 @@ func getTimeFromFormatTime(formatTime string) (*time.Time,
errors.Error) {
return &t, nil
}
+
+type SonarqubePageInfo struct {
+ Total int `json:"total"`
+ P int `json:"p"`
Review Comment:
what's the meaning of p and ps?
##########
backend/plugins/sonarqube/tasks/issues_collector.go:
##########
@@ -133,17 +148,62 @@ func CollectIssues(taskCtx plugin.SubTaskContext) (err
errors.Error) {
createdBeforeUnix = createdBefore.Unix()
}
- // can not split it any more
- if createdBeforeUnix-createdAfterUnix <= 10 {
- return 100, nil
+ // can not split it by time
+ if createdBeforeUnix-createdAfterUnix <=
MININTERVAL {
+ // split it by dir/fil
+ for _, facet := range body.Facets {
+ for _, value := range
facet.Values {
+ if value.Count <=
MAXISSUECOUNT {
+
iterator.Push(&SonarqubeIssueIteratorNode{
+
Severity: severity,
+ Status:
status,
+ Type:
typ,
+
CreatedAfter: createdAfter,
+
CreatedBefore: createdBefore,
+
FilePath: value.Val,
+ })
+
logger.Info("split by dir, and it's issue count:[%d] and file path:[%s]",
value.Count, value.Val)
+ } else {
+ // split it by
dir when it's issue count > 10000
+ res2, err :=
data.ApiClient.Get("issues/search", url.Values{
+
"componentKeys": {fmt.Sprintf("%v", data.Options.ProjectKey)},
+
"directories": {value.Val},
+
"facets": {"files"},
+ "ps":
{"1"},
+ }, nil)
+ if err != nil {
+ return
0, err
+ }
+ body2 :=
&SonarqubePageInfo{}
+ err =
helper.UnmarshalResponse(res2, body2)
+ if err != nil {
+ return
0, err
+ }
+ if
len(body2.Facets) != 1 {
+ return
0, errors.Default.New(fmt.Sprintf("the facets count [%d] is not 1",
len(body2.Facets)))
+ }
+ for _, value2
:= range body2.Facets[0].Values {
+ if
value2.Count > MAXISSUECOUNT {
+
logger.Warn(fmt.Errorf("the issue count [%d] exceeds the maximum page size",
value2.Count), "")
Review Comment:
no need to use fmt.Errorf.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
