Gitea Go SDK
Overview
The official Go SDK for Gitea provides 332+ API methods with full type safety. Use it for bots, automation, integrations, and complex workflows. For quick CLI operations, use gitea:tea-cli instead.
Quick Setup
import "code.gitea.io/sdk/gitea"
// Create client
client, err := gitea.NewClient(
"https://gitea.example.com",
gitea.SetToken("your-token"),
)
go get code.gitea.io/sdk/gitea
See references/authentication.md in tea-cli for token creation.
Quick Reference
| Task |
Method |
| Repos |
|
| List my repos |
client.ListMyRepos(ListReposOptions{}) |
| Get repo |
client.GetRepo(owner, repo) |
| Create repo |
client.CreateRepo(CreateRepoOption{}) |
| Issues |
|
| List issues |
client.ListRepoIssues(owner, repo, ListIssueOption{}) |
| Create issue |
client.CreateIssue(owner, repo, CreateIssueOption{}) |
| Edit issue |
client.EditIssue(owner, repo, index, EditIssueOption{}) |
| PRs |
|
| List PRs |
client.ListRepoPullRequests(owner, repo, ListPullRequestsOptions{}) |
| Create PR |
client.CreatePullRequest(owner, repo, CreatePullRequestOption{}) |
| Merge PR |
client.MergePullRequest(owner, repo, index, MergePullRequestOption{}) |
| Releases |
|
| List releases |
client.ListReleases(owner, repo, ListReleasesOptions{}) |
| Create release |
client.CreateRelease(owner, repo, CreateReleaseOption{}) |
API Categories
See references/api-reference.md for complete method list:
- Repositories (70+ methods)
- Issues & comments (50+ methods)
- Pull requests & reviews (40+ methods)
- Releases & attachments
- Organizations & teams
- Users, webhooks, actions
Common Types
See references/types.md for struct definitions:
Repository, Issue, PullRequest, Release
User, Organization, Team
ListOptions for pagination
- Option structs for create/edit
Patterns
See references/examples.md for idiomatic patterns:
- Error handling
- Pagination
- Context usage
- Webhook handlers
Authentication Options
// Token auth (recommended)
client, _ := gitea.NewClient(url, gitea.SetToken(token))
// Basic auth
client, _ := gitea.NewClient(url, gitea.SetBasicAuth(user, pass))
// With 2FA
client, _ := gitea.NewClient(url,
gitea.SetBasicAuth(user, pass),
gitea.SetOTP(otp),
)
// SSH key
client, _ := gitea.NewClient(url,
gitea.UseSSHPubkey(fingerprint, keyPath, passphrase),
)
Common Patterns
// Pagination
opts := gitea.ListOptions{Page: 1, PageSize: 50}
for {
repos, resp, _ := client.ListMyRepos(gitea.ListReposOptions{ListOptions: opts})
// process repos...
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}
// Context support
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
client.SetContext(ctx)
Common Mistakes
| Problem |
Solution |
| Nil pointer panic |
Always check error before using result |
| Missing pagination |
Use resp.NextPage to get all results |
| Context timeout |
Set appropriate timeout for bulk operations |
| Rate limiting |
Check resp.Header for rate limit info |
1---2name: go-sdk3description: Use when writing Go code to interact with Gitea API - automation, bots, integrations, migrations, or programmatic git forge operations4---5
6# Gitea Go SDK
7
8## Overview
9
10The official Go SDK for Gitea provides 332+ API methods with full type safety. Use it for bots, automation, integrations, and complex workflows. For quick CLI operations, use `gitea:tea-cli` instead.
11
12## Quick Setup
13
14```go
15import "code.gitea.io/sdk/gitea"
16
17// Create client
18client, err := gitea.NewClient(
19 "https://gitea.example.com",
20 gitea.SetToken("your-token"),
21)
22```
23
24```bash
25go get code.gitea.io/sdk/gitea
26```
27
28See `references/authentication.md` in tea-cli for token creation.
29
30## Quick Reference
31
32| Task | Method |
33|------|--------|
34| **Repos** | |
35| List my repos | `client.ListMyRepos(ListReposOptions{})` |
36| Get repo | `client.GetRepo(owner, repo)` |
37| Create repo | `client.CreateRepo(CreateRepoOption{})` |
38| **Issues** | |
39| List issues | `client.ListRepoIssues(owner, repo, ListIssueOption{})` |
40| Create issue | `client.CreateIssue(owner, repo, CreateIssueOption{})` |
41| Edit issue | `client.EditIssue(owner, repo, index, EditIssueOption{})` |
42| **PRs** | |
43| List PRs | `client.ListRepoPullRequests(owner, repo, ListPullRequestsOptions{})` |
44| Create PR | `client.CreatePullRequest(owner, repo, CreatePullRequestOption{})` |
45| Merge PR | `client.MergePullRequest(owner, repo, index, MergePullRequestOption{})` |
46| **Releases** | |
47| List releases | `client.ListReleases(owner, repo, ListReleasesOptions{})` |
48| Create release | `client.CreateRelease(owner, repo, CreateReleaseOption{})` |
49
50## API Categories
51
52See `references/api-reference.md` for complete method list:
53- Repositories (70+ methods)
54- Issues & comments (50+ methods)
55- Pull requests & reviews (40+ methods)
56- Releases & attachments
57- Organizations & teams
58- Users, webhooks, actions
59
60## Common Types
61
62See `references/types.md` for struct definitions:
63- `Repository`, `Issue`, `PullRequest`, `Release`
64- `User`, `Organization`, `Team`
65- `ListOptions` for pagination
66- Option structs for create/edit
67
68## Patterns
69
70See `references/examples.md` for idiomatic patterns:
71- Error handling
72- Pagination
73- Context usage
74- Webhook handlers
75
76## Authentication Options
77
78```go
79// Token auth (recommended)
80client, _ := gitea.NewClient(url, gitea.SetToken(token))
81
82// Basic auth
83client, _ := gitea.NewClient(url, gitea.SetBasicAuth(user, pass))
84
85// With 2FA
86client, _ := gitea.NewClient(url,
87 gitea.SetBasicAuth(user, pass),
88 gitea.SetOTP(otp),
89)
90
91// SSH key
92client, _ := gitea.NewClient(url,
93 gitea.UseSSHPubkey(fingerprint, keyPath, passphrase),
94)
95```
96
97## Common Patterns
98
99```go
100// Pagination
101opts := gitea.ListOptions{Page: 1, PageSize: 50}
102for {
103 repos, resp, _ := client.ListMyRepos(gitea.ListReposOptions{ListOptions: opts})
104 // process repos...
105 if resp.NextPage == 0 {
106 break
107 }
108 opts.Page = resp.NextPage
109}
110
111// Context support
112ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
113defer cancel()
114client.SetContext(ctx)
115```
116
117## Common Mistakes
118
119| Problem | Solution |
120|---------|----------|
121| Nil pointer panic | Always check error before using result |
122| Missing pagination | Use `resp.NextPage` to get all results |
123| Context timeout | Set appropriate timeout for bulk operations |
124| Rate limiting | Check `resp.Header` for rate limit info |