Skip to content

Commit f1a6b7d

Browse files
committed
todo list: Remove MR and Issue lookups
While looking at some other code I discovered that type Todo contains a type TodoTarget which contains the information that I was pulling from the MR and Issue lookups. These lookups can be dropped and the code is simplified, there are fewer API calls, and 'lab todo list --pretty' is faster. Remove the MR and Issue lookups with the --pretty option. Signed-off-by: Prarit Bhargava <prarit@redhat.com>
1 parent debc30d commit f1a6b7d

1 file changed

Lines changed: 5 additions & 30 deletions

File tree

cmd/todo_list.go

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,39 +44,14 @@ var todoListCmd = &cobra.Command{
4444
continue
4545
}
4646

47-
delim := "merge_requests/"
48-
if todo.TargetType == "Issue" {
49-
delim = "issues/"
50-
}
51-
52-
s := strings.Split(todo.TargetURL, delim)
53-
s = strings.Split(s[1], "#")
54-
id, err := strconv.Atoi(s[0])
55-
if err != nil {
56-
log.Fatal(err)
57-
}
58-
59-
var (
60-
state string
61-
title string
62-
)
47+
var state string
6348
if todo.TargetType == "MergeRequest" {
64-
mr, err := lab.MRGet(todo.Project.ID, id)
65-
if err != nil {
66-
log.Fatal(err)
67-
}
68-
state = mr.State
69-
if mr.State == "opened" && mr.WorkInProgress {
49+
state = todo.Target.State
50+
if todo.Target.State == "opened" && todo.Target.WorkInProgress {
7051
state = "draft"
7152
}
72-
title = mr.Title
7353
} else {
74-
issue, err := lab.IssueGet(todo.Project.ID, id)
75-
if err != nil {
76-
log.Fatal(err)
77-
}
78-
state = issue.State
79-
title = issue.Title
54+
state = todo.Target.State
8055
}
8156

8257
switch state {
@@ -90,7 +65,7 @@ var todoListCmd = &cobra.Command{
9065
state = red(state)
9166
}
9267

93-
fmt.Printf("%s %d \"%s\" ", state, todo.ID, title)
68+
fmt.Printf("%s %d \"%s\" ", state, todo.ID, todo.Target.Title)
9469

9570
name := todo.Author.Name
9671
if lab.User() == todo.Author.Username {

0 commit comments

Comments
 (0)