Skip to content

Commit

Permalink
improve dataspec usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dobarx committed Nov 22, 2024
1 parent 4ae4cc4 commit 45373c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/plugins/atlassian/data-sources/jira_issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ data jira_issues {
# Optional list of string.
# Must have a length of at most 5
# Default value:
properties = null
properties = []
# Size limit to retrieve.
#
Expand Down
24 changes: 9 additions & 15 deletions internal/atlassian/data_jira_issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package atlassian

import (
"context"
"fmt"

"github.com/hashicorp/hcl/v2"
"github.com/zclconf/go-cty/cty"
Expand Down Expand Up @@ -76,6 +75,7 @@ func makeJiraIssuesDataSource(loader ClientLoadFn) *plugin.DataSource {
Type: cty.List(cty.String),
Doc: "A list of up to 5 issue properties to include in the results.",
MaxInclusive: cty.NumberIntVal(5),
DefaultVal: cty.ListValEmpty(cty.String),
},
{
Name: "size",
Expand Down Expand Up @@ -106,11 +106,10 @@ func searchJiraIssuesData(loader ClientLoadFn) plugin.RetrieveDataFunc {
Summary: "Failed to parse arguments",
}}
}
size := 0
if attr := params.Args.GetAttrVal("size"); !attr.IsNull() {
num, _ := attr.AsBigFloat().Int64()
size = int(num)
}

num, _ := params.Args.GetAttrVal("size").AsBigFloat().Int64()
size := int(num)

var issues plugindata.List
for {
res, err := cli.SearchIssues(ctx, req)
Expand Down Expand Up @@ -140,9 +139,6 @@ func searchJiraIssuesData(loader ClientLoadFn) plugin.RetrieveDataFunc {
}

func parseSearchIssuesReq(args *dataspec.Block) (*client.SearchIssuesReq, error) {
if args == nil {
return nil, fmt.Errorf("arguments are required")
}
req := &client.SearchIssuesReq{}
if attr := args.GetAttrVal("expand"); !attr.IsNull() {
req.Expand = client.String(attr.AsString())
Expand All @@ -158,13 +154,11 @@ func parseSearchIssuesReq(args *dataspec.Block) (*client.SearchIssuesReq, error)
req.Fields = append(req.Fields, field.AsString())
}
}
if attr := args.GetAttrVal("properties"); !attr.IsNull() {
for _, property := range attr.AsValueSlice() {
if property.IsNull() {
continue
}
req.Properties = append(req.Properties, property.AsString())
for _, property := range args.GetAttrVal("properties").AsValueSlice() {
if property.IsNull() {
continue
}
req.Properties = append(req.Properties, property.AsString())
}
return req, nil
}

0 comments on commit 45373c8

Please sign in to comment.