feat(issue): support render state col in issue list.
Signed-off-by: EdmondFrank <EdmondFrank@hotmail.com>
This commit is contained in:
parent
e8a74c0293
commit
14ee7afd7a
|
@ -44,13 +44,14 @@ var ListCmd = &cobra.Command{
|
|||
|
||||
columns := []table.Column{
|
||||
{Title: "Ident", Width: 8},
|
||||
{Title: "Title", Width: 60},
|
||||
{Title: "Title", Width: 50},
|
||||
{Title: "State", Width: 10},
|
||||
}
|
||||
|
||||
rows := make([]table.Row, 0)
|
||||
|
||||
for _, issue := range _issues {
|
||||
rows = append(rows, table.Row{issue.Ident, issue.Title})
|
||||
rows = append(rows, table.Row{issue.Ident, issue.Title, issue.IssueState.Title})
|
||||
}
|
||||
|
||||
issueTable := tui.NewTable(enterprise, tui.Issue, columns, rows)
|
||||
|
|
|
@ -17,7 +17,7 @@ var RootCmd = &cobra.Command{
|
|||
Use: "gitee",
|
||||
Short: "Gitee In terminal",
|
||||
Long: "Gitee CLI is a tool which interact with gitee server seamlessly via terminal",
|
||||
Version: "0.0.1",
|
||||
Version: "0.0.2",
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"gitee_cli/utils/http_utils"
|
||||
"gitee_cli/internal/api/issue_state"
|
||||
)
|
||||
|
||||
const Endpoint = "https://api.gitee.com/enterprises/%d/issues"
|
||||
|
@ -15,6 +16,7 @@ type Issue struct {
|
|||
Title string `json:"title"`
|
||||
Url string `json:"issue_url"`
|
||||
Description string `json:"description"`
|
||||
IssueState issue_state.IssueState `json:"issue_state"`
|
||||
}
|
||||
|
||||
func Find(enterpriseId int, params map[string]string) ([]Issue, error) {
|
||||
|
@ -59,6 +61,25 @@ func Create(enterpriseId int, payload map[string]interface{}) (Issue, error) {
|
|||
return issue, nil
|
||||
}
|
||||
|
||||
func Update(enterpriseId int, issueId int, payload map[string]interface{}) (Issue, error) {
|
||||
url := fmt.Sprintf("%s/%d", Endpoint, enterpriseId, issueId)
|
||||
giteeClient := http_utils.NewGiteeClient("PUT", url, nil, payload)
|
||||
giteeClient.SetCookieAuth()
|
||||
|
||||
giteeClient.Do()
|
||||
|
||||
if giteeClient.IsFail() {
|
||||
return Issue{}, errors.New("更新工作项失败!")
|
||||
}
|
||||
|
||||
issue := Issue{}
|
||||
|
||||
data, _ := giteeClient.GetRespBody()
|
||||
json.Unmarshal(data, &issue)
|
||||
|
||||
return issue, nil
|
||||
}
|
||||
|
||||
func FillOptions(issues []Issue, optionMap map[string]int, options []string) (map[string]int, []string) {
|
||||
if len(issues) == 0 {
|
||||
return optionMap, options
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package issue_state
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"gitee_cli/utils/http_utils"
|
||||
)
|
||||
|
||||
type IssueState struct {
|
||||
Id int `json:"id"`
|
||||
Title string `json:"title"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
func ListWithIssue(entId int, issueId int) ([]IssueState, error) {
|
||||
url := fmt.Sprintf("https://api.gitee.com/enterprises/%d/issues/%d/issue_states", entId, issueId)
|
||||
giteeClient := http_utils.NewGiteeClient("GET", url, nil, nil)
|
||||
giteeClient.SetCookieAuth()
|
||||
if _, err := giteeClient.Do(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var res = struct {
|
||||
Data []IssueState `json:"data"`
|
||||
TotalCount int `json:"total_count"`
|
||||
}{}
|
||||
|
||||
data, _ := giteeClient.GetRespBody()
|
||||
|
||||
json.Unmarshal(data, &res)
|
||||
|
||||
return res.Data, nil
|
||||
}
|
||||
|
||||
func FillOptions(issueStates []IssueState, optionMap map[string]int, options []string) (map[string]int, []string) {
|
||||
if len(issueStates) == 0 {
|
||||
return optionMap, options
|
||||
}
|
||||
|
||||
for _, issueState := range issueStates {
|
||||
optionMap[issueState.Title] = issueState.Id
|
||||
options = append(options, issueState.Title)
|
||||
}
|
||||
return optionMap, options
|
||||
}
|
Loading…
Reference in New Issue