mirror of
https://gitea.com/gitea/tea.git
synced 2026-06-05 18:58:43 +02:00
8e0666ab85
Reviewed-on: https://gitea.com/gitea/tea/pulls/1003 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: techknowlogick <techknowlogick@gitea.com> Co-committed-by: techknowlogick <techknowlogick@gitea.com>
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package workflows
|
|
|
|
import (
|
|
stdctx "context"
|
|
"fmt"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
|
|
"gitea.dev/tea/cmd/flags"
|
|
"gitea.dev/tea/modules/context"
|
|
"gitea.dev/tea/modules/print"
|
|
"github.com/urfave/cli/v3"
|
|
)
|
|
|
|
// CmdWorkflowsList represents a sub command to list workflows
|
|
var CmdWorkflowsList = cli.Command{
|
|
Name: "list",
|
|
Aliases: []string{"ls"},
|
|
Usage: "List repository workflows",
|
|
Description: "List workflows in the repository with their status",
|
|
Action: RunWorkflowsList,
|
|
Flags: flags.AllDefaultFlags,
|
|
}
|
|
|
|
// RunWorkflowsList lists workflows in the repository using the workflow API
|
|
func RunWorkflowsList(ctx stdctx.Context, cmd *cli.Command) error {
|
|
c, err := context.InitCommand(cmd)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err := c.Ensure(context.CtxRequirement{RemoteRepo: true}); err != nil {
|
|
return err
|
|
}
|
|
client := c.Login.Client()
|
|
|
|
resp, _, err := client.ListRepoActionWorkflows(c.Owner, c.Repo)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to list workflows: %w", err)
|
|
}
|
|
|
|
var workflows []*gitea.ActionWorkflow
|
|
if resp != nil {
|
|
workflows = resp.Workflows
|
|
}
|
|
|
|
return print.ActionWorkflowsList(workflows, c.Output)
|
|
}
|