From 76837c0ea4b9b9a011e7bb04d79e3d20caf1a45c Mon Sep 17 00:00:00 2001 From: Martin Hebnes Pedersen Date: Thu, 15 Dec 2016 17:13:48 +0100 Subject: [PATCH] Backward compatibility (username vs. login) Reintroduce the username field for user object on JSON marshal to fix backward compatibility. Fixes Drone 0.4 compatibility issues. --- gitea/user.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gitea/user.go b/gitea/user.go index 2560d85..967d8b5 100644 --- a/gitea/user.go +++ b/gitea/user.go @@ -5,6 +5,7 @@ package gitea import ( + "encoding/json" "fmt" ) @@ -17,6 +18,16 @@ type User struct { AvatarURL string `json:"avatar_url"` } +// MarshalJSON implements the json.Marshaler interface for User, adding field(s) for backward compatibility +func (u User) MarshalJSON() ([]byte, error) { + // Re-declaring User to avoid recursion + type shadow User + return json.Marshal(struct { + shadow + CompatUserName string `json:"username"` + }{shadow(u), u.UserName}) +} + // GetUserInfo get user info by user's name func (c *Client) GetUserInfo(user string) (*User, error) { u := new(User)