Skip to content

Commit

Permalink
todo list: Remove MR and Issue lookups
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
prarit committed May 20, 2021
1 parent debc30d commit f1a6b7d
Showing 1 changed file with 5 additions and 30 deletions.
35 changes: 5 additions & 30 deletions cmd/todo_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,39 +44,14 @@ var todoListCmd = &cobra.Command{
continue
}

delim := "merge_requests/"
if todo.TargetType == "Issue" {
delim = "issues/"
}

s := strings.Split(todo.TargetURL, delim)
s = strings.Split(s[1], "#")
id, err := strconv.Atoi(s[0])
if err != nil {
log.Fatal(err)
}

var (
state string
title string
)
var state string
if todo.TargetType == "MergeRequest" {
mr, err := lab.MRGet(todo.Project.ID, id)
if err != nil {
log.Fatal(err)
}
state = mr.State
if mr.State == "opened" && mr.WorkInProgress {
state = todo.Target.State
if todo.Target.State == "opened" && todo.Target.WorkInProgress {
state = "draft"
}
title = mr.Title
} else {
issue, err := lab.IssueGet(todo.Project.ID, id)
if err != nil {
log.Fatal(err)
}
state = issue.State
title = issue.Title
state = todo.Target.State
}

switch state {
Expand All @@ -90,7 +65,7 @@ var todoListCmd = &cobra.Command{
state = red(state)
}

fmt.Printf("%s %d \"%s\" ", state, todo.ID, title)
fmt.Printf("%s %d \"%s\" ", state, todo.ID, todo.Target.Title)

name := todo.Author.Name
if lab.User() == todo.Author.Username {
Expand Down

0 comments on commit f1a6b7d

Please sign in to comment.