-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforge.go
More file actions
164 lines (152 loc) · 3.6 KB
/
forge.go
File metadata and controls
164 lines (152 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package forge
import "net/http"
// Forge is the top-level client for the Forgejo API.
//
// Usage:
//
// ctx := context.Background()
// f := forge.NewForge("https://forge.lthn.ai", "token")
// repo, err := f.Repos.Get(ctx, forge.Params{"owner": "core", "repo": "go-forge"})
type Forge struct {
client *Client
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
Commits *CommitService
Milestones *MilestoneService
ActivityPub *ActivityPubService
}
// NewForge creates a new Forge client.
//
// Usage:
//
// ctx := context.Background()
// f := forge.NewForge("https://forge.lthn.ai", "token")
// repos, err := f.Repos.ListOrgRepos(ctx, "core")
func NewForge(url, token string, opts ...Option) *Forge {
c := NewClient(url, token, opts...)
f := &Forge{client: c}
f.Repos = newRepoService(c)
f.Issues = newIssueService(c)
f.Pulls = newPullService(c)
f.Orgs = newOrgService(c)
f.Users = newUserService(c)
f.Teams = newTeamService(c)
f.Admin = newAdminService(c)
f.Branches = newBranchService(c)
f.Releases = newReleaseService(c)
f.Labels = newLabelService(c)
f.Webhooks = newWebhookService(c)
f.Notifications = newNotificationService(c)
f.Packages = newPackageService(c)
f.Actions = newActionsService(c)
f.Contents = newContentService(c)
f.Wiki = newWikiService(c)
f.Misc = newMiscService(c)
f.Commits = newCommitService(c)
f.Milestones = newMilestoneService(c)
f.ActivityPub = newActivityPubService(c)
return f
}
// Client returns the underlying Forge client.
//
// Usage:
//
// client := f.Client()
func (f *Forge) Client() *Client {
if f == nil {
return nil
}
return f.client
}
// BaseURL returns the configured Forgejo base URL.
//
// Usage:
//
// baseURL := f.BaseURL()
func (f *Forge) BaseURL() string {
if f == nil || f.client == nil {
return ""
}
return f.client.BaseURL()
}
// RateLimit returns the last known rate limit information.
//
// Usage:
//
// rl := f.RateLimit()
func (f *Forge) RateLimit() RateLimit {
if f == nil || f.client == nil {
return RateLimit{}
}
return f.client.RateLimit()
}
// UserAgent returns the configured User-Agent header value.
//
// Usage:
//
// ua := f.UserAgent()
func (f *Forge) UserAgent() string {
if f == nil || f.client == nil {
return ""
}
return f.client.UserAgent()
}
// HTTPClient returns the configured underlying HTTP client.
//
// Usage:
//
// hc := f.HTTPClient()
func (f *Forge) HTTPClient() *http.Client {
if f == nil || f.client == nil {
return nil
}
return f.client.HTTPClient()
}
// HasToken reports whether the Forge client was configured with an API token.
//
// Usage:
//
// if f.HasToken() {
// _ = "authenticated"
// }
func (f *Forge) HasToken() bool {
if f == nil || f.client == nil {
return false
}
return f.client.HasToken()
}
// String returns a safe summary of the Forge client.
//
// Usage:
//
// s := f.String()
func (f *Forge) String() string {
if f == nil {
return "forge.Forge{<nil>}"
}
if f.client == nil {
return "forge.Forge{client=<nil>}"
}
return "forge.Forge{client=" + f.client.String() + "}"
}
// 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() }