Compare commits

...

6 Commits

Author SHA1 Message Date
Andrew Nester 9c7d2a238f
Merge 68e27f2eed into 0753dfe2f4 2024-10-15 13:15:34 +00:00
Andrew Nester 0753dfe2f4
Fixed unmarshalling json input into `interface{}` type (#1832)
## Changes
Fixed unmarshalling json input into `interface{}` type

Commands like `api post` support free form request input, so it should
be unmarshaled correctly

## Tests
Added regression test + E2E test pass
2024-10-15 12:10:02 +00:00
Andrew Nester 68e27f2eed
Merge branch 'main' into close-stale-issues 2023-12-29 14:36:51 +01:00
Andrew Nester d58624b644
Use latest version 2023-09-06 10:37:38 +02:00
Andrew Nester 555f635058
Use actions/stale and make close periods longer 2023-09-06 10:29:55 +02:00
Andrew Nester 7cf99715c0
Added close stale issues workflow 2023-08-03 12:00:10 +02:00
3 changed files with 58 additions and 14 deletions

View File

@ -0,0 +1,34 @@
name: "Close Stale Issues"
# Controls when the action will run.
on:
workflow_dispatch:
schedule:
- cron: "0 */4 * * *"
jobs:
cleanup:
permissions:
issues: write
contents: read
pull-requests: write
runs-on: ubuntu-latest
name: Stale issue job
steps:
- uses: actions/stale@v8
with:
issue-types: issues
stale-issue-message: This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.
# These labels are required
stale-issue-label: Stale
exempt-issue-labels: No Autoclose
# Issue timing
days-before-stale: 30
days-before-close: 7
repo-token: ${{ secrets.GITHUB_TOKEN }}
loglevel: DEBUG
# Set dry-run to true to not perform label or close actions.
dry-run: false

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"reflect"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn/convert"
@ -63,12 +64,25 @@ func (j *JsonFlag) Unmarshal(v any) diag.Diagnostics {
return diags.Extend(diag.FromErr(err))
}
kind := reflect.ValueOf(v).Kind()
if kind == reflect.Ptr {
kind = reflect.ValueOf(v).Elem().Kind()
}
if kind == reflect.Struct {
// Finally unmarshal the normalized data to the output.
// It will fill in the ForceSendFields field if the struct contains it.
err = marshal.Unmarshal(data, v)
if err != nil {
return diags.Extend(diag.FromErr(err))
}
} else {
// If the output is not a struct, just unmarshal the data to the output.
err = json.Unmarshal(data, v)
if err != nil {
return diags.Extend(diag.FromErr(err))
}
}
return diags
}

View File

@ -13,10 +13,6 @@ import (
"github.com/stretchr/testify/require"
)
type requestType struct {
Foo string `json:"foo"`
}
func TestJsonFlagEmpty(t *testing.T) {
var body JsonFlag
@ -35,13 +31,13 @@ func TestJsonFlagInline(t *testing.T) {
err := body.Set(`{"foo": "bar"}`)
assert.NoError(t, err)
var request requestType
var request any
diags := body.Unmarshal(&request)
assert.NoError(t, diags.Error())
assert.Empty(t, diags)
assert.Equal(t, "JSON (14 bytes)", body.String())
assert.Equal(t, requestType{"bar"}, request)
assert.Equal(t, map[string]any{"foo": "bar"}, request)
}
func TestJsonFlagError(t *testing.T) {
@ -50,7 +46,7 @@ func TestJsonFlagError(t *testing.T) {
err := body.Set(`{"foo":`)
assert.NoError(t, err)
var request requestType
var request any
diags := body.Unmarshal(&request)
assert.EqualError(t, diags.Error(), "error decoding JSON at (inline):1:8: unexpected end of JSON input")
assert.Equal(t, "JSON (7 bytes)", body.String())
@ -58,7 +54,7 @@ func TestJsonFlagError(t *testing.T) {
func TestJsonFlagFile(t *testing.T) {
var body JsonFlag
var request requestType
var request any
var fpath string
var payload = []byte(`{"foo": "bar"}`)
@ -78,7 +74,7 @@ func TestJsonFlagFile(t *testing.T) {
assert.NoError(t, diags.Error())
assert.Empty(t, diags)
assert.Equal(t, requestType{"bar"}, request)
assert.Equal(t, map[string]any{"foo": "bar"}, request)
}
const jsonData = `