This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch fix-graphql-since
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/fix-graphql-since by this push:
new 234f83c3d fix: github graphql deployment collector filter by since
234f83c3d is described below
commit 234f83c3d77336d6bc7e18c3d6bb34cd177e1fa1
Author: abeizn <[email protected]>
AuthorDate: Mon Oct 30 20:40:37 2023 +0800
fix: github graphql deployment collector filter by since
---
.../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 4d1bd0dec..7120542fd 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 = CollectAndExtractDeployment
@@ -87,9 +88,7 @@ type GraphqlQueryDeploymentDeployment struct {
// CollectAndExtractDeployment 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 CollectAndExtractDeployment(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 CollectAndExtractDeployment(taskCtx
plugin.SubTaskContext) errors.Error {
if err != nil {
return err
}
+ since := helper.DateTime{}
+ if collectorWithState.Since != nil {
+ since = helper.DateTime{Time: *collectorWithState.Since}
+ }
+ isSince := false
err =
collectorWithState.InitGraphQLCollector(helper.GraphqlCollectorArgs{
GraphqlClient: data.GraphqlClient,
PageSize: 100,
BuildQuery: func(reqData *helper.GraphqlRequestData)
(interface{}, map[string]interface{}, error) {
+ if isSince {
+ return nil, nil, nil
+ }
query := &GraphqlQueryDeploymentWrapper{}
variables := make(map[string]interface{})
if reqData == nil {
@@ -129,6 +136,11 @@ func CollectAndExtractDeployment(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) {
+ isSince = true
+ continue
+ }
githubDeployment, err :=
convertGithubDeployment(deployment, data.Options.ConnectionId,
data.Options.GithubId)
if err != nil {
return nil, err