turbot / steampipe-plugin-jira

Use SQL to instantly query Jira. Open source CLI. No DB required.
https://hub.steampipe.io/plugins/turbot/jira
Apache License 2.0
22 stars 14 forks source link

Fix sprint type could be string and map #87

Closed juandspy closed 1 year ago

juandspy commented 1 year ago

There is an error with some queries because the Jira issue contains a string sprint instead of a map:

❯ steampipe query "select key, self, project_key from jira_issue where project_key = 'MYPROJECT' limit 5000;"

Error: failed to populate column 'sprint_ids': rpc error: code = Internal desc = transform extractSprintIds failed with panic interface conversion: interface {} is string, not map[string]interface {} (SQLSTATE HV000)

+-----+------+-------------+
| key | self | project_key |
+-----+------+-------------+
+-----+------+-------------+

These changes ignore invalid types such as string and just store the valid values.

cbruno10 commented 1 year ago

@juandspy Thanks for raising the PR! Do you know what causes a sprint to come back as type string as opposed to map? Does this correspond to a particular issue type in Jira?

juandspy commented 1 year ago

@juandspy Thanks for raising the PR! Do you know what causes a sprint to come back as type string as opposed to map? Does this correspond to a particular issue type in Jira?

@cbruno10 I've added some logging in there:

        if sprint, ok := item.(map[string]interface{}); ok {
            sprintNames = append(sprintNames, sprint["name"])
        } else {
            plugin.Logger(ctx).Debug("extractSprintNames", fmt.Sprintf("Wrong type of sprint found. Type is %v, value is %v", reflect.TypeOf(sprint), sprint))
        }

and found out that there are some empty maps:

2023-08-09 07:37:52.954 UTC [DEBUG] steampipe-plugin-jira.plugin: [DEBUG] 1691566672787: extractSprintNames: EXTRA_VALUE_AT_END="Wrong type of sprint found. Type is map[string]interface {}, value is map[]"
cbruno10 commented 1 year ago

@juandspy In Jira itself, do you know what types of issues would cause the API/SDK to return them as empty maps instead of strings? Or do you think this is just an SDK issue?

I think we can handle the different data types like you have in this PR, but it would be good to know the root cause of why there are multiple data types coming back.

juandspy commented 1 year ago

plugin.Logger(ctx).Debug("extractSprintNames", fmt.Sprintf("Wrong type of sprint found. Type is %v, value is %v", reflect.TypeOf(sprint), sprint))

@cbruno10 it looks like this happens for issues that have no sprints defined f.e image

If the issue has at least 1 sprint this doesn't happen

cbruno10 commented 1 year ago

Thanks for the info @juandspy ! Change LGTM