diff options
author | 6543 <6543@obermui.de> | 2022-01-05 05:51:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-05 05:51:12 +0100 |
commit | ec6cc38c6c26f95748be4a9041da2a9528e3625d (patch) | |
tree | 8ac98a32ab06fec2c92462e2af9de9c1b6d16c45 /vendor/code.gitea.io/sdk/gitea/user.go | |
parent | 8760af752abd94f050c6014c8cfa3cb6a6c854b7 (diff) | |
download | gitea-ec6cc38c6c26f95748be4a9041da2a9528e3625d.tar.gz gitea-ec6cc38c6c26f95748be4a9041da2a9528e3625d.zip |
code.gitea.io/sdk/gitea v0.14.0 -> v0.15.1 (#18186)
Diffstat (limited to 'vendor/code.gitea.io/sdk/gitea/user.go')
-rw-r--r-- | vendor/code.gitea.io/sdk/gitea/user.go | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/vendor/code.gitea.io/sdk/gitea/user.go b/vendor/code.gitea.io/sdk/gitea/user.go index 209523632d..c37627bfaa 100644 --- a/vendor/code.gitea.io/sdk/gitea/user.go +++ b/vendor/code.gitea.io/sdk/gitea/user.go @@ -6,6 +6,8 @@ package gitea import ( "fmt" + "net/url" + "strconv" "time" ) @@ -23,9 +25,30 @@ type User struct { // User locale Language string `json:"language"` // Is the user an administrator - IsAdmin bool `json:"is_admin"` - LastLogin time.Time `json:"last_login,omitempty"` - Created time.Time `json:"created,omitempty"` + IsAdmin bool `json:"is_admin"` + // Date and Time of last login + LastLogin time.Time `json:"last_login"` + // Date and Time of user creation + Created time.Time `json:"created"` + // Is user restricted + Restricted bool `json:"restricted"` + // Is user active + IsActive bool `json:"active"` + // Is user login prohibited + ProhibitLogin bool `json:"prohibit_login"` + // the user's location + Location string `json:"location"` + // the user's website + Website string `json:"website"` + // the user's description + Description string `json:"description"` + // User visibility level option + Visibility VisibleType `json:"visibility"` + + // user counts + FollowerCount int `json:"followers_count"` + FollowingCount int `json:"following_count"` + StarredRepoCount int `json:"starred_repos_count"` } // GetUserInfo get user info by user's name @@ -44,3 +67,24 @@ func (c *Client) GetMyUserInfo() (*User, *Response, error) { resp, err := c.getParsedResponse("GET", "/user", nil, nil, u) return u, resp, err } + +// GetUserByID returns user by a given user ID +func (c *Client) GetUserByID(id int64) (*User, *Response, error) { + if id < 0 { + return nil, nil, fmt.Errorf("invalid user id %d", id) + } + + query := make(url.Values) + query.Add("uid", strconv.FormatInt(id, 10)) + users, resp, err := c.searchUsers(query.Encode()) + + if err != nil { + return nil, resp, err + } + + if len(users) == 1 { + return users[0], resp, err + } + + return nil, resp, fmt.Errorf("user not found with id %d", id) +} |