This repository was archived by the owner on May 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathissues.go
139 lines (116 loc) · 3.03 KB
/
issues.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright 2018 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package cmd
import (
"fmt"
"log"
"os"
"strconv"
"strings"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli"
)
// CmdIssues represents to login a gitea server.
var CmdIssues = cli.Command{
Name: "issues",
Usage: "Operate with issues of the repository",
Description: `Operate with issues of the repository`,
Action: runIssues,
Subcommands: []cli.Command{
CmdIssuesList,
CmdIssuesCreate,
},
Flags: append([]cli.Flag{}, RepoDefaultFlags...),
}
// CmdIssuesList represents a sub command of issues to list issues
var CmdIssuesList = cli.Command{
Name: "ls",
Usage: "List issues of the repository",
Description: `List issues of the repository`,
Action: runIssuesList,
}
func runIssues(ctx *cli.Context) error {
if len(os.Args) == 3 {
return runIssueDetail(ctx, os.Args[2])
}
return runIssuesList(ctx)
}
func runIssueDetail(ctx *cli.Context, index string) error {
login, owner, repo := initCommand()
if strings.HasPrefix(index, "#") {
index = index[1:]
}
idx, err := strconv.ParseInt(index, 10, 64)
if err != nil {
return err
}
issue, err := login.Client().GetIssue(owner, repo, idx)
if err != nil {
return err
}
fmt.Printf("#%d %s\n%s created %s\n\n%s", issue.Index,
issue.Title,
issue.Poster.UserName,
issue.Created.Format("2006-01-02 15:04:05"),
issue.Body,
)
return nil
}
func runIssuesList(ctx *cli.Context) error {
login, owner, repo := initCommand()
issues, err := login.Client().ListRepoIssues(owner, repo, gitea.ListIssueOption{
Page: 0,
State: string(gitea.StateOpen),
})
if err != nil {
log.Fatal(err)
}
if len(issues) == 0 {
fmt.Println("No issues left")
return nil
}
for _, issue := range issues {
name := issue.Poster.FullName
if len(name) == 0 {
name = issue.Poster.UserName
}
fmt.Printf("#%d\t%s\t%s\t%s\n", issue.Index, name, issue.Updated.Format("2006-01-02 15:04:05"), issue.Title)
}
return nil
}
// CmdIssuesCreate represents a sub command of issues to create issue
var CmdIssuesCreate = cli.Command{
Name: "create",
Usage: "Create an issue on repository",
Description: `Create an issue on repository`,
Action: runIssuesCreate,
Flags: append([]cli.Flag{
cli.StringFlag{
Name: "title, t",
Usage: "issue title to create",
},
cli.StringFlag{
Name: "body, b",
Usage: "issue body to create",
},
}, RepoDefaultFlags...),
}
func runIssuesCreate(ctx *cli.Context) error {
login, owner, repo := initCommand()
_, err := login.Client().CreateIssue(owner, repo, gitea.CreateIssueOption{
Title: ctx.String("title"),
Body: ctx.String("body"),
// TODO:
//Assignee string `json:"assignee"`
//Assignees []string `json:"assignees"`
//Deadline *time.Time `json:"due_date"`
//Milestone int64 `json:"milestone"`
//Labels []int64 `json:"labels"`
//Closed bool `json:"closed"`
})
if err != nil {
log.Fatal(err)
}
return nil
}