From a6e6813c98df24f0863c584a9b975a63d2a01297 Mon Sep 17 00:00:00 2001 From: Shivam Sharma <192242476+ShivamSharma43@users.noreply.github.com> Date: Tue, 10 Nov 2026 13:21:13 +0530 Subject: [PATCH] fix(github): return the issue extractor setup errors ExtractApiIssues and the github_graphql ExtractIssues returned nil when NewIssueRegexes failed, e.g. on an invalid issue regex in the scope config. The github_graphql extractor did the same when the milestone query failed. The subtask was marked successful without extracting anything, and the error was lost. Return it, like the PR extractors do. Closes #9358 Generated-by: Claude Code (Claude Opus 5.5) Co-Authored-By: Claude Opus 5.5 Signed-off-by: Shivam Sharma <192242476+ShivamSharma43@users.noreply.github.com> --- .../plugins/github/tasks/issue_extractor.go | 2 +- .../github/tasks/issue_extractor_test.go | 21 ++++++ .../github_graphql/tasks/issue_extractor.go | 4 +- .../tasks/issue_extractor_test.go | 70 +++++++++++++++++++ 4 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 backend/plugins/github_graphql/tasks/issue_extractor_test.go 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) +}