feat: issue edit
This commit is contained in:
parent
daa51159ec
commit
9251487e56
1 changed files with 78 additions and 1 deletions
79
cmd/issue.go
79
cmd/issue.go
|
|
@ -8,9 +8,9 @@ import (
|
|||
"text/tabwriter"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/spf13/cobra"
|
||||
"codeberg.org/romaintb/fgj/internal/api"
|
||||
"codeberg.org/romaintb/fgj/internal/config"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var issueCmd = &cobra.Command{
|
||||
|
|
@ -57,6 +57,14 @@ var issueCloseCmd = &cobra.Command{
|
|||
RunE: runIssueClose,
|
||||
}
|
||||
|
||||
var issueEditCmd = &cobra.Command{
|
||||
Use: "edit <number>",
|
||||
Short: "Edit an issue",
|
||||
Long: "Edit an existing issue's title, body, or state.",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runIssueEdit,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(issueCmd)
|
||||
issueCmd.AddCommand(issueListCmd)
|
||||
|
|
@ -64,6 +72,7 @@ func init() {
|
|||
issueCmd.AddCommand(issueCreateCmd)
|
||||
issueCmd.AddCommand(issueCommentCmd)
|
||||
issueCmd.AddCommand(issueCloseCmd)
|
||||
issueCmd.AddCommand(issueEditCmd)
|
||||
|
||||
issueListCmd.Flags().StringP("repo", "R", "", "Repository in owner/name format")
|
||||
issueListCmd.Flags().StringP("state", "s", "open", "Filter by state: open, closed, all")
|
||||
|
|
@ -78,6 +87,11 @@ func init() {
|
|||
issueCommentCmd.Flags().StringP("body", "b", "", "Comment body")
|
||||
|
||||
issueCloseCmd.Flags().StringP("repo", "R", "", "Repository in owner/name format")
|
||||
|
||||
issueEditCmd.Flags().StringP("repo", "R", "", "Repository in owner/name format")
|
||||
issueEditCmd.Flags().StringP("title", "t", "", "New title for the issue")
|
||||
issueEditCmd.Flags().StringP("body", "b", "", "New body for the issue")
|
||||
issueEditCmd.Flags().StringP("state", "s", "", "New state for the issue (open or closed)")
|
||||
}
|
||||
|
||||
func runIssueList(cmd *cobra.Command, args []string) error {
|
||||
|
|
@ -299,3 +313,66 @@ func runIssueClose(cmd *cobra.Command, args []string) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func runIssueEdit(cmd *cobra.Command, args []string) error {
|
||||
repo, _ := cmd.Flags().GetString("repo")
|
||||
title, _ := cmd.Flags().GetString("title")
|
||||
body, _ := cmd.Flags().GetString("body")
|
||||
stateStr, _ := cmd.Flags().GetString("state")
|
||||
|
||||
issueNumber, err := strconv.ParseInt(args[0], 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid issue number: %w", err)
|
||||
}
|
||||
|
||||
owner, name, err := parseRepo(repo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if title == "" && body == "" && stateStr == "" {
|
||||
return fmt.Errorf("at least one of --title, --body, or --state must be provided")
|
||||
}
|
||||
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
client, err := api.NewClientFromConfig(cfg, "")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
editOpt := gitea.EditIssueOption{}
|
||||
|
||||
if title != "" {
|
||||
editOpt.Title = title
|
||||
}
|
||||
|
||||
if body != "" {
|
||||
editOpt.Body = &body
|
||||
}
|
||||
|
||||
if stateStr != "" {
|
||||
switch strings.ToLower(stateStr) {
|
||||
case "open":
|
||||
stateOpen := gitea.StateOpen
|
||||
editOpt.State = &stateOpen
|
||||
case "closed":
|
||||
stateClosed := gitea.StateClosed
|
||||
editOpt.State = &stateClosed
|
||||
default:
|
||||
return fmt.Errorf("invalid state: %s (must be 'open' or 'closed')", stateStr)
|
||||
}
|
||||
}
|
||||
|
||||
_, _, err = client.EditIssue(owner, name, issueNumber, editOpt)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to edit issue: %w", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Issue #%d updated\n", issueNumber)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue