2026-02-21 15:43:14 +00:00
|
|
|
package forge
|
|
|
|
|
|
2026-04-02 07:35:37 +00:00
|
|
|
import "net/http"
|
|
|
|
|
|
2026-02-21 15:43:14 +00:00
|
|
|
// Forge is the top-level client for the Forgejo API.
|
2026-03-26 18:00:20 +00:00
|
|
|
//
|
|
|
|
|
// Usage:
|
|
|
|
|
//
|
2026-04-02 07:22:52 +00:00
|
|
|
// ctx := context.Background()
|
2026-03-26 18:00:20 +00:00
|
|
|
// f := forge.NewForge("https://forge.lthn.ai", "token")
|
2026-04-02 07:22:52 +00:00
|
|
|
// repo, err := f.Repos.Get(ctx, forge.Params{"owner": "core", "repo": "go-forge"})
|
2026-02-21 15:43:14 +00:00
|
|
|
type Forge struct {
|
|
|
|
|
client *Client
|
2026-02-21 15:46:10 +00:00
|
|
|
|
|
|
|
|
Repos *RepoService
|
|
|
|
|
Issues *IssueService
|
|
|
|
|
Pulls *PullService
|
|
|
|
|
Orgs *OrgService
|
|
|
|
|
Users *UserService
|
|
|
|
|
Teams *TeamService
|
|
|
|
|
Admin *AdminService
|
|
|
|
|
Branches *BranchService
|
|
|
|
|
Releases *ReleaseService
|
|
|
|
|
Labels *LabelService
|
|
|
|
|
Webhooks *WebhookService
|
|
|
|
|
Notifications *NotificationService
|
|
|
|
|
Packages *PackageService
|
|
|
|
|
Actions *ActionsService
|
|
|
|
|
Contents *ContentService
|
|
|
|
|
Wiki *WikiService
|
|
|
|
|
Misc *MiscService
|
2026-02-21 16:11:29 +00:00
|
|
|
Commits *CommitService
|
2026-03-23 12:53:10 +00:00
|
|
|
Milestones *MilestoneService
|
2026-04-02 02:04:26 +00:00
|
|
|
ActivityPub *ActivityPubService
|
2026-02-21 15:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewForge creates a new Forge client.
|
2026-03-26 18:00:20 +00:00
|
|
|
//
|
|
|
|
|
// Usage:
|
|
|
|
|
//
|
2026-04-02 07:22:52 +00:00
|
|
|
// ctx := context.Background()
|
2026-03-26 18:00:20 +00:00
|
|
|
// f := forge.NewForge("https://forge.lthn.ai", "token")
|
2026-04-02 07:22:52 +00:00
|
|
|
// repos, err := f.Repos.ListOrgRepos(ctx, "core")
|
2026-02-21 15:43:14 +00:00
|
|
|
func NewForge(url, token string, opts ...Option) *Forge {
|
|
|
|
|
c := NewClient(url, token, opts...)
|
2026-02-21 15:46:10 +00:00
|
|
|
f := &Forge{client: c}
|
|
|
|
|
f.Repos = newRepoService(c)
|
2026-02-21 15:50:22 +00:00
|
|
|
f.Issues = newIssueService(c)
|
|
|
|
|
f.Pulls = newPullService(c)
|
2026-02-21 15:53:29 +00:00
|
|
|
f.Orgs = newOrgService(c)
|
|
|
|
|
f.Users = newUserService(c)
|
|
|
|
|
f.Teams = newTeamService(c)
|
2026-02-21 15:57:09 +00:00
|
|
|
f.Admin = newAdminService(c)
|
2026-02-21 15:59:43 +00:00
|
|
|
f.Branches = newBranchService(c)
|
|
|
|
|
f.Releases = newReleaseService(c)
|
2026-02-21 16:03:46 +00:00
|
|
|
f.Labels = newLabelService(c)
|
|
|
|
|
f.Webhooks = newWebhookService(c)
|
2026-02-21 16:07:43 +00:00
|
|
|
f.Notifications = newNotificationService(c)
|
|
|
|
|
f.Packages = newPackageService(c)
|
|
|
|
|
f.Actions = newActionsService(c)
|
2026-02-21 16:03:46 +00:00
|
|
|
f.Contents = newContentService(c)
|
2026-02-21 16:11:29 +00:00
|
|
|
f.Wiki = newWikiService(c)
|
|
|
|
|
f.Misc = newMiscService(c)
|
|
|
|
|
f.Commits = newCommitService(c)
|
2026-03-23 12:53:10 +00:00
|
|
|
f.Milestones = newMilestoneService(c)
|
2026-04-02 02:04:26 +00:00
|
|
|
f.ActivityPub = newActivityPubService(c)
|
2026-02-21 15:46:10 +00:00
|
|
|
return f
|
2026-02-21 15:43:14 +00:00
|
|
|
}
|
2026-02-21 15:46:10 +00:00
|
|
|
|
|
|
|
|
// Client returns the underlying HTTP client.
|
2026-04-02 07:19:20 +00:00
|
|
|
//
|
|
|
|
|
// Usage:
|
|
|
|
|
//
|
|
|
|
|
// client := f.Client()
|
2026-02-21 15:46:10 +00:00
|
|
|
func (f *Forge) Client() *Client { return f.client }
|
2026-04-02 07:26:13 +00:00
|
|
|
|
|
|
|
|
// BaseURL returns the configured Forgejo base URL.
|
|
|
|
|
//
|
|
|
|
|
// Usage:
|
|
|
|
|
//
|
|
|
|
|
// baseURL := f.BaseURL()
|
|
|
|
|
func (f *Forge) BaseURL() string { return f.client.BaseURL() }
|
|
|
|
|
|
|
|
|
|
// RateLimit returns the last known rate limit information.
|
|
|
|
|
//
|
|
|
|
|
// Usage:
|
|
|
|
|
//
|
|
|
|
|
// rl := f.RateLimit()
|
|
|
|
|
func (f *Forge) RateLimit() RateLimit { return f.client.RateLimit() }
|
2026-04-02 07:29:00 +00:00
|
|
|
|
|
|
|
|
// UserAgent returns the configured User-Agent header value.
|
|
|
|
|
//
|
|
|
|
|
// Usage:
|
|
|
|
|
//
|
|
|
|
|
// ua := f.UserAgent()
|
|
|
|
|
func (f *Forge) UserAgent() string { return f.client.UserAgent() }
|
2026-04-02 07:31:56 +00:00
|
|
|
|
2026-04-02 07:35:37 +00:00
|
|
|
// HTTPClient returns the configured underlying HTTP client.
|
|
|
|
|
//
|
|
|
|
|
// Usage:
|
|
|
|
|
//
|
|
|
|
|
// hc := f.HTTPClient()
|
|
|
|
|
func (f *Forge) HTTPClient() *http.Client { return f.client.HTTPClient() }
|
|
|
|
|
|
2026-04-02 07:31:56 +00:00
|
|
|
// HasToken reports whether the Forge client was configured with an API token.
|
|
|
|
|
//
|
|
|
|
|
// Usage:
|
|
|
|
|
//
|
|
|
|
|
// if f.HasToken() {
|
|
|
|
|
// _ = "authenticated"
|
|
|
|
|
// }
|
|
|
|
|
func (f *Forge) HasToken() bool { return f.client.HasToken() }
|
2026-04-02 07:46:05 +00:00
|
|
|
|
|
|
|
|
// String returns a safe summary of the Forge client.
|
|
|
|
|
//
|
|
|
|
|
// Usage:
|
|
|
|
|
//
|
|
|
|
|
// s := f.String()
|
|
|
|
|
func (f *Forge) String() string {
|
2026-04-02 07:54:28 +00:00
|
|
|
if f == nil {
|
|
|
|
|
return "forge.Forge{<nil>}"
|
|
|
|
|
}
|
|
|
|
|
if f.client == nil {
|
|
|
|
|
return "forge.Forge{client=<nil>}"
|
|
|
|
|
}
|
2026-04-02 07:46:05 +00:00
|
|
|
return "forge.Forge{" + f.client.String() + "}"
|
|
|
|
|
}
|
2026-04-02 07:48:37 +00:00
|
|
|
|
|
|
|
|
// GoString returns a safe Go-syntax summary of the Forge client.
|
|
|
|
|
//
|
|
|
|
|
// Usage:
|
|
|
|
|
//
|
|
|
|
|
// s := fmt.Sprintf("%#v", f)
|
|
|
|
|
func (f *Forge) GoString() string { return f.String() }
|