mirror of
https://gitea.com/gitea/tea.git
synced 2025-10-20 23:04:03 +02:00

## Summary This PR adds support for organization-level and global webhooks in the tea CLI tool. ## Changes Made ### Organization Webhooks - Added `--org` flag to webhook commands to operate on organization-level webhooks - Implemented full CRUD operations for org webhooks (create, list, update, delete) - Extended TeaContext to support organization scope ### Global Webhooks - Added `--global` flag with placeholder implementation - Ready for when Gitea SDK adds global webhook API methods ### Technical Details - Updated context handling to support org/global scopes - Modified all webhook subcommands (create, list, update, delete) - Maintained backward compatibility for repository webhooks - Updated tests and documentation ## Usage Examples ```bash # Repository webhooks (existing) tea webhooks list tea webhooks create https://example.com/hook --events push # Organization webhooks (new) tea webhooks list --org myorg tea webhooks create https://example.com/hook --org myorg --events push,pull_request # Global webhooks (future) tea webhooks list --global ``` ## Testing - All existing tests pass - Updated test expectations for new descriptions - Manual testing of org webhook operations completed Closes: webhook management feature request Reviewed-on: https://gitea.com/gitea/tea/pulls/798 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Ross Golder <ross@golder.org> Co-committed-by: Ross Golder <ross@golder.org>
82 lines
1.9 KiB
Go
82 lines
1.9 KiB
Go
// Copyright 2024 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package print
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
)
|
|
|
|
// WebhooksList prints a listing of webhooks
|
|
func WebhooksList(hooks []*gitea.Hook, output string) {
|
|
t := tableWithHeader(
|
|
"ID",
|
|
"Type",
|
|
"URL",
|
|
"Events",
|
|
"Active",
|
|
"Updated",
|
|
)
|
|
|
|
for _, hook := range hooks {
|
|
var url string
|
|
if hook.Config != nil {
|
|
url = hook.Config["url"]
|
|
}
|
|
|
|
events := strings.Join(hook.Events, ",")
|
|
if len(events) > 40 {
|
|
events = events[:37] + "..."
|
|
}
|
|
|
|
active := "✓"
|
|
if !hook.Active {
|
|
active = "✗"
|
|
}
|
|
|
|
t.addRow(
|
|
strconv.FormatInt(hook.ID, 10),
|
|
string(hook.Type),
|
|
url,
|
|
events,
|
|
active,
|
|
FormatTime(hook.Updated, false),
|
|
)
|
|
}
|
|
|
|
t.print(output)
|
|
}
|
|
|
|
// WebhookDetails prints detailed information about a webhook
|
|
func WebhookDetails(hook *gitea.Hook) {
|
|
fmt.Printf("# Webhook %d\n\n", hook.ID)
|
|
fmt.Printf("- **Type**: %s\n", hook.Type)
|
|
fmt.Printf("- **Active**: %t\n", hook.Active)
|
|
fmt.Printf("- **Created**: %s\n", FormatTime(hook.Created, false))
|
|
fmt.Printf("- **Updated**: %s\n", FormatTime(hook.Updated, false))
|
|
|
|
if hook.Config != nil {
|
|
fmt.Printf("- **URL**: %s\n", hook.Config["url"])
|
|
if contentType, ok := hook.Config["content_type"]; ok {
|
|
fmt.Printf("- **Content Type**: %s\n", contentType)
|
|
}
|
|
if method, ok := hook.Config["http_method"]; ok {
|
|
fmt.Printf("- **HTTP Method**: %s\n", method)
|
|
}
|
|
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")
|
|
}
|
|
if _, hasAuth := hook.Config["authorization_header"]; hasAuth {
|
|
fmt.Printf("- **Authorization Header**: (configured)\n")
|
|
}
|
|
}
|
|
|
|
fmt.Printf("- **Events**: %s\n", strings.Join(hook.Events, ", "))
|
|
}
|