提交 c1871604 编写于 作者: 徐晓伟's avatar 徐晓伟

议题 API: 列出议题: 打印 JSON、打印时间

上级 db7ab756
...@@ -258,23 +258,26 @@ COPYRIGHT: ...@@ -258,23 +258,26 @@ COPYRIGHT:
--token value your_access_token --token value your_access_token
--page value 页码(默认:1),中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination (default: 1) --page value 页码(默认:1),中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination (default: 1)
--per-page value 每页列出的项目数(默认:20;最大:100),中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination (default: 20) --per-page value 每页列出的项目数(默认:20;最大:100),中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination (default: 20)
--print-json 打印 JSON (default: false)
--print-time 打印时间 (default: false)
--assignee-username value 对于给定的用户名 username,返回指派给这个用户的议题。与 assignee_id 相似且与其冲突。在免费版中,assignee_username 数组只能包含单个成员,否则将报参数错误提示。 --assignee-username value 对于给定的用户名 username,返回指派给这个用户的议题。与 assignee_id 相似且与其冲突。在免费版中,assignee_username 数组只能包含单个成员,否则将报参数错误提示。
--author-id value 对于给定的用户 id,返回这个用户创建的议题。与 author_username 冲突。与 scope=all 或 scope=assigned_to_me 配合使用。 --author-id value 对于给定的用户 id,返回这个用户创建的议题。与 author_username 冲突。与 scope=all 或 scope=assigned_to_me 配合使用。
--author-username value 对于给定的用户名 username,返回这个用户创建的议题。与 author_id 相似且与其冲突。 --author-username value 对于给定的用户名 username,返回这个用户创建的议题。与 author_id 相似且与其冲突。
--confidential value 筛选私密议题与公开议题。 --confidential 筛选私密议题与公开议题。 (default: false)
--due-date value 返回没有截止日期、已经逾期、本周内逾期、本月内逾期或介于两周前和下个月之间逾期的议题。可接受的值:0(没有截止日期)、any、today、tomorrow、overdue、week、month、next_month_and_previous_two_weeks。 --due-date value 返回没有截止日期、已经逾期、本周内逾期、本月内逾期或介于两周前和下个月之间逾期的议题。可接受的值:0(没有截止日期)、any、today、tomorrow、overdue、week、month、next_month_and_previous_two_weeks。
--iids value 返回包含给定 iid 的议题。 --iids value 返回包含给定 iid 的议题。
--in value 修改 search 属性的范围。可以使用 title、description 或使用半角逗号对他们进行连接。默认值是 title,description。 --in value 修改 search 属性的范围。可以使用 title、description 或使用半角逗号对他们进行连接。默认值是 title,description。 (default: "title,description")
--issue-type value 筛选议题的类型,可选值为 issue、incident 或 test_case。引入于 13.12 版本。 --issue-type value 筛选议题的类型,可选值为 issue、incident 或 test_case。引入于 13.12 版本。
--iteration-id value 对于给定的迭代 ID,返回与这个迭代关联的议题。使用 None 则返回未与迭代关联的议题。使用 Any 则返回存在关联迭代的议题。引入于 13.6 版本。 --iteration-id value 对于给定的迭代 ID,返回与这个迭代关联的议题。使用 None 则返回未与迭代关联的议题。使用 Any 则返回存在关联迭代的议题。引入于 13.6 版本。
--milestone value 里程碑名称。使用 None 则列出没有里程碑的议题。使用 Any 则列出存在关联里程碑的议题。None 及 Any 的用法将会在未来被弃用,请使用 milestone_id 替代。milestone 与 milestone_id 冲突。 --milestone value 里程碑名称。使用 None 则列出没有里程碑的议题。使用 Any 则列出存在关联里程碑的议题。None 及 Any 的用法将会在未来被弃用,请使用 milestone_id 替代。milestone 与 milestone_id 冲突。
--milestone-id value 对于给定的时间段(None、Any、Upcoming 或 Started),返回与该时间段里程碑相关联的议题。使用 None 则列出没有里程碑的议题。使用 Any 则列出存在关联里程碑的议题。使用 Upcoming 则列出与未开始里程碑相关联的议题。使用 Started 则列出与已开始里程碑相关联的议题。milestone 和 milestone_id 冲突。引入于 14.3 版本。 --milestone-id value 对于给定的时间段(None、Any、Upcoming 或 Started),返回与该时间段里程碑相关联的议题。使用 None 则列出没有里程碑的议题。使用 Any 则列出存在关联里程碑的议题。使用 Upcoming 则列出与未开始里程碑相关联的议题。使用 Started 则列出与已开始里程碑相关联的议题。milestone 和 milestone_id 冲突。引入于 14.3 版本。
--my-reaction-emoji value 对于给定的 emoji,返回用户使用该表情回应的议题。使用 None 则返回没有使用表情回应的议题。使用 Any 则返回使用至少一个表情回应的议题。 --my-reaction-emoji value 对于给定的 emoji,返回用户使用该表情回应的议题。使用 None 则返回没有使用表情回应的议题。使用 Any 则返回使用至少一个表情回应的议题。
--order-by value 返回根据 created_at、due_date、label_priority、milestone_due、popularity、priority、relative_position、title、updated_at 或 weight 排序的议题。默认值是 created_at。 --order-by value 返回根据 created_at、due_date、label_priority、milestone_due、popularity、priority、relative_position、title、updated_at 或 weight 排序的议题。默认值是 created_at。 (default: "created_at")
--scope value 返回满足范围 created_by_me、assigned_to_me 或 all 的议题。默认值是 created_by_me。 --scope value 返回满足范围 created_by_me、assigned_to_me 或 all 的议题。默认值是 created_by_me。 (default: "created_by_me")
--search value 根据 title 和 description 搜索议题。 --search value 根据 title 和 description 搜索议题。
--sort value 按照 asc 或者 desc 排序 (default: "desc") --sort value 按照 asc 或者 desc 排序 (default: "desc")
--state value 返回全部 all 议题或仅返回处于 opened 或 closed 状态的议题。 --state value 返回全部 all 议题或仅返回处于 opened 或 closed 状态的议题。 (default: "all")
--with-labels-details 若为 true 则返回更详尽的标签信息::name、:color、:description、:description_html、:text_color。默认值是 false。description_html 属性引入于 12.7 版本。 (default: false)
--help, -h show help --help, -h show help
``` ```
......
package constant package constant
const ( const (
Token = "token" Token = "token"
BaseUrl = "base-url" BaseUrl = "base-url"
BaseUrlDefault = "https://gitlab.com/api/v4" BaseUrlDefault = "https://gitlab.com/api/v4"
Id = "id" Id = "id"
JobId = "job-id" JobId = "job-id"
Sort = "sort" Sort = "sort"
SortDefault = "desc" SortDefault = "desc"
Page = "page" Page = "page"
PerPage = "per-page" PerPage = "per-page"
PrintJson = "print-json"
PrintJsonDefault = false
PrintTime = "print-time"
PrintTimeDefault = false
) )
...@@ -19,6 +19,22 @@ func CommonTokenRequired() []cli.Flag { ...@@ -19,6 +19,22 @@ func CommonTokenRequired() []cli.Flag {
} }
} }
func PrintJson() cli.Flag {
return &cli.BoolFlag{
Name: constant.PrintJson,
Value: constant.PrintJsonDefault,
Usage: "打印 JSON",
}
}
func PrintTime() cli.Flag {
return &cli.BoolFlag{
Name: constant.PrintTime,
Value: constant.PrintTimeDefault,
Usage: "打印时间",
}
}
func BaseUrl() cli.Flag { func BaseUrl() cli.Flag {
return &cli.StringFlag{ return &cli.StringFlag{
Name: constant.BaseUrl, Name: constant.BaseUrl,
......
...@@ -16,7 +16,7 @@ func Issues() *cli.Command { ...@@ -16,7 +16,7 @@ func Issues() *cli.Command {
Name: "issue", Name: "issue",
Aliases: []string{"issues"}, Aliases: []string{"issues"},
Usage: "议题 API,中文文档:https://docs.gitlab.cn/jh/api/issues.html", Usage: "议题 API,中文文档:https://docs.gitlab.cn/jh/api/issues.html",
Flags: append(flag.Common(), flag.Page(), flag.PerPage(), Flags: append(flag.Common(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime(),
flag.AssigneeUsername(), flag.AuthorId(), flag.AuthorUsername(), flag.Confidential(), flag.AssigneeUsername(), flag.AuthorId(), flag.AuthorUsername(), flag.Confidential(),
flag.DueDate(), flag.Iids(), flag.In(), flag.IssueType(), flag.IterationId(), flag.Milestone(), flag.DueDate(), flag.Iids(), flag.In(), flag.IssueType(), flag.IterationId(), flag.Milestone(),
flag.MilestoneId(), flag.MyReactionEmoji(), flag.OrderBy(), flag.Scope(), flag.Search(), flag.MilestoneId(), flag.MyReactionEmoji(), flag.OrderBy(), flag.Scope(), flag.Search(),
...@@ -25,7 +25,7 @@ func Issues() *cli.Command { ...@@ -25,7 +25,7 @@ func Issues() *cli.Command {
{ {
Name: "list", Name: "list",
Usage: "列出议题", Usage: "列出议题",
Flags: append(flag.CommonTokenRequired(), flag.Page(), flag.PerPage(), Flags: append(flag.CommonTokenRequired(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime(),
flag.AssigneeUsername(), flag.AuthorId(), flag.AuthorUsername(), flag.Confidential(), flag.AssigneeUsername(), flag.AuthorId(), flag.AuthorUsername(), flag.Confidential(),
flag.DueDate(), flag.Iids(), flag.In(), flag.IssueType(), flag.IterationId(), flag.Milestone(), flag.DueDate(), flag.Iids(), flag.In(), flag.IssueType(), flag.IterationId(), flag.Milestone(),
flag.MilestoneId(), flag.MyReactionEmoji(), flag.OrderBy(), flag.Scope(), flag.Search(), flag.MilestoneId(), flag.MyReactionEmoji(), flag.OrderBy(), flag.Scope(), flag.Search(),
...@@ -35,6 +35,8 @@ func Issues() *cli.Command { ...@@ -35,6 +35,8 @@ func Issues() *cli.Command {
var token = context.String(constant.Token) var token = context.String(constant.Token)
var page = context.Int(constant.Page) var page = context.Int(constant.Page)
var perPage = context.Int(constant.PerPage) var perPage = context.Int(constant.PerPage)
var printJson = context.Bool(constant.PrintJson)
var printTime = context.Bool(constant.PrintTime)
// var assigneeId = context.Int(constant.AssigneeId) // var assigneeId = context.Int(constant.AssigneeId)
var assigneeUsername = context.String(constant.AssigneeUsername) var assigneeUsername = context.String(constant.AssigneeUsername)
...@@ -146,13 +148,60 @@ func Issues() *cli.Command { ...@@ -146,13 +148,60 @@ func Issues() *cli.Command {
fmt.Println("") fmt.Println("")
for index, issue := range issues { if printJson {
jsonData, err := json.Marshal(issue) if printTime {
if err != nil { for _, issue := range issues {
panic(err) jsonData, err := json.Marshal(issue)
if err != nil {
panic(err)
}
log.Printf("\n%s\n", string(jsonData))
fmt.Println("")
}
} else {
for _, issue := range issues {
jsonData, err := json.Marshal(issue)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", string(jsonData))
fmt.Println("")
}
}
} else {
if printTime {
for _, issue := range issues {
log.Printf("ID: %d\n", issue.ID)
log.Printf("Title: %s\n", issue.Title)
log.Printf("State: %s\n", issue.State)
log.Printf("CreatedAt: %s\n", issue.CreatedAt)
log.Printf("UpdatedAt: %s\n", issue.UpdatedAt)
log.Printf("ClosedAt: %s\n", issue.ClosedAt)
log.Printf("DueDate: %s\n", issue.DueDate)
log.Printf("Author: %s\n", issue.Author.Name)
log.Printf("Assignee: %s\n", issue.Assignee.Name)
log.Printf("Labels: %s\n", issue.Labels)
log.Printf("Milestone: %s\n", issue.Milestone.Title)
log.Printf("ProjectID: %d\n", issue.ProjectID)
fmt.Println("")
}
} else {
for _, issue := range issues {
fmt.Printf("ID: %d\n", issue.ID)
fmt.Printf("Title: %s\n", issue.Title)
fmt.Printf("State: %s\n", issue.State)
fmt.Printf("CreatedAt: %s\n", issue.CreatedAt)
fmt.Printf("UpdatedAt: %s\n", issue.UpdatedAt)
fmt.Printf("ClosedAt: %s\n", issue.ClosedAt)
fmt.Printf("DueDate: %s\n", issue.DueDate)
fmt.Printf("Author: %s\n", issue.Author.Name)
fmt.Printf("Labels: %s\n", issue.Labels)
fmt.Printf("ProjectID: %d\n", issue.ProjectID)
fmt.Println("")
}
} }
log.Printf("Index: %d: \n%s\n", index, string(jsonData))
fmt.Println("")
} }
return nil return nil
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册