-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
86 lines (76 loc) · 1.97 KB
/
Copy pathmain.go
File metadata and controls
86 lines (76 loc) · 1.97 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
package main
import (
"context"
"fmt"
"log"
gitcode "github.com/yi-nology/gitcode_api"
)
func main() {
client := gitcode.NewClient("your-gitcode-token")
ctx := context.Background()
// 获取当前用户
user, err := client.GetCurrentUser(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Printf("当前用户: %s (%s)\n", user.Name, user.Login)
// 列出仓库
repos, err := client.ListRepositories(ctx, gitcode.ListRepositoriesOptions{
ListOptions: gitcode.ListOptions{Page: 1, PerPage: 10},
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("\n仓库列表:\n")
for _, repo := range repos {
fmt.Printf("- %s (%s)\n", repo.FullName, repo.Description)
}
// 获取单个仓库
repo, err := client.GetRepository(ctx, "owner", "repo")
if err != nil {
log.Fatal(err)
}
fmt.Printf("\n仓库详情: %s\n", repo.FullName)
fmt.Printf(" 描述: %s\n", repo.Description)
fmt.Printf(" Stars: %d\n", repo.StarsCount)
// 列出分支
branches, err := client.ListBranches(ctx, "owner", "repo")
if err != nil {
log.Fatal(err)
}
fmt.Printf("\n分支列表:\n")
for _, branch := range branches {
fmt.Printf("- %s\n", branch.Name)
}
// 列出 Issue
issues, err := client.ListIssues(ctx, "owner", "repo", gitcode.ListIssuesOptions{
State: gitcode.IssueStateOpen,
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("\nIssue 列表:\n")
for _, issue := range issues {
fmt.Printf("#%d: %s\n", int(issue.Number), issue.Title)
}
// 列出 Pull Request
prs, err := client.ListPullRequests(ctx, "owner", "repo", gitcode.ListPullRequestsOptions{
State: gitcode.PullRequestStateOpen,
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("\nPull Request 列表:\n")
for _, pr := range prs {
fmt.Printf("#%d: %s\n", pr.Number, pr.Title)
}
// 列出 Webhook
hooks, err := client.ListWebhooks(ctx, "owner", "repo")
if err != nil {
log.Fatal(err)
}
fmt.Printf("\nWebhook 列表:\n")
for _, hook := range hooks {
fmt.Printf("- %s (active: %v)\n", hook.URL, hook.Active)
}
}