Files
gitea-tea/internal/terminal/milestone_form.go
T
bircni c161a63eb6 feat(milestone): milestone tables, views, forms and one selection model
milestone view printed the list row, and milestone list hid the due date
and progress. milestone list now shows ID TITLE [STATE] DUE PROGRESS, open
milestones first and by due date; milestone view shows the state, due
date, progress, description and the milestone's web page (also --web).

Every milestone command addresses milestones by title or ID. Mutations
report ✓ lines: milestone create also prints the new milestone's URL and
takes the title as an argument; close and reopen skip milestones already
in that state; delete names the milestone in its confirmation; milestone
issue add and remove report one line such as "✓ Added #1, #2 to
milestone "v1.0" in alice/x". milestone issue list uses the issue table.
milestone edit without flags on a terminal opens the milestone form with
the current values, and every milestone command completes milestone
titles and has help text with examples.

Signed-off-by: bircni <bircni@icloud.com>
2026-10-12 00:17:02 +02:00

43 lines
1.5 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package terminal
import (
"context"
"strings"
"time"
"charm.land/huh/v2"
)
// MilestoneFormValues holds interactively collected milestone fields.
type MilestoneFormValues struct {
Title, Description string
Deadline *time.Time
}
// MilestoneForm collects interactive milestone input.
type MilestoneForm interface {
// EditMilestone asks for the fields of a milestone, starting from current, under heading, such
// as "Editing milestone v1.0". Empty values create a milestone.
EditMilestone(ctx context.Context, heading string, current MilestoneFormValues) (MilestoneFormValues, error)
}
// EditMilestone runs the interactive milestone form on stderr.
func (p *FormPrompter) EditMilestone(ctx context.Context, heading string, current MilestoneFormValues) (MilestoneFormValues, error) {
title, description, deadline := current.Title, current.Description, ""
if current.Deadline != nil {
deadline = current.Deadline.Format(time.DateOnly)
}
if err := p.runForm(ctx, huh.NewForm(huh.NewGroup(
huh.NewInput().Title("Milestone title (required):").Value(&title).Validate(huh.ValidateNotEmpty()),
bodyField("Milestone description (markdown):", &description),
dueDateInput("Milestone deadline:", &deadline),
).Title(heading))); err != nil {
return MilestoneFormValues{}, err
}
parsed, err := parseDueDate(deadline)
return MilestoneFormValues{Title: strings.TrimSpace(title), Description: description, Deadline: parsed}, err
}