warren830 commented on code in PR #3705: URL: https://github.com/apache/incubator-devlake/pull/3705#discussion_r1018681607
########## plugins/github_graphql/tasks/check_run_collector.go: ########## @@ -0,0 +1,190 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package tasks + +import ( + "encoding/json" + "github.com/apache/incubator-devlake/errors" + "github.com/apache/incubator-devlake/plugins/core" + "github.com/apache/incubator-devlake/plugins/core/dal" + "github.com/apache/incubator-devlake/plugins/github/models" + githubTasks "github.com/apache/incubator-devlake/plugins/github/tasks" + "github.com/apache/incubator-devlake/plugins/helper" + "github.com/merico-dev/graphql" + "reflect" + "time" +) + +const RAW_CHECK_RUNS_TABLE = "github_graphql_check_runs" + +type GraphqlQueryCheckRunWrapper struct { + RateLimit struct { + Cost int + } + Node []GraphqlQueryCheckSuite `graphql:"node(id: $id)" graphql-extend:"true"` +} + +type GraphqlQueryCheckSuite struct { + Id string + Typename string `graphql:"__typename"` + CheckSuite struct { + CheckRuns struct { + TotalCount int + Nodes []struct { + Id string + Name string + DetailsUrl string + DatabaseId int + Status string + StartedAt *time.Time + Conclusion string + CompletedAt *time.Time + //ExternalId string + //Url string + //Title interface{} + //Text interface{} + //Summary interface{} + + Steps struct { + TotalCount int + Nodes []struct { + CompletedAt *time.Time + Conclusion string + ExternalId string + Name string + Number int + SecondsToCompletion int + StartedAt *time.Time + Status string + } + } `graphql:"steps(first: 50)"` + } + } `graphql:"checkRuns(first: 50)"` + } `graphql:"... on CheckSuite"` +} + +type SimpleWorkflowRun struct { + CheckSuiteNodeID string +} + +var CollectCheckRunMeta = core.SubTaskMeta{ + Name: "CollectCheckRun", + EntryPoint: CollectCheckRun, + EnabledByDefault: true, + Description: "Collect CheckRun data from GithubGraphql api", +} + +var _ core.SubTaskEntryPoint = CollectAccount + +func CollectCheckRun(taskCtx core.SubTaskContext) errors.Error { + logger := taskCtx.GetLogger() + db := taskCtx.GetDal() + data := taskCtx.GetData().(*githubTasks.GithubTaskData) + + cursor, err := db.Cursor( + dal.Select("check_suite_node_id"), + dal.From(models.GithubRun{}.TableName()), + dal.Where("repo_id = ? and connection_id=?", data.Repo.GithubId, data.Options.ConnectionId), + ) + if err != nil { + return err + } + iterator, err := helper.NewDalCursorIterator(db, cursor, reflect.TypeOf(SimpleWorkflowRun{})) + if err != nil { + return err + } + + collector, err := helper.NewGraphqlCollector(helper.GraphqlCollectorArgs{ + RawDataSubTaskArgs: helper.RawDataSubTaskArgs{ + Ctx: taskCtx, + Params: githubTasks.GithubApiParams{ + ConnectionId: data.Options.ConnectionId, + Owner: data.Options.Owner, + Repo: data.Options.Repo, + }, + Table: RAW_CHECK_RUNS_TABLE, + }, + Input: iterator, + InputStep: 30, Review Comment: how about 60? -- 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]
