leric commented on code in PR #6507:
URL: 
https://github.com/apache/incubator-devlake/pull/6507#discussion_r1405894449


##########
backend/plugins/sonarqube/tasks/issues_collector.go:
##########
@@ -133,17 +148,63 @@ 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), "")
+                                                                       } else {
+                                                                               
iterator.Push(&SonarqubeIssueIteratorNode{

Review Comment:
   If the count exceed MAXISSUECOUNT, a warning is logged, we still need to 
push this node into the queue, or we should log an error.



-- 
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]

Reply via email to