mirror of
https://gitea.com/gitea/tea.git
synced 2026-04-25 17:53:37 +02:00
Compare commits
1 Commits
lunny/fix_
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5103496232 |
@@ -61,11 +61,19 @@ func runReleaseAttachmentDelete(_ stdctx.Context, cmd *cli.Command) error {
|
||||
return err
|
||||
}
|
||||
|
||||
existing, _, err := client.ListReleaseAttachments(ctx.Owner, ctx.Repo, release.ID, gitea.ListReleaseAttachmentsOptions{
|
||||
ListOptions: gitea.ListOptions{Page: -1},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
var existing []*gitea.Attachment
|
||||
for page := 1; ; {
|
||||
page_attachments, resp, err := client.ListReleaseAttachments(ctx.Owner, ctx.Repo, release.ID, gitea.ListReleaseAttachmentsOptions{
|
||||
ListOptions: gitea.ListOptions{Page: page, PageSize: 50},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
existing = append(existing, page_attachments...)
|
||||
if resp == nil || resp.NextPage == 0 {
|
||||
break
|
||||
}
|
||||
page = resp.NextPage
|
||||
}
|
||||
|
||||
for _, name := range ctx.Args().Slice()[1:] {
|
||||
|
||||
19
cmd/pulls.go
19
cmd/pulls.go
@@ -109,11 +109,20 @@ func runPullDetail(_ stdctx.Context, cmd *cli.Command, index string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
reviews, _, err := client.ListPullReviews(ctx.Owner, ctx.Repo, idx, gitea.ListPullReviewsOptions{
|
||||
ListOptions: gitea.ListOptions{Page: -1},
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("error while loading reviews: %v\n", err)
|
||||
var reviews []*gitea.PullReview
|
||||
for page := 1; ; {
|
||||
page_reviews, resp, err := client.ListPullReviews(ctx.Owner, ctx.Repo, idx, gitea.ListPullReviewsOptions{
|
||||
ListOptions: gitea.ListOptions{Page: page, PageSize: 50},
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Printf("error while loading reviews: %v\n", err)
|
||||
break
|
||||
}
|
||||
reviews = append(reviews, page_reviews...)
|
||||
if resp == nil || resp.NextPage == 0 {
|
||||
break
|
||||
}
|
||||
page = resp.NextPage
|
||||
}
|
||||
|
||||
if ctx.IsSet("output") {
|
||||
|
||||
@@ -11,19 +11,25 @@ import (
|
||||
|
||||
// GetReleaseByTag finds a release by its tag name.
|
||||
func GetReleaseByTag(owner, repo, tag string, client *gitea.Client) (*gitea.Release, error) {
|
||||
rl, _, err := client.ListReleases(owner, repo, gitea.ListReleasesOptions{
|
||||
ListOptions: gitea.ListOptions{Page: -1},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(rl) == 0 {
|
||||
return nil, fmt.Errorf("repo does not have any release")
|
||||
}
|
||||
for _, r := range rl {
|
||||
if r.TagName == tag {
|
||||
return r, nil
|
||||
for page := 1; ; {
|
||||
rl, resp, err := client.ListReleases(owner, repo, gitea.ListReleasesOptions{
|
||||
ListOptions: gitea.ListOptions{Page: page, PageSize: 50},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if page == 1 && len(rl) == 0 {
|
||||
return nil, fmt.Errorf("repo does not have any release")
|
||||
}
|
||||
for _, r := range rl {
|
||||
if r.TagName == tag {
|
||||
return r, nil
|
||||
}
|
||||
}
|
||||
if resp == nil || resp.NextPage == 0 {
|
||||
break
|
||||
}
|
||||
page = resp.NextPage
|
||||
}
|
||||
return nil, fmt.Errorf("release tag does not exist")
|
||||
}
|
||||
|
||||
@@ -89,26 +89,30 @@ func runWebhooksCreate(ctx stdctx.Context, cmd *cli.Command) error {
|
||||
config["secret"] = secret
|
||||
}
|
||||
|
||||
if branchFilter != "" {
|
||||
config["branch_filter"] = branchFilter
|
||||
}
|
||||
|
||||
if authHeader != "" {
|
||||
config["authorization_header"] = authHeader
|
||||
}
|
||||
|
||||
var hook *gitea.Hook
|
||||
if c.IsGlobal {
|
||||
return fmt.Errorf("global webhooks not yet supported in this version")
|
||||
} else if len(c.Org) > 0 {
|
||||
hook, _, err = client.CreateOrgHook(c.Org, gitea.CreateHookOption{
|
||||
Type: webhookType,
|
||||
Config: config,
|
||||
Events: events,
|
||||
Active: active,
|
||||
BranchFilter: branchFilter,
|
||||
AuthorizationHeader: authHeader,
|
||||
Type: webhookType,
|
||||
Config: config,
|
||||
Events: events,
|
||||
Active: active,
|
||||
})
|
||||
} else {
|
||||
hook, _, err = client.CreateRepoHook(c.Owner, c.Repo, gitea.CreateHookOption{
|
||||
Type: webhookType,
|
||||
Config: config,
|
||||
Events: events,
|
||||
Active: active,
|
||||
BranchFilter: branchFilter,
|
||||
AuthorizationHeader: authHeader,
|
||||
Type: webhookType,
|
||||
Config: config,
|
||||
Events: events,
|
||||
Active: active,
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -79,6 +79,8 @@ func TestWebhookConfigConstruction(t *testing.T) {
|
||||
name string
|
||||
url string
|
||||
secret string
|
||||
branchFilter string
|
||||
authHeader string
|
||||
expectedKeys []string
|
||||
expectedValues map[string]string
|
||||
}{
|
||||
@@ -104,16 +106,44 @@ func TestWebhookConfigConstruction(t *testing.T) {
|
||||
"secret": "my-secret",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Config with branch filter",
|
||||
url: "https://example.com/webhook",
|
||||
branchFilter: "main,develop",
|
||||
expectedKeys: []string{"url", "http_method", "content_type", "branch_filter"},
|
||||
expectedValues: map[string]string{
|
||||
"url": "https://example.com/webhook",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
"branch_filter": "main,develop",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Config with auth header",
|
||||
url: "https://example.com/webhook",
|
||||
authHeader: "Bearer token123",
|
||||
expectedKeys: []string{"url", "http_method", "content_type", "authorization_header"},
|
||||
expectedValues: map[string]string{
|
||||
"url": "https://example.com/webhook",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
"authorization_header": "Bearer token123",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Complete config",
|
||||
url: "https://example.com/webhook",
|
||||
secret: "secret123",
|
||||
expectedKeys: []string{"url", "http_method", "content_type", "secret"},
|
||||
branchFilter: "main",
|
||||
authHeader: "X-Token: abc",
|
||||
expectedKeys: []string{"url", "http_method", "content_type", "secret", "branch_filter", "authorization_header"},
|
||||
expectedValues: map[string]string{
|
||||
"url": "https://example.com/webhook",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
"secret": "secret123",
|
||||
"url": "https://example.com/webhook",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
"secret": "secret123",
|
||||
"branch_filter": "main",
|
||||
"authorization_header": "X-Token: abc",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -129,6 +159,12 @@ func TestWebhookConfigConstruction(t *testing.T) {
|
||||
if tt.secret != "" {
|
||||
config["secret"] = tt.secret
|
||||
}
|
||||
if tt.branchFilter != "" {
|
||||
config["branch_filter"] = tt.branchFilter
|
||||
}
|
||||
if tt.authHeader != "" {
|
||||
config["authorization_header"] = tt.authHeader
|
||||
}
|
||||
|
||||
// Check all expected keys exist
|
||||
for _, key := range tt.expectedKeys {
|
||||
@@ -148,13 +184,11 @@ func TestWebhookConfigConstruction(t *testing.T) {
|
||||
|
||||
func TestWebhookCreateOptions(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
webhookType string
|
||||
events []string
|
||||
active bool
|
||||
config map[string]string
|
||||
branchFilter string
|
||||
authHeader string
|
||||
name string
|
||||
webhookType string
|
||||
events []string
|
||||
active bool
|
||||
config map[string]string
|
||||
}{
|
||||
{
|
||||
name: "Gitea webhook",
|
||||
@@ -166,8 +200,6 @@ func TestWebhookCreateOptions(t *testing.T) {
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
},
|
||||
branchFilter: "main",
|
||||
authHeader: "X-Token: abc",
|
||||
},
|
||||
{
|
||||
name: "Slack webhook",
|
||||
@@ -196,20 +228,16 @@ func TestWebhookCreateOptions(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
option := gitea.CreateHookOption{
|
||||
Type: gitea.HookType(tt.webhookType),
|
||||
Config: tt.config,
|
||||
Events: tt.events,
|
||||
Active: tt.active,
|
||||
BranchFilter: tt.branchFilter,
|
||||
AuthorizationHeader: tt.authHeader,
|
||||
Type: gitea.HookType(tt.webhookType),
|
||||
Config: tt.config,
|
||||
Events: tt.events,
|
||||
Active: tt.active,
|
||||
}
|
||||
|
||||
assert.Equal(t, gitea.HookType(tt.webhookType), option.Type)
|
||||
assert.Equal(t, tt.events, option.Events)
|
||||
assert.Equal(t, tt.active, option.Active)
|
||||
assert.Equal(t, tt.config, option.Config)
|
||||
assert.Equal(t, tt.branchFilter, option.BranchFilter)
|
||||
assert.Equal(t, tt.authHeader, option.AuthorizationHeader)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,14 +97,11 @@ func runWebhooksUpdate(ctx stdctx.Context, cmd *cli.Command) error {
|
||||
if cmd.IsSet("secret") {
|
||||
config["secret"] = cmd.String("secret")
|
||||
}
|
||||
branchFilter := hook.BranchFilter
|
||||
if cmd.IsSet("branch-filter") {
|
||||
branchFilter = cmd.String("branch-filter")
|
||||
config["branch_filter"] = cmd.String("branch-filter")
|
||||
}
|
||||
|
||||
authHeader := hook.AuthorizationHeader
|
||||
if cmd.IsSet("authorization-header") {
|
||||
authHeader = cmd.String("authorization-header")
|
||||
config["authorization_header"] = cmd.String("authorization-header")
|
||||
}
|
||||
|
||||
// Update events if specified
|
||||
@@ -129,19 +126,15 @@ func runWebhooksUpdate(ctx stdctx.Context, cmd *cli.Command) error {
|
||||
return fmt.Errorf("global webhooks not yet supported in this version")
|
||||
} else if len(c.Org) > 0 {
|
||||
_, err = client.EditOrgHook(c.Org, int64(webhookID), gitea.EditHookOption{
|
||||
Config: config,
|
||||
Events: events,
|
||||
Active: &active,
|
||||
BranchFilter: branchFilter,
|
||||
AuthorizationHeader: authHeader,
|
||||
Config: config,
|
||||
Events: events,
|
||||
Active: &active,
|
||||
})
|
||||
} else {
|
||||
_, err = client.EditRepoHook(c.Owner, c.Repo, int64(webhookID), gitea.EditHookOption{
|
||||
Config: config,
|
||||
Events: events,
|
||||
Active: &active,
|
||||
BranchFilter: branchFilter,
|
||||
AuthorizationHeader: authHeader,
|
||||
Config: config,
|
||||
Events: events,
|
||||
Active: &active,
|
||||
})
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -128,10 +128,12 @@ func TestUpdateActiveInactiveFlags(t *testing.T) {
|
||||
func TestUpdateConfigPreservation(t *testing.T) {
|
||||
// Test that existing configuration is preserved when not updated
|
||||
originalConfig := map[string]string{
|
||||
"url": "https://old.example.com/webhook",
|
||||
"secret": "old-secret",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
"url": "https://old.example.com/webhook",
|
||||
"secret": "old-secret",
|
||||
"branch_filter": "main",
|
||||
"authorization_header": "Bearer old-token",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@@ -145,32 +147,53 @@ func TestUpdateConfigPreservation(t *testing.T) {
|
||||
"url": "https://new.example.com/webhook",
|
||||
},
|
||||
expectedConfig: map[string]string{
|
||||
"url": "https://new.example.com/webhook",
|
||||
"secret": "old-secret",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
"url": "https://new.example.com/webhook",
|
||||
"secret": "old-secret",
|
||||
"branch_filter": "main",
|
||||
"authorization_header": "Bearer old-token",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Update secret",
|
||||
name: "Update secret and auth header",
|
||||
updates: map[string]string{
|
||||
"secret": "new-secret",
|
||||
"secret": "new-secret",
|
||||
"authorization_header": "X-Token: new-token",
|
||||
},
|
||||
expectedConfig: map[string]string{
|
||||
"url": "https://old.example.com/webhook",
|
||||
"secret": "new-secret",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
"url": "https://old.example.com/webhook",
|
||||
"secret": "new-secret",
|
||||
"branch_filter": "main",
|
||||
"authorization_header": "X-Token: new-token",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Clear branch filter",
|
||||
updates: map[string]string{
|
||||
"branch_filter": "",
|
||||
},
|
||||
expectedConfig: map[string]string{
|
||||
"url": "https://old.example.com/webhook",
|
||||
"secret": "old-secret",
|
||||
"branch_filter": "",
|
||||
"authorization_header": "Bearer old-token",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "No updates",
|
||||
updates: map[string]string{},
|
||||
expectedConfig: map[string]string{
|
||||
"url": "https://old.example.com/webhook",
|
||||
"secret": "old-secret",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
"url": "https://old.example.com/webhook",
|
||||
"secret": "old-secret",
|
||||
"branch_filter": "main",
|
||||
"authorization_header": "Bearer old-token",
|
||||
"http_method": "post",
|
||||
"content_type": "json",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -194,61 +217,6 @@ func TestUpdateConfigPreservation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateBranchFilterAndAuthHeaderHandling(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
originalBranchFilter string
|
||||
originalAuthHeader string
|
||||
setBranchFilter bool
|
||||
newBranchFilter string
|
||||
setAuthorizationHeader bool
|
||||
newAuthHeader string
|
||||
expectedBranchFilter string
|
||||
expectedAuthHeader string
|
||||
}{
|
||||
{
|
||||
name: "Preserve values",
|
||||
originalBranchFilter: "main",
|
||||
originalAuthHeader: "Bearer old-token",
|
||||
expectedBranchFilter: "main",
|
||||
expectedAuthHeader: "Bearer old-token",
|
||||
},
|
||||
{
|
||||
name: "Update branch filter",
|
||||
originalBranchFilter: "main",
|
||||
setBranchFilter: true,
|
||||
newBranchFilter: "develop",
|
||||
expectedBranchFilter: "develop",
|
||||
expectedAuthHeader: "",
|
||||
},
|
||||
{
|
||||
name: "Update authorization header",
|
||||
originalAuthHeader: "Bearer old-token",
|
||||
setAuthorizationHeader: true,
|
||||
newAuthHeader: "X-Token: new-token",
|
||||
expectedBranchFilter: "",
|
||||
expectedAuthHeader: "X-Token: new-token",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
branchFilter := tt.originalBranchFilter
|
||||
if tt.setBranchFilter {
|
||||
branchFilter = tt.newBranchFilter
|
||||
}
|
||||
|
||||
authHeader := tt.originalAuthHeader
|
||||
if tt.setAuthorizationHeader {
|
||||
authHeader = tt.newAuthHeader
|
||||
}
|
||||
|
||||
assert.Equal(t, tt.expectedBranchFilter, branchFilter)
|
||||
assert.Equal(t, tt.expectedAuthHeader, authHeader)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateEventsHandling(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
||||
@@ -180,19 +180,25 @@ func fetchIssueSelectables(login *config.Login, owner, repo string, done chan is
|
||||
r.MilestoneList[i] = m.Title
|
||||
}
|
||||
|
||||
labels, _, err := c.ListRepoLabels(owner, repo, gitea.ListLabelsOptions{
|
||||
ListOptions: gitea.ListOptions{Page: -1},
|
||||
})
|
||||
if err != nil {
|
||||
r.Err = err
|
||||
done <- r
|
||||
return
|
||||
}
|
||||
r.LabelMap = make(map[string]int64)
|
||||
r.LabelList = make([]string, len(labels))
|
||||
for i, l := range labels {
|
||||
r.LabelMap[l.Name] = l.ID
|
||||
r.LabelList[i] = l.Name
|
||||
r.LabelList = make([]string, 0)
|
||||
for page := 1; ; {
|
||||
labels, resp, err := c.ListRepoLabels(owner, repo, gitea.ListLabelsOptions{
|
||||
ListOptions: gitea.ListOptions{Page: page, PageSize: 50},
|
||||
})
|
||||
if err != nil {
|
||||
r.Err = err
|
||||
done <- r
|
||||
return
|
||||
}
|
||||
for _, l := range labels {
|
||||
r.LabelMap[l.Name] = l.ID
|
||||
r.LabelList = append(r.LabelList, l.Name)
|
||||
}
|
||||
if resp == nil || resp.NextPage == 0 {
|
||||
break
|
||||
}
|
||||
page = resp.NextPage
|
||||
}
|
||||
|
||||
done <- r
|
||||
|
||||
@@ -67,21 +67,13 @@ func WebhookDetails(hook *gitea.Hook) {
|
||||
if method, ok := hook.Config["http_method"]; ok {
|
||||
fmt.Printf("- **HTTP Method**: %s\n", method)
|
||||
}
|
||||
branchFilter := hook.BranchFilter
|
||||
if branchFilter == "" {
|
||||
branchFilter = hook.Config["branch_filter"]
|
||||
}
|
||||
if branchFilter != "" {
|
||||
if branchFilter, ok := hook.Config["branch_filter"]; ok && branchFilter != "" {
|
||||
fmt.Printf("- **Branch Filter**: %s\n", branchFilter)
|
||||
}
|
||||
if _, hasSecret := hook.Config["secret"]; hasSecret {
|
||||
fmt.Printf("- **Secret**: (configured)\n")
|
||||
}
|
||||
hasAuth := hook.AuthorizationHeader != ""
|
||||
if !hasAuth {
|
||||
_, hasAuth = hook.Config["authorization_header"]
|
||||
}
|
||||
if hasAuth {
|
||||
if _, hasAuth := hook.Config["authorization_header"]; hasAuth {
|
||||
fmt.Printf("- **Authorization Header**: (configured)\n")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,17 +81,17 @@ func TestWebhookDetails(t *testing.T) {
|
||||
ID: 123,
|
||||
Type: "gitea",
|
||||
Config: map[string]string{
|
||||
"url": "https://example.com/webhook",
|
||||
"content_type": "json",
|
||||
"http_method": "post",
|
||||
"secret": "secret-value",
|
||||
"url": "https://example.com/webhook",
|
||||
"content_type": "json",
|
||||
"http_method": "post",
|
||||
"branch_filter": "main,develop",
|
||||
"secret": "secret-value",
|
||||
"authorization_header": "Bearer token123",
|
||||
},
|
||||
BranchFilter: "main,develop",
|
||||
AuthorizationHeader: "Bearer token123",
|
||||
Events: []string{"push", "pull_request", "issues"},
|
||||
Active: true,
|
||||
Created: now.Add(-24 * time.Hour),
|
||||
Updated: now,
|
||||
Events: []string{"push", "pull_request", "issues"},
|
||||
Active: true,
|
||||
Created: now.Add(-24 * time.Hour),
|
||||
Updated: now,
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -238,14 +238,16 @@ func TestWebhookConfigHandling(t *testing.T) {
|
||||
{
|
||||
name: "Config with all fields",
|
||||
config: map[string]string{
|
||||
"url": "https://example.com/webhook",
|
||||
"secret": "my-secret",
|
||||
"content_type": "json",
|
||||
"http_method": "post",
|
||||
"url": "https://example.com/webhook",
|
||||
"secret": "my-secret",
|
||||
"authorization_header": "Bearer token",
|
||||
"content_type": "json",
|
||||
"http_method": "post",
|
||||
"branch_filter": "main",
|
||||
},
|
||||
expectedURL: "https://example.com/webhook",
|
||||
hasSecret: true,
|
||||
hasAuthHeader: false,
|
||||
hasAuthHeader: true,
|
||||
},
|
||||
{
|
||||
name: "Config with minimal fields",
|
||||
@@ -339,17 +341,17 @@ func TestWebhookDetailsFormatting(t *testing.T) {
|
||||
ID: 123,
|
||||
Type: "gitea",
|
||||
Config: map[string]string{
|
||||
"url": "https://example.com/webhook",
|
||||
"content_type": "json",
|
||||
"http_method": "post",
|
||||
"secret": "secret-value",
|
||||
"url": "https://example.com/webhook",
|
||||
"content_type": "json",
|
||||
"http_method": "post",
|
||||
"branch_filter": "main,develop",
|
||||
"secret": "secret-value",
|
||||
"authorization_header": "Bearer token123",
|
||||
},
|
||||
BranchFilter: "main,develop",
|
||||
AuthorizationHeader: "Bearer token123",
|
||||
Events: []string{"push", "pull_request", "issues"},
|
||||
Active: true,
|
||||
Created: now.Add(-24 * time.Hour),
|
||||
Updated: now,
|
||||
Events: []string{"push", "pull_request", "issues"},
|
||||
Active: true,
|
||||
Created: now.Add(-24 * time.Hour),
|
||||
Updated: now,
|
||||
}
|
||||
|
||||
// Test that all expected fields are included in details
|
||||
@@ -377,8 +379,8 @@ func TestWebhookDetailsFormatting(t *testing.T) {
|
||||
assert.Equal(t, "https://example.com/webhook", hook.Config["url"])
|
||||
assert.Equal(t, "json", hook.Config["content_type"])
|
||||
assert.Equal(t, "post", hook.Config["http_method"])
|
||||
assert.Equal(t, "main,develop", hook.BranchFilter)
|
||||
assert.Equal(t, "main,develop", hook.Config["branch_filter"])
|
||||
assert.Contains(t, hook.Config, "secret")
|
||||
assert.Equal(t, "Bearer token123", hook.AuthorizationHeader)
|
||||
assert.Contains(t, hook.Config, "authorization_header")
|
||||
assert.Equal(t, []string{"push", "pull_request", "issues"}, hook.Events)
|
||||
}
|
||||
|
||||
@@ -13,16 +13,23 @@ import (
|
||||
// ResolveLabelNames returns a list of label IDs for a given list of label names
|
||||
func ResolveLabelNames(client *gitea.Client, owner, repo string, labelNames []string) ([]int64, error) {
|
||||
labelIDs := make([]int64, 0, len(labelNames))
|
||||
labels, _, err := client.ListRepoLabels(owner, repo, gitea.ListLabelsOptions{
|
||||
ListOptions: gitea.ListOptions{Page: -1},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, l := range labels {
|
||||
if utils.Contains(labelNames, l.Name) {
|
||||
labelIDs = append(labelIDs, l.ID)
|
||||
page := 1
|
||||
for {
|
||||
labels, resp, err := client.ListRepoLabels(owner, repo, gitea.ListLabelsOptions{
|
||||
ListOptions: gitea.ListOptions{Page: page, PageSize: 50},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, l := range labels {
|
||||
if utils.Contains(labelNames, l.Name) {
|
||||
labelIDs = append(labelIDs, l.ID)
|
||||
}
|
||||
}
|
||||
if resp == nil || resp.NextPage == 0 {
|
||||
break
|
||||
}
|
||||
page = resp.NextPage
|
||||
}
|
||||
return labelIDs, nil
|
||||
}
|
||||
|
||||
@@ -166,11 +166,19 @@ func generateToken(login config.Login, user, pass, otp, scopes string) (string,
|
||||
}
|
||||
client := login.Client(opts...)
|
||||
|
||||
tl, _, err := client.ListAccessTokens(gitea.ListAccessTokensOptions{
|
||||
ListOptions: gitea.ListOptions{Page: -1},
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
var tl []*gitea.AccessToken
|
||||
for page := 1; ; {
|
||||
page_tokens, resp, err := client.ListAccessTokens(gitea.ListAccessTokensOptions{
|
||||
ListOptions: gitea.ListOptions{Page: page, PageSize: 50},
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
tl = append(tl, page_tokens...)
|
||||
if resp == nil || resp.NextPage == 0 {
|
||||
break
|
||||
}
|
||||
page = resp.NextPage
|
||||
}
|
||||
host, _ := os.Hostname()
|
||||
tokenName := host + "-tea"
|
||||
|
||||
@@ -19,11 +19,22 @@ import (
|
||||
// a matching private key in ~/.ssh/. If no match is found, path is empty.
|
||||
func findSSHKey(client *gitea.Client) (string, error) {
|
||||
// get keys registered on gitea instance
|
||||
keys, _, err := client.ListMyPublicKeys(gitea.ListPublicKeysOptions{
|
||||
ListOptions: gitea.ListOptions{Page: -1},
|
||||
})
|
||||
if err != nil || len(keys) == 0 {
|
||||
return "", err
|
||||
var keys []*gitea.PublicKey
|
||||
for page := 1; ; {
|
||||
page_keys, resp, err := client.ListMyPublicKeys(gitea.ListPublicKeysOptions{
|
||||
ListOptions: gitea.ListOptions{Page: page, PageSize: 50},
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
keys = append(keys, page_keys...)
|
||||
if resp == nil || resp.NextPage == 0 {
|
||||
break
|
||||
}
|
||||
page = resp.NextPage
|
||||
}
|
||||
if len(keys) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
// enumerate ~/.ssh/*.pub files
|
||||
|
||||
@@ -14,11 +14,19 @@ import (
|
||||
func ListPullReviewComments(ctx *context.TeaContext, idx int64) ([]*gitea.PullReviewComment, error) {
|
||||
c := ctx.Login.Client()
|
||||
|
||||
reviews, _, err := c.ListPullReviews(ctx.Owner, ctx.Repo, idx, gitea.ListPullReviewsOptions{
|
||||
ListOptions: gitea.ListOptions{Page: -1},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var reviews []*gitea.PullReview
|
||||
for page := 1; ; {
|
||||
page_reviews, resp, err := c.ListPullReviews(ctx.Owner, ctx.Repo, idx, gitea.ListPullReviewsOptions{
|
||||
ListOptions: gitea.ListOptions{Page: page, PageSize: 50},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
reviews = append(reviews, page_reviews...)
|
||||
if resp == nil || resp.NextPage == 0 {
|
||||
break
|
||||
}
|
||||
page = resp.NextPage
|
||||
}
|
||||
|
||||
var allComments []*gitea.PullReviewComment
|
||||
|
||||
Reference in New Issue
Block a user