Merge remote-tracking branch 'origin/main' into Metrics-and-Logs

This commit is contained in:
Robin Olsen
2026-03-09 13:24:07 +01:00
44 changed files with 1949 additions and 477 deletions

View File

@@ -7,8 +7,6 @@ import (
"github.com/spf13/cobra"
)
// CloseCmd represents the close command,
// which allows users to close an existing issue by its ID.
var CloseCmd = &cobra.Command{
Use: "close [id]",
Short: "Close an existing issue",
@@ -21,8 +19,6 @@ var CloseCmd = &cobra.Command{
ValidArgsFunction: completeIssues,
}
// runCloseCmd executes the close command logic,
// which closes an issue by its ID after confirming with the user.
func runCloseCmd(cmd *cobra.Command, args []string) error {
closeID := args[0]
@@ -42,14 +38,30 @@ func runCloseCmd(cmd *cobra.Command, args []string) error {
return fmt.Errorf("issue with ID %s not found", closeID)
}
// Ask for closing reason
if err = huh.NewInput().Value(&issue.CloseReason).
Title("Reason for closing the issue?").WithTheme(huh.ThemeBase()).Run(); err != nil {
closeReason := ""
if err = huh.NewSelect[string]().Value(&closeReason).
Title("Reason for closing the issue?").
Options(
huh.NewOption("Done", "Done"),
huh.NewOption("Duplicate issue", "Duplicate issue"),
huh.NewOption("Won't fix", "Won't fix"),
huh.NewOption("Obsolete", "Obsolete"),
huh.NewOption("Other", "Other"),
).WithTheme(huh.ThemeBase()).Run(); err != nil {
return fmt.Errorf("error getting close reason: %w", err)
}
// Close the issue.
err = app.Issues.CloseIssue(cmd.Context(), closeID, issue.CloseReason, "", "")
if closeReason == "Other" {
if err = huh.NewInput().Value(&closeReason).
Title("Enter closing reason:").WithTheme(huh.ThemeBase()).Run(); err != nil {
return fmt.Errorf("error getting close reason: %w", err)
}
if closeReason == "" {
return fmt.Errorf("closing reason cannot be empty when selecting 'Other'")
}
}
err = app.Issues.CloseIssue(cmd.Context(), closeID, closeReason, "", "")
if err != nil {
return fmt.Errorf("error closing issue: %w", err)
}

View File

@@ -43,11 +43,6 @@ func (e *Expector) CompleteWithMessage(message string) ValidationFeedback {
return e.ValidationFeedback
}
func (e *Expector) Fail(message string) ValidationFeedback {
e.Checks = append(e.Checks, NewCheck(message, false))
return e.ValidationFeedback
}
func (e *Expector) Errors() []error {
var errors []error
for _, check := range e.Checks {
@@ -58,6 +53,32 @@ func (e *Expector) Errors() []error {
return errors
}
func (e *Expector) Pass(message string) *Expector {
e.Checks = append(e.Checks, NewCheck(message, true))
return e
}
func (e *Expector) Fail(message string) *Expector {
e.Checks = append(e.Checks, NewCheck(message, false))
return e
}
func (e *Expector) NotEmptyAndEqual(val, expected string, message string) *Expector {
if val == "" {
return e.Fail(fmt.Sprintf("%s is empty", message))
} else if val != expected {
return e.Fail(fmt.Sprintf(`%s expected "%v", got "%v"`, message, expected, val))
}
return e.Pass(message + " is correct")
}
func (e *Expector) Equal(val, expected any, message string) *Expector {
if val != expected {
return e.Fail(fmt.Sprintf(`%s expected "%v", got "%v"`, message, expected, val))
}
return e.Pass(message + " is correct")
}
func (e *Expector) Assert(condition bool, message string) *Expector {
check := NewCheck(message, condition)
e.Checks = append(e.Checks, check)