mirror of
				https://gitea.com/gitea/tea.git
				synced 2025-10-30 16:55:25 +01:00 
			
		
		
		
	 3495ec5ed4
			
		
	
	3495ec5ed4
	
	
	
		
			
			## 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>
		
			
				
	
	
		
			90 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			90 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| // Copyright 2024 The Gitea Authors. All rights reserved.
 | |
| // SPDX-License-Identifier: MIT
 | |
| 
 | |
| package cmd
 | |
| 
 | |
| import (
 | |
| 	stdctx "context"
 | |
| 	"fmt"
 | |
| 
 | |
| 	"code.gitea.io/tea/cmd/webhooks"
 | |
| 	"code.gitea.io/tea/modules/context"
 | |
| 	"code.gitea.io/tea/modules/print"
 | |
| 	"code.gitea.io/tea/modules/utils"
 | |
| 
 | |
| 	"code.gitea.io/sdk/gitea"
 | |
| 	"github.com/urfave/cli/v3"
 | |
| )
 | |
| 
 | |
| // CmdWebhooks represents the webhooks command
 | |
| var CmdWebhooks = cli.Command{
 | |
| 	Name:        "webhooks",
 | |
| 	Aliases:     []string{"webhook", "hooks", "hook"},
 | |
| 	Category:    catEntities,
 | |
| 	Usage:       "Manage webhooks",
 | |
| 	Description: "List, create, update, and delete repository, organization, or global webhooks",
 | |
| 	ArgsUsage:   "[webhook-id]",
 | |
| 	Action:      runWebhooksDefault,
 | |
| 	Commands: []*cli.Command{
 | |
| 		&webhooks.CmdWebhooksList,
 | |
| 		&webhooks.CmdWebhooksCreate,
 | |
| 		&webhooks.CmdWebhooksDelete,
 | |
| 		&webhooks.CmdWebhooksUpdate,
 | |
| 	},
 | |
| 	Flags: append([]cli.Flag{
 | |
| 		&cli.StringFlag{
 | |
| 			Name:  "repo",
 | |
| 			Usage: "repository to operate on",
 | |
| 		},
 | |
| 		&cli.StringFlag{
 | |
| 			Name:  "org",
 | |
| 			Usage: "organization to operate on",
 | |
| 		},
 | |
| 		&cli.BoolFlag{
 | |
| 			Name:  "global",
 | |
| 			Usage: "operate on global webhooks",
 | |
| 		},
 | |
| 		&cli.StringFlag{
 | |
| 			Name:  "login",
 | |
| 			Usage: "gitea login instance to use",
 | |
| 		},
 | |
| 		&cli.StringFlag{
 | |
| 			Name:    "output",
 | |
| 			Aliases: []string{"o"},
 | |
| 			Usage:   "output format [table, csv, simple, tsv, yaml, json]",
 | |
| 		},
 | |
| 	}, webhooks.CmdWebhooksList.Flags...),
 | |
| }
 | |
| 
 | |
| func runWebhooksDefault(ctx stdctx.Context, cmd *cli.Command) error {
 | |
| 	if cmd.Args().Len() == 1 {
 | |
| 		return runWebhookDetail(ctx, cmd)
 | |
| 	}
 | |
| 	return webhooks.RunWebhooksList(ctx, cmd)
 | |
| }
 | |
| 
 | |
| func runWebhookDetail(_ stdctx.Context, cmd *cli.Command) error {
 | |
| 	ctx := context.InitCommand(cmd)
 | |
| 	client := ctx.Login.Client()
 | |
| 
 | |
| 	webhookID, err := utils.ArgToIndex(cmd.Args().First())
 | |
| 	if err != nil {
 | |
| 		return err
 | |
| 	}
 | |
| 
 | |
| 	var hook *gitea.Hook
 | |
| 	if ctx.IsGlobal {
 | |
| 		return fmt.Errorf("global webhooks not yet supported in this version")
 | |
| 	} else if len(ctx.Org) > 0 {
 | |
| 		hook, _, err = client.GetOrgHook(ctx.Org, int64(webhookID))
 | |
| 	} else {
 | |
| 		hook, _, err = client.GetRepoHook(ctx.Owner, ctx.Repo, int64(webhookID))
 | |
| 	}
 | |
| 	if err != nil {
 | |
| 		return err
 | |
| 	}
 | |
| 
 | |
| 	print.WebhookDetails(hook)
 | |
| 	return nil
 | |
| }
 |