types: restore mispelled json field for backwards compat #815

merged
opened by oppi.li targeting master from op/xurkpxuzwzlo

both spellings are supported.

Signed-off-by: oppiliappan me@oppi.li

Changed files
+21
types
+21
types/repo.go
···
package types
import (
"github.com/bluekeyes/go-gitdiff/gitdiff"
"github.com/go-git/go-git/v5/plumbing/object"
)
···
IsDefault bool `json:"is_default,omitempty"`
}
type RepoTagsResponse struct {
Tags []*TagReference `json:"tags,omitempty"`
}
···
package types
import (
+
"encoding/json"
+
"github.com/bluekeyes/go-gitdiff/gitdiff"
"github.com/go-git/go-git/v5/plumbing/object"
)
···
IsDefault bool `json:"is_default,omitempty"`
}
+
func (b *Branch) UnmarshalJSON(data []byte) error {
+
aux := &struct {
+
Reference `json:"reference"`
+
Commit *object.Commit `json:"commit,omitempty"`
+
IsDefault bool `json:"is_default,omitempty"`
+
MispelledIsDefault bool `json:"is_deafult,omitempty"` // mispelled name
+
}{}
+
+
if err := json.Unmarshal(data, aux); err != nil {
+
return err
+
}
+
+
b.Reference = aux.Reference
+
b.Commit = aux.Commit
+
b.IsDefault = aux.IsDefault || aux.MispelledIsDefault // whichever was set
+
+
return nil
+
}
+
type RepoTagsResponse struct {
Tags []*TagReference `json:"tags,omitempty"`
}