feat(issue): support change issue state
This commit is contained in:
parent
bdb059c957
commit
712171250e
|
@ -94,7 +94,7 @@ var CreateCmd = &cobra.Command{
|
||||||
optionMap = make(map[string]int, 0)
|
optionMap = make(map[string]int, 0)
|
||||||
optionMap, options = issue.FillOptions(candidateTasks, optionMap, options)
|
optionMap, options = issue.FillOptions(candidateTasks, optionMap, options)
|
||||||
promote = "请选择要关联的父任务"
|
promote = "请选择要关联的父任务"
|
||||||
selector := selector_tui.NewMapSelector(optionMap, options, promote)
|
selector := selector_tui.NewMapSelector(optionMap, options, promote, false)
|
||||||
if model, err = selector.Run(); err != nil {
|
if model, err = selector.Run(); err != nil {
|
||||||
color.Red("父任务选择器加载失败!")
|
color.Red("父任务选择器加载失败!")
|
||||||
return
|
return
|
||||||
|
@ -113,7 +113,7 @@ var CreateCmd = &cobra.Command{
|
||||||
optionMap = make(map[string]int, 0)
|
optionMap = make(map[string]int, 0)
|
||||||
optionMap, options = member.FillOptions(candidateAssignees, optionMap, options)
|
optionMap, options = member.FillOptions(candidateAssignees, optionMap, options)
|
||||||
promote = "请选择指派的负责人"
|
promote = "请选择指派的负责人"
|
||||||
selector = selector_tui.NewMapSelector(optionMap, options, promote)
|
selector = selector_tui.NewMapSelector(optionMap, options, promote, false)
|
||||||
if model, err = selector.Run(); err != nil {
|
if model, err = selector.Run(); err != nil {
|
||||||
color.Red("负责人选择器加载失败!")
|
color.Red("负责人选择器加载失败!")
|
||||||
return
|
return
|
||||||
|
|
|
@ -17,7 +17,7 @@ var RootCmd = &cobra.Command{
|
||||||
Use: "gitee",
|
Use: "gitee",
|
||||||
Short: "Gitee In terminal",
|
Short: "Gitee In terminal",
|
||||||
Long: "Gitee CLI is a tool which interact with gitee server seamlessly via terminal",
|
Long: "Gitee CLI is a tool which interact with gitee server seamlessly via terminal",
|
||||||
Version: "0.0.4",
|
Version: "0.0.5",
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -62,7 +62,7 @@ func Create(enterpriseId int, payload map[string]interface{}) (Issue, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update(enterpriseId int, issueId int, payload map[string]interface{}) (Issue, error) {
|
func Update(enterpriseId int, issueId int, payload map[string]interface{}) (Issue, error) {
|
||||||
url := fmt.Sprintf("%s/%d", Endpoint, enterpriseId, issueId)
|
url := fmt.Sprintf("https://api.gitee.com/enterprises/%d/issues/%d", enterpriseId, issueId)
|
||||||
giteeClient := http_utils.NewGiteeClient("PUT", url, nil, payload)
|
giteeClient := http_utils.NewGiteeClient("PUT", url, nil, payload)
|
||||||
giteeClient.SetCookieAuth()
|
giteeClient.SetCookieAuth()
|
||||||
|
|
||||||
|
|
|
@ -14,13 +14,17 @@ type MapSelector struct {
|
||||||
Cursor int
|
Cursor int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMapSelector(optionsMap map[string]int, options []string, promote string) *tea.Program {
|
func NewMapSelector(optionsMap map[string]int, options []string, promote string, altScreen bool) *tea.Program {
|
||||||
mapSelector := MapSelector{
|
mapSelector := MapSelector{
|
||||||
OptionsMap: optionsMap,
|
OptionsMap: optionsMap,
|
||||||
Options: options,
|
Options: options,
|
||||||
Promote: promote,
|
Promote: promote,
|
||||||
}
|
}
|
||||||
|
if altScreen {
|
||||||
|
return tea.NewProgram(mapSelector, tea.WithAltScreen())
|
||||||
|
} else {
|
||||||
return tea.NewProgram(mapSelector)
|
return tea.NewProgram(mapSelector)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m MapSelector) Init() tea.Cmd {
|
func (m MapSelector) Init() tea.Cmd {
|
||||||
|
|
|
@ -5,8 +5,10 @@ import (
|
||||||
"gitee_cli/config"
|
"gitee_cli/config"
|
||||||
"gitee_cli/internal/api/enterprises"
|
"gitee_cli/internal/api/enterprises"
|
||||||
"gitee_cli/internal/api/issue"
|
"gitee_cli/internal/api/issue"
|
||||||
|
"gitee_cli/internal/api/issue_state"
|
||||||
"gitee_cli/internal/api/pull_request"
|
"gitee_cli/internal/api/pull_request"
|
||||||
"gitee_cli/utils/git_utils"
|
"gitee_cli/utils/git_utils"
|
||||||
|
"gitee_cli/utils/tui/selector_tui"
|
||||||
"github.com/atotto/clipboard"
|
"github.com/atotto/clipboard"
|
||||||
"github.com/charmbracelet/bubbles/key"
|
"github.com/charmbracelet/bubbles/key"
|
||||||
"github.com/charmbracelet/bubbles/table"
|
"github.com/charmbracelet/bubbles/table"
|
||||||
|
@ -103,6 +105,43 @@ func (t Table) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
case "q", "ctrl+c":
|
case "q", "ctrl+c":
|
||||||
t.SelectedKey = ""
|
t.SelectedKey = ""
|
||||||
return t, tea.Quit
|
return t, tea.Quit
|
||||||
|
case "s":
|
||||||
|
if t.ResourceType == Issue {
|
||||||
|
targetIssue, err := issue.Detail(t.Enterprise.Id, t.table.SelectedRow()[0])
|
||||||
|
if err != nil {
|
||||||
|
color.Red("获取任务详情失败!")
|
||||||
|
return t, tea.Quit
|
||||||
|
}
|
||||||
|
if issueStates, err := issue_state.ListWithIssue(t.Enterprise.Id, targetIssue.Id); err == nil {
|
||||||
|
var model tea.Model
|
||||||
|
options := make([]string, 0)
|
||||||
|
optionMap := make(map[string]int, 0)
|
||||||
|
optionMap, options = issue_state.FillOptions(issueStates, optionMap, options)
|
||||||
|
promote := "请选择要变更的状态"
|
||||||
|
selector := selector_tui.NewMapSelector(optionMap, options, promote, true)
|
||||||
|
if model, err = selector.Run(); err != nil {
|
||||||
|
color.Red("任务状态选择器加载失败!")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
mapSelector, _ := model.(selector_tui.MapSelector)
|
||||||
|
|
||||||
|
issueStateId, err := mapSelector.SelectedValue()
|
||||||
|
if err != nil {
|
||||||
|
color.Red(err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
if targetIssue, err = issue.Update(t.Enterprise.Id, targetIssue.Id, map[string]interface{}{
|
||||||
|
"issue_state_id": issueStateId,
|
||||||
|
}); err != nil {
|
||||||
|
color.Red(err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
return t, tea.ClearScrollArea
|
||||||
|
} else {
|
||||||
|
color.Red("获取任务状态列表失败!")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
case "v":
|
case "v":
|
||||||
if t.ResourceType == Issue {
|
if t.ResourceType == Issue {
|
||||||
if _issue, err := issue.Detail(t.Enterprise.Id, t.table.SelectedRow()[0]); err == nil {
|
if _issue, err := issue.Detail(t.Enterprise.Id, t.table.SelectedRow()[0]); err == nil {
|
||||||
|
|
Loading…
Reference in New Issue