This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/main by this push:
     new ae7391901 fix: ensure Changelog IDs are numeric (#4835)
ae7391901 is described below

commit ae7391901667a31dc008e21660504160f2c14dcf
Author: dwalker-sabiogroup 
<[email protected]>
AuthorDate: Mon Apr 3 05:45:03 2023 +0100

    fix: ensure Changelog IDs are numeric (#4835)
    
    **Why**
    
    The current validation in convertIds function only guards against
    leading/trailing white space. This can cause an issue if other
    characters such as `[` or `]` are included in the ids input by the
    caller e.g. 123,[90],65
    
    Resulting in errors such as
    
    ```
    time="2023-03-30 12:46:45" level=error msg=" [pipeline service] [pipeline 
#1] run tasks failed
            caused by: Error running task 70.
            Wraps: (2) subtask convertIssueChangelogs ended unexpectedly
            Wraps: (3) error calling Converter plugin implementation
            Wraps: (4) strconv.ParseUint: parsing "[90]": invalid syntax
            Wraps: (5) strconv.ParseUint: parsing "[90]"
            Wraps: (6) invalid syntax
            Error types: (1) *hintdetail.withDetail (2) *hintdetail.withDetail 
(3) *hintdetail.withDetail (4) *hintdetail.withDetail (5) *strconv.NumError (6) 
*errors.errorString
    ```
    
    **How**
    
    - Add a Regular Expression to match any repeated numeric characters
    - Return the first match of the regular expression as the item ID
    
    The above will prevent parseUint from returning an error and resolve 
https://github.com/apache/incubator-devlake/issues/4827
---
 backend/plugins/jira/tasks/issue_changelog_convertor.go | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/backend/plugins/jira/tasks/issue_changelog_convertor.go 
b/backend/plugins/jira/tasks/issue_changelog_convertor.go
index 8d11b35e5..0dc8d134b 100644
--- a/backend/plugins/jira/tasks/issue_changelog_convertor.go
+++ b/backend/plugins/jira/tasks/issue_changelog_convertor.go
@@ -18,6 +18,12 @@ limitations under the License.
 package tasks
 
 import (
+       "reflect"
+       "regexp"
+       "strconv"
+       "strings"
+       "time"
+
        "github.com/apache/incubator-devlake/core/dal"
        "github.com/apache/incubator-devlake/core/errors"
        "github.com/apache/incubator-devlake/core/models/domainlayer"
@@ -26,12 +32,10 @@ import (
        "github.com/apache/incubator-devlake/core/plugin"
        "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
        "github.com/apache/incubator-devlake/plugins/jira/models"
-       "reflect"
-       "strconv"
-       "strings"
-       "time"
 )
 
+var validID = regexp.MustCompile(`[0-9]+`)
+
 var ConvertIssueChangelogsMeta = plugin.SubTaskMeta{
        Name:             "convertIssueChangelogs",
        EntryPoint:       ConvertIssueChangelogs,
@@ -160,6 +164,7 @@ func convertIds(ids string, connectionId uint64, 
sprintIdGenerator *didgen.Domai
        var resultSlice []string
        for _, item := range ss {
                item = strings.TrimSpace(item)
+               item := validID.FindString(item)
                if item != "" {
                        id, err := strconv.ParseUint(item, 10, 64)
                        if err != nil {

Reply via email to