Skip to content

Commit

Permalink
refactor: skip running pipelines when collecting
Browse files Browse the repository at this point in the history
  • Loading branch information
klesh committed Oct 11, 2023
1 parent 94263cb commit 841679f
Showing 1 changed file with 1 addition and 35 deletions.
36 changes: 1 addition & 35 deletions backend/plugins/github/tasks/cicd_run_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@ package tasks
import (
"encoding/json"
"fmt"
"io"
"net/http"
"net/url"
"reflect"
"time"

"github.com/apache/incubator-devlake/core/dal"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/models/common"
"github.com/apache/incubator-devlake/core/plugin"
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/plugins/github/models"
)

func init() {
Expand Down Expand Up @@ -67,7 +63,6 @@ var CollectRunsMeta = plugin.SubTaskMeta{

func CollectRuns(taskCtx plugin.SubTaskContext) errors.Error {
data := taskCtx.GetData().(*GithubTaskData)
db := taskCtx.GetDal()
collector, err := helper.NewStatefulApiCollectorForFinalizableEntity(helper.FinalizableApiCollectorArgs{
RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
Ctx: taskCtx,
Expand All @@ -85,6 +80,7 @@ func CollectRuns(taskCtx plugin.SubTaskContext) errors.Error {
UrlTemplate: "repos/{{ .Params.Name }}/actions/runs",
Query: func(reqData *helper.RequestData, createdAfter *time.Time) (url.Values, errors.Error) {
query := url.Values{}
query.Set("status", "completed")
query.Set("page", fmt.Sprintf("%v", reqData.Pager.Page))
query.Set("per_page", fmt.Sprintf("%v", reqData.Pager.Size))
return query, nil
Expand All @@ -110,36 +106,6 @@ func CollectRuns(taskCtx plugin.SubTaskContext) errors.Error {
return pj.CreatedAt.ToTime(), nil
},
},
CollectUnfinishedDetails: &helper.FinalizableApiCollectorDetailArgs{
BuildInputIterator: func() (helper.Iterator, errors.Error) {
// load unfinished runs from the database
cursor, err := db.Cursor(
dal.Select("id"),
dal.From(&models.GithubRun{}),
dal.Where(
"repo_id = ? AND connection_id = ? AND status IN ('ACTION_REQUIRED', 'STALE', 'IN_PROGRESS', 'QUEUED', 'REQUESTED', 'WAITING', 'PENDING')",
data.Options.GithubId, data.Options.ConnectionId,
),
)
if err != nil {
return nil, err
}
return helper.NewDalCursorIterator(db, cursor, reflect.TypeOf(SimpleGithubApiJob{}))
},

FinalizableApiCollectorCommonArgs: helper.FinalizableApiCollectorCommonArgs{
UrlTemplate: "repos/{{ .Params.Name }}/actions/runs/{{ .Input.ID }}",
ResponseParser: func(res *http.Response) ([]json.RawMessage, errors.Error) {
body, err := io.ReadAll(res.Body)
if err != nil {
return nil, errors.Convert(err)
}
res.Body.Close()
return []json.RawMessage{body}, nil
},
AfterResponse: ignoreHTTPStatus404,
},
},
})

if err != nil {
Expand Down

0 comments on commit 841679f

Please sign in to comment.