Improve UX for transitioning
This commit is contained in:
parent
f12287c3e4
commit
03481b1c77
36
actions.go
36
actions.go
@ -337,21 +337,43 @@ func ActionSetStatus(_ []string) {
|
||||
printError("No issue selected", nil)
|
||||
return
|
||||
}
|
||||
issueKey := GetIssueKey()
|
||||
|
||||
issueTypes, err := GetAllStatuses(GetProjectId())
|
||||
issue, err := GetIssue(issueKey)
|
||||
if err != nil {
|
||||
printError("Failed to get sprint statuses", err)
|
||||
printError("Failed to fetch issue", err)
|
||||
return
|
||||
}
|
||||
options := []huh.Option[string]{}
|
||||
for _, status := range (*issueTypes)[0].Statuses {
|
||||
name := fmt.Sprintf("%s (%s)", status.Name, status.ID)
|
||||
options = append(options, huh.Option[string]{Key: name, Value: status.ID})
|
||||
|
||||
transitions, err := GetIssueTransitions(issueKey)
|
||||
if err != nil {
|
||||
printError("Could not fetch issue transitions", err)
|
||||
return
|
||||
}
|
||||
huh.NewSelect[string]().
|
||||
|
||||
options := []huh.Option[string]{}
|
||||
var selected string
|
||||
for _, transition := range transitions {
|
||||
options = append(options, huh.Option[string]{Key: transition.Name, Value: transition.ID})
|
||||
if transition.To.ID == issue.Fields.Status.ID {
|
||||
selected = transition.ID
|
||||
}
|
||||
}
|
||||
|
||||
err = huh.NewSelect[string]().
|
||||
Title("Select Option").
|
||||
Options(options...).
|
||||
Value(&selected).
|
||||
Run()
|
||||
if err != nil {
|
||||
printError("Failed to select status", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = UpdateIssueTransition(issueKey, selected)
|
||||
if err != nil {
|
||||
printError("Failed to update status", err)
|
||||
}
|
||||
}
|
||||
|
||||
func ActionSetTitle(_ []string) {
|
||||
|
@ -56,9 +56,10 @@ var CommandTree = []CommandArg{
|
||||
command("comments", ActionViewComments).WithHelp("View comments of an issue"),
|
||||
).WithHelp("View data about something"),
|
||||
option("set",
|
||||
command("status", ActionSetStatus).WithHelp("Set status of a ticket"),
|
||||
command("status", ActionSetStatus).WithHelp("Transition a ticket"),
|
||||
command("title", ActionSetTitle).WithHelp("Set the title of a ticket"),
|
||||
).WithHelp("Change something"),
|
||||
command("transition", ActionSetStatus).WithHelp("Transition a ticket"),
|
||||
command("exit", ActionExit).WithHelp("Exit jirashell"),
|
||||
command("logout", ActionLogout).WithHelp("Logout from Jira"),
|
||||
command("back", ActionBack).WithHelp("Go back"),
|
||||
|
22
jira.go
22
jira.go
@ -124,3 +124,25 @@ func UpdateIssueTitle(issue string, title string) error {
|
||||
return resp.Body.Close()
|
||||
})
|
||||
}
|
||||
|
||||
func GetIssueTransitions(issue string) ([]jira.Transition, error) {
|
||||
r, err := RunSpinner("Getting issue transitions...", func(ctx context.Context) (*[]jira.Transition, any, error) {
|
||||
transitions, response, err := jiraClient.Issue.GetTransitions(ctx, issue)
|
||||
return &transitions, response, err
|
||||
})
|
||||
if r == nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return *r, err
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateIssueTransition(issue string, transition string) error {
|
||||
return RunSpinnerRaw("Transitioning issue...", func(ctx context.Context) error {
|
||||
resp, err := jiraClient.Issue.DoTransition(ctx, issue, transition)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return resp.Body.Close()
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user