1239fdee70
The transport was hand-rolled net/http against the REST API. The payload shapes were ours, in internal/wire, which meant every field Gitea learned was a field somebody here had to notice; and "does this instance have issue dependencies?" had to be guessed from a status code, because a 404 from a missing route and a 404 from a missing issue look alike. The SDK settles both. The shapes are maintained by the people who maintain the server, and the client negotiates the server's version when it is built, so the dependency endpoint is now gated on `>= 1.20.0` — verified against the release where the route appears, not assumed. Below the gate nothing is requested at all. internal/wire keeps what the SDK has no answer for: addressing. The SDK takes an owner, a name and an int64 and never parses, while `42`, `#42`, `owner/repo#42` and an issue URL are four spellings of one address, all four are what somebody has in hand, and Key is what the ledger is keyed by. The payload structs go. Four things that had to survive the move, and did: - request bodies still land in .kettle/payload/, now via an http.RoundTripper on the client the SDK is given — which is better than before, because it files every request rather than the ones a call site remembered to name; - errors still carry the HTTP status AND the response body, and a decode failure on a 2xx is deliberately not an APIError, so the dependency probe cannot read a bad decode as "feature missing"; - the number -> slug ledger is untouched, entries still outlive the files they name; - Client.For(repo) still re-points at another repository for one call. What it cost, written down in AGENTS.md where it happened. internal/mapping's layering test was a fact about the import graph — nothing in its closure could open a socket — and the SDK ships its types and its client in one package, so the test now asserts what is still true: the bridge performs no I/O, checked on direct imports plus a grep for time.Now. A run makes one extra request before it does anything. Gitea's issue edit endpoint carries no labels, so a push whose labels changed needs a second call; push makes it and says so. go.mod requires go 1.26, which the SDK sets and which is now the floor for building this binary. internal/issue and internal/project are byte-identical. The domain did not notice, which is the whole argument for the layering. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
96 lines
2.6 KiB
Go
96 lines
2.6 KiB
Go
// Copyright 2014 The Gogs Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package gitea
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
// User represents a user
|
|
type User struct {
|
|
// the user's id
|
|
ID int64 `json:"id"`
|
|
// the user's username
|
|
UserName string `json:"login"`
|
|
// The login_name of non local users (e.g. LDAP / OAuth / SMTP)
|
|
LoginName string `json:"login_name"`
|
|
// The ID of the Authentication Source for non local users.
|
|
SourceID int64 `json:"source_id"`
|
|
// the user's full name
|
|
FullName string `json:"full_name"`
|
|
Email string `json:"email"`
|
|
// URL to the user's avatar
|
|
AvatarURL string `json:"avatar_url"`
|
|
// URL to the user's profile
|
|
HTMLURL string `json:"html_url"`
|
|
// User locale
|
|
Language string `json:"language"`
|
|
// Is the user an administrator
|
|
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
|
|
func (c *Client) GetUserInfo(user string) (*User, *Response, error) {
|
|
if err := escapeValidatePathSegments(&user); err != nil {
|
|
return nil, nil, err
|
|
}
|
|
u := new(User)
|
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/users/%s", user), nil, nil, u)
|
|
return u, resp, err
|
|
}
|
|
|
|
// GetMyUserInfo get user info of current user
|
|
func (c *Client) GetMyUserInfo() (*User, *Response, error) {
|
|
u := new(User)
|
|
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)
|
|
}
|