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)
|
printError("No issue selected", nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
issueKey := GetIssueKey()
|
||||||
|
|
||||||
issueTypes, err := GetAllStatuses(GetProjectId())
|
issue, err := GetIssue(issueKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
printError("Failed to get sprint statuses", err)
|
printError("Failed to fetch issue", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
options := []huh.Option[string]{}
|
|
||||||
for _, status := range (*issueTypes)[0].Statuses {
|
transitions, err := GetIssueTransitions(issueKey)
|
||||||
name := fmt.Sprintf("%s (%s)", status.Name, status.ID)
|
if err != nil {
|
||||||
options = append(options, huh.Option[string]{Key: name, Value: status.ID})
|
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").
|
Title("Select Option").
|
||||||
Options(options...).
|
Options(options...).
|
||||||
|
Value(&selected).
|
||||||
Run()
|
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) {
|
func ActionSetTitle(_ []string) {
|
||||||
|
@ -56,9 +56,10 @@ var CommandTree = []CommandArg{
|
|||||||
command("comments", ActionViewComments).WithHelp("View comments of an issue"),
|
command("comments", ActionViewComments).WithHelp("View comments of an issue"),
|
||||||
).WithHelp("View data about something"),
|
).WithHelp("View data about something"),
|
||||||
option("set",
|
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"),
|
command("title", ActionSetTitle).WithHelp("Set the title of a ticket"),
|
||||||
).WithHelp("Change something"),
|
).WithHelp("Change something"),
|
||||||
|
command("transition", ActionSetStatus).WithHelp("Transition a ticket"),
|
||||||
command("exit", ActionExit).WithHelp("Exit jirashell"),
|
command("exit", ActionExit).WithHelp("Exit jirashell"),
|
||||||
command("logout", ActionLogout).WithHelp("Logout from Jira"),
|
command("logout", ActionLogout).WithHelp("Logout from Jira"),
|
||||||
command("back", ActionBack).WithHelp("Go back"),
|
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()
|
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