feat(forge): expose user agent metadata
Some checks failed
Security Scan / security (push) Successful in 15s
Test / test (push) Has been cancelled

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 07:29:00 +00:00
parent 84d7c6a796
commit 933dc982f7
5 changed files with 29 additions and 0 deletions

View file

@ -141,6 +141,15 @@ func (c *Client) RateLimit() RateLimit {
return c.rateLimit
}
// UserAgent returns the configured User-Agent header value.
//
// Usage:
//
// ua := client.UserAgent()
func (c *Client) UserAgent() string {
return c.userAgent
}
// NewClient creates a new Forgejo API client.
//
// Usage:

View file

@ -195,6 +195,9 @@ func TestClient_Options_Good(t *testing.T) {
if c.userAgent != "go-forge/1.0" {
t.Errorf("got user agent=%q", c.userAgent)
}
if got := c.UserAgent(); got != "go-forge/1.0" {
t.Errorf("got UserAgent()=%q", got)
}
}
func TestClient_WithHTTPClient_Good(t *testing.T) {

View file

@ -98,6 +98,7 @@ Coverage notes: rows list direct tests when a symbol is named in test names or r
| method | Client.PostRaw | `func (c *Client) PostRaw(ctx context.Context, path string, body any) ([]byte, error)` | PostRaw performs a POST request with a JSON body and returns the raw response body as bytes instead of JSON-decoding. Useful for endpoints such as /markdown that return raw HTML text. | No direct tests. |
| method | Client.Put | `func (c *Client) Put(ctx context.Context, path string, body, out any) error` | Put performs a PUT request. | No direct tests. |
| method | Client.RateLimit | `func (c *Client) RateLimit() RateLimit` | RateLimit returns the last known rate limit information. | `TestClient_Good_RateLimit` |
| method | Client.UserAgent | `func (c *Client) UserAgent() string` | UserAgent returns the configured User-Agent header value. | `TestClient_Good_Options` |
| method | CommitService.CreateStatus | `func (s *CommitService) CreateStatus(ctx context.Context, owner, repo, sha string, opts *types.CreateStatusOption) (*types.CommitStatus, error)` | CreateStatus creates a new commit status for the given SHA. | `TestCommitService_Good_CreateStatus` |
| method | CommitService.Get | `func (s *CommitService) Get(ctx context.Context, params Params) (*types.Commit, error)` | Get returns a single commit by SHA or ref. | `TestCommitService_Good_Get`, `TestCommitService_Good_List` |
| method | CommitService.GetCombinedStatus | `func (s *CommitService) GetCombinedStatus(ctx context.Context, owner, repo, ref string) (*types.CombinedStatus, error)` | GetCombinedStatus returns the combined status for a given ref (branch, tag, or SHA). | `TestCommitService_Good_GetCombinedStatus` |
@ -112,6 +113,8 @@ Coverage notes: rows list direct tests when a symbol is named in test names or r
| method | ContentService.GetRawFile | `func (s *ContentService) GetRawFile(ctx context.Context, owner, repo, filepath string) ([]byte, error)` | GetRawFile returns the raw file content as bytes. | `TestContentService_Bad_GetRawNotFound`, `TestContentService_Good_GetRawFile` |
| method | ContentService.UpdateFile | `func (s *ContentService) UpdateFile(ctx context.Context, owner, repo, filepath string, opts *types.UpdateFileOptions) (*types.FileResponse, error)` | UpdateFile updates an existing file in a repository. | `TestContentService_Good_UpdateFile` |
| method | Forge.Client | `func (f *Forge) Client() *Client` | Client returns the underlying HTTP client. | `TestForge_Good_Client` |
| method | Forge.RateLimit | `func (f *Forge) RateLimit() RateLimit` | RateLimit returns the last known rate limit information. | `TestForge_Good_RateLimit` |
| method | Forge.UserAgent | `func (f *Forge) UserAgent() string` | UserAgent returns the configured User-Agent header value. | `TestForge_Good_UserAgent` |
| method | IssueService.AddLabels | `func (s *IssueService) AddLabels(ctx context.Context, owner, repo string, index int64, labelIDs []int64) error` | AddLabels adds labels to an issue. | No direct tests. |
| method | IssueService.AddReaction | `func (s *IssueService) AddReaction(ctx context.Context, owner, repo string, index int64, reaction string) error` | AddReaction adds a reaction to an issue. | No direct tests. |
| method | IssueService.CreateComment | `func (s *IssueService) CreateComment(ctx context.Context, owner, repo string, index int64, body string) (*types.Comment, error)` | CreateComment creates a comment on an issue. | `TestIssueService_Good_CreateComment` |

View file

@ -85,3 +85,10 @@ func (f *Forge) BaseURL() string { return f.client.BaseURL() }
//
// rl := f.RateLimit()
func (f *Forge) RateLimit() RateLimit { return f.client.RateLimit() }
// UserAgent returns the configured User-Agent header value.
//
// Usage:
//
// ua := f.UserAgent()
func (f *Forge) UserAgent() string { return f.client.UserAgent() }

View file

@ -52,6 +52,13 @@ func TestForge_RateLimit_Good(t *testing.T) {
}
}
func TestForge_UserAgent_Good(t *testing.T) {
f := NewForge("https://forge.lthn.ai", "tok", WithUserAgent("go-forge/1.0"))
if got := f.UserAgent(); got != "go-forge/1.0" {
t.Fatalf("got user agent %q", got)
}
}
func TestRepoService_ListOrgRepos_Good(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {