This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new e828cadb3 fix: github graphql deployment collector filter by since 
(#6361)
e828cadb3 is described below

commit e828cadb33ea7afc36a75b27ffb56331dafe6b46
Author: abeizn <[email protected]>
AuthorDate: Wed Nov 1 22:29:59 2023 -0500

    fix: github graphql deployment collector filter by since (#6361)
    
    * fix: github graphql deployment collector filter by since
    
    * fix: rename to enableSince
---
 .../tasks/deployment_collector_extractor.go          | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git 
a/backend/plugins/github_graphql/tasks/deployment_collector_extractor.go 
b/backend/plugins/github_graphql/tasks/deployment_collector_extractor.go
index f4f318240..8d7e03e38 100644
--- a/backend/plugins/github_graphql/tasks/deployment_collector_extractor.go
+++ b/backend/plugins/github_graphql/tasks/deployment_collector_extractor.go
@@ -18,6 +18,9 @@ limitations under the License.
 package tasks
 
 import (
+       "strings"
+       "time"
+
        "github.com/apache/incubator-devlake/core/errors"
        "github.com/apache/incubator-devlake/core/models/common"
        "github.com/apache/incubator-devlake/core/plugin"
@@ -25,8 +28,6 @@ import (
        githubModels "github.com/apache/incubator-devlake/plugins/github/models"
        githubTasks "github.com/apache/incubator-devlake/plugins/github/tasks"
        "github.com/merico-dev/graphql"
-       "strings"
-       "time"
 )
 
 var _ plugin.SubTaskEntryPoint = CollectAndExtractDeployments
@@ -87,9 +88,7 @@ type GraphqlQueryDeploymentDeployment struct {
 // CollectAndExtractDeployments will request github api via graphql and store 
the result into raw layer by default
 // ResponseParser's return will be stored to tool layer. So it's called 
CollectorAndExtractor.
 func CollectAndExtractDeployments(taskCtx plugin.SubTaskContext) errors.Error {
-
        data := taskCtx.GetData().(*githubTasks.GithubTaskData)
-
        collectorWithState, err := 
helper.NewStatefulApiCollector(helper.RawDataSubTaskArgs{
                Ctx: taskCtx,
                Params: githubTasks.GithubApiParams{
@@ -101,11 +100,19 @@ func CollectAndExtractDeployments(taskCtx 
plugin.SubTaskContext) errors.Error {
        if err != nil {
                return err
        }
+       since := helper.DateTime{}
+       if collectorWithState.Since != nil {
+               since = helper.DateTime{Time: *collectorWithState.Since}
+       }
+       enableSince := false
 
        err = 
collectorWithState.InitGraphQLCollector(helper.GraphqlCollectorArgs{
                GraphqlClient: data.GraphqlClient,
                PageSize:      100,
                BuildQuery: func(reqData *helper.GraphqlRequestData) 
(interface{}, map[string]interface{}, error) {
+                       if enableSince {
+                               return nil, nil, nil
+                       }
                        query := &GraphqlQueryDeploymentWrapper{}
                        variables := make(map[string]interface{})
                        if reqData == nil {
@@ -129,6 +136,11 @@ func CollectAndExtractDeployments(taskCtx 
plugin.SubTaskContext) errors.Error {
                        deployments := query.Repository.Deployments.Deployments
                        var results []interface{}
                        for _, deployment := range deployments {
+                               //Skip deployments with createdAt earlier than 
'since'
+                               if deployment.CreatedAt.Before(since.Time) {
+                                       enableSince = true
+                                       continue
+                               }
                                githubDeployment, err := 
convertGithubDeployment(deployment, data.Options.ConnectionId, 
data.Options.GithubId)
                                if err != nil {
                                        return nil, err

Reply via email to