diff --git a/backend/plugins/github/tasks/issue_extractor.go b/backend/plugins/github/tasks/issue_extractor.go index 2f80c928617..575ff15279c 100644 --- a/backend/plugins/github/tasks/issue_extractor.go +++ b/backend/plugins/github/tasks/issue_extractor.go @@ -91,7 +91,7 @@ func ExtractApiIssues(taskCtx plugin.SubTaskContext) errors.Error { config := data.Options.ScopeConfig issueRegexes, err := NewIssueRegexes(config) if err != nil { - return nil + return err } extractor, extErr := api.NewStatefulApiExtractor(&api.StatefulApiExtractorArgs[IssuesResponse]{ diff --git a/backend/plugins/github/tasks/issue_extractor_test.go b/backend/plugins/github/tasks/issue_extractor_test.go index b8294240ace..341cd5a4be2 100644 --- a/backend/plugins/github/tasks/issue_extractor_test.go +++ b/backend/plugins/github/tasks/issue_extractor_test.go @@ -21,6 +21,9 @@ import ( "testing" "time" + "github.com/apache/devlake/helpers/unithelper" + mockdal "github.com/apache/devlake/mocks/core/dal" + "github.com/apache/devlake/plugins/github/models" "github.com/stretchr/testify/assert" ) @@ -40,3 +43,21 @@ func TestIssueLeadTimeMinutes(t *testing.T) { // Closed before created, as GitHub reports for some transferred issues. assert.Nil(t, IssueLeadTimeMinutes(createdAt, createdAt.Add(-44*time.Minute))) } + +func TestExtractApiIssuesReturnsIssueRegexError(t *testing.T) { + mockDal := new(mockdal.Dal) + taskCtx := unithelper.DummySubTaskContext(mockDal) + taskCtx.On("GetData").Return(&GithubTaskData{ + Options: &GithubOptions{ + ConnectionId: 1, + Name: "apache/devlake", + ScopeConfig: &models.GithubScopeConfig{IssueSeverity: "severity/(.*"}, + }, + }) + + err := ExtractApiIssues(taskCtx) + + if assert.NotNil(t, err) { + assert.Contains(t, err.Error(), "issueSeverity") + } +} diff --git a/backend/plugins/github_graphql/tasks/issue_extractor.go b/backend/plugins/github_graphql/tasks/issue_extractor.go index 3f15bd0d949..7b05aaaec52 100644 --- a/backend/plugins/github_graphql/tasks/issue_extractor.go +++ b/backend/plugins/github_graphql/tasks/issue_extractor.go @@ -47,11 +47,11 @@ func ExtractIssues(taskCtx plugin.SubTaskContext) errors.Error { config := data.Options.ScopeConfig issueRegexes, err := githubTasks.NewIssueRegexes(config) if err != nil { - return nil + return err } milestoneMap, err := getMilestoneMap(db, data.Options.GithubId, data.Options.ConnectionId) if err != nil { - return nil + return err } extractor, err := api.NewApiExtractor(api.ApiExtractorArgs{ diff --git a/backend/plugins/github_graphql/tasks/issue_extractor_test.go b/backend/plugins/github_graphql/tasks/issue_extractor_test.go new file mode 100644 index 00000000000..d1b9f2fba1f --- /dev/null +++ b/backend/plugins/github_graphql/tasks/issue_extractor_test.go @@ -0,0 +1,70 @@ +/* +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" + + "github.com/apache/devlake/core/errors" + "github.com/apache/devlake/helpers/unithelper" + mockdal "github.com/apache/devlake/mocks/core/dal" + "github.com/apache/devlake/plugins/github/models" + githubTasks "github.com/apache/devlake/plugins/github/tasks" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +func TestExtractIssuesReturnsIssueRegexError(t *testing.T) { + mockDal := new(mockdal.Dal) + taskCtx := unithelper.DummySubTaskContext(mockDal) + taskCtx.On("GetData").Return(&githubTasks.GithubTaskData{ + Options: &githubTasks.GithubOptions{ + ConnectionId: 1, + Name: "apache/devlake", + ScopeConfig: &models.GithubScopeConfig{IssueSeverity: "severity/(.*"}, + }, + }) + + err := ExtractIssues(taskCtx) + + if assert.NotNil(t, err) { + assert.Contains(t, err.Error(), "issueSeverity") + } +} + +func TestExtractIssuesReturnsMilestoneQueryError(t *testing.T) { + dbErr := errors.Default.New("db unavailable") + mockDal := new(mockdal.Dal) + mockDal.On("All", mock.Anything, mock.Anything).Return(dbErr).Once() + taskCtx := unithelper.DummySubTaskContext(mockDal) + taskCtx.On("GetData").Return(&githubTasks.GithubTaskData{ + Options: &githubTasks.GithubOptions{ + ConnectionId: 1, + GithubId: 101, + Name: "apache/devlake", + ScopeConfig: &models.GithubScopeConfig{}, + }, + }) + + err := ExtractIssues(taskCtx) + + if assert.NotNil(t, err) { + assert.Contains(t, err.Error(), "db unavailable") + } + mockDal.AssertExpectations(t) +}