Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion backend/helpers/pluginhelper/api/graphql_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,16 @@ func (collector *GraphqlCollector) HasError() bool {
return len(collector.workerErrors) > 0
}

// isIgnorableGraphqlQueryError reports whether err means the queried issue no
// longer exists upstream, so its children can be skipped. GitHub and Linear
// word this differently.
func isIgnorableGraphqlQueryError(err error) bool {
return err != nil && strings.Contains(err.Error(), "Could not resolve to an Issue")
if err == nil {
return false
}
msg := err.Error()
return strings.Contains(msg, "Could not resolve to an Issue") ||
strings.Contains(msg, "Entity not found: Issue")
}

var _ plugin.SubTask = (*GraphqlCollector)(nil)
2 changes: 2 additions & 0 deletions backend/helpers/pluginhelper/api/graphql_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (

func TestIsIgnorableGraphqlQueryError(t *testing.T) {
assert.True(t, isIgnorableGraphqlQueryError(errors.New("Could not resolve to an Issue with the number of 17.")))
assert.True(t, isIgnorableGraphqlQueryError(errors.New("Entity not found: Issue")))
assert.False(t, isIgnorableGraphqlQueryError(errors.New("Entity not found: Team")))
assert.False(t, isIgnorableGraphqlQueryError(errors.New("some other graphql error")))
assert.False(t, isIgnorableGraphqlQueryError(nil))
}
3 changes: 1 addition & 2 deletions backend/plugins/linear/tasks/comment_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ func CollectComments(taskCtx plugin.SubTaskContext) errors.Error {
return query, variables, nil
},
GetPageInfo: func(iQuery interface{}, args *helper.GraphqlCollectorArgs) (*helper.GraphqlQueryPageInfo, error) {
query := iQuery.(*GraphqlQueryCommentWrapper)
return query.Issue.Comments.PageInfo, nil
return commentsPageInfo(iQuery.(*GraphqlQueryCommentWrapper)), nil
},
ResponseParser: func(queryWrapper interface{}) (messages []json.RawMessage, err errors.Error) {
query := queryWrapper.(*GraphqlQueryCommentWrapper)
Expand Down
3 changes: 1 addition & 2 deletions backend/plugins/linear/tasks/issue_history_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ func CollectIssueHistory(taskCtx plugin.SubTaskContext) errors.Error {
return query, variables, nil
},
GetPageInfo: func(iQuery interface{}, args *helper.GraphqlCollectorArgs) (*helper.GraphqlQueryPageInfo, error) {
query := iQuery.(*GraphqlQueryHistoryWrapper)
return query.Issue.History.PageInfo, nil
return historyPageInfo(iQuery.(*GraphqlQueryHistoryWrapper)), nil
},
ResponseParser: func(queryWrapper interface{}) (messages []json.RawMessage, err errors.Error) {
query := queryWrapper.(*GraphqlQueryHistoryWrapper)
Expand Down
48 changes: 48 additions & 0 deletions backend/plugins/linear/tasks/page_info_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
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 (
"testing"

helper "github.com/apache/devlake/helpers/pluginhelper/api"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// A deleted issue comes back as an empty `issue` object: the collector
// skips its "Entity not found: Issue" error, but must not then fail on the
// missing page info.
func TestPageInfo_DeletedIssueEndsPagination(t *testing.T) {
comments := commentsPageInfo(&GraphqlQueryCommentWrapper{})
require.NotNil(t, comments)
assert.False(t, comments.HasNextPage)

history := historyPageInfo(&GraphqlQueryHistoryWrapper{})
require.NotNil(t, history)
assert.False(t, history.HasNextPage)
}

func TestPageInfo_KeepsLinearPagination(t *testing.T) {
query := &GraphqlQueryCommentWrapper{}
query.Issue.Comments.PageInfo = &helper.GraphqlQueryPageInfo{EndCursor: "c1", HasNextPage: true}

pageInfo := commentsPageInfo(query)
assert.True(t, pageInfo.HasNextPage)
assert.Equal(t, "c1", pageInfo.EndCursor)
}
19 changes: 19 additions & 0 deletions backend/plugins/linear/tasks/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,28 @@ import (

"github.com/apache/devlake/core/dal"
"github.com/apache/devlake/core/models/domainlayer/ticket"
helper "github.com/apache/devlake/helpers/pluginhelper/api"
"github.com/apache/devlake/plugins/linear/models"
)

// An issue deleted in Linear returns an empty `issue` object with no page
// info. The collector skips that error, so treat the issue as its own last
// page instead of failing on the missing page info.
func pageInfoOrLast(pageInfo *helper.GraphqlQueryPageInfo) *helper.GraphqlQueryPageInfo {
if pageInfo == nil {
return &helper.GraphqlQueryPageInfo{HasNextPage: false}
}
return pageInfo
}

func commentsPageInfo(query *GraphqlQueryCommentWrapper) *helper.GraphqlQueryPageInfo {
return pageInfoOrLast(query.Issue.Comments.PageInfo)
}

func historyPageInfo(query *GraphqlQueryHistoryWrapper) *helper.GraphqlQueryPageInfo {
return pageInfoOrLast(query.Issue.History.PageInfo)
}

// issuesToCollectChildrenClauses builds the cursor clauses that drive per-issue
// child collection (comments, history). When `since` is non-nil (an incremental
// run), it restricts the sweep to issues updated since the last successful
Expand Down
Loading