github.com/zaquestion/lab@v0.25.1/cmd/todo_issue.go (about)

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/MakeNowJust/heredoc/v2"
     7  	"github.com/spf13/cobra"
     8  	lab "github.com/zaquestion/lab/internal/gitlab"
     9  )
    10  
    11  var todoIssueCmd = &cobra.Command{
    12  	Use:   "issue [remote] <id>",
    13  	Short: "Add a Issue to Todo list",
    14  	Example: heredoc.Doc(`
    15  		lab todo issue 5678               #adds issue 5678 to user's Todo list
    16  		lab todo issue otherRemote 91011`),
    17  	PersistentPreRun: labPersistentPreRun,
    18  	Run: func(cmd *cobra.Command, args []string) {
    19  		rn, num, err := parseArgsRemoteAndID(args)
    20  		if err != nil {
    21  			log.Fatal(err)
    22  		}
    23  
    24  		todoAddIssue(rn, int(num))
    25  
    26  	},
    27  }
    28  
    29  func todoAddIssue(project string, issueNum int) {
    30  	todoID, err := lab.TodoIssueCreate(project, issueNum)
    31  	if err != nil {
    32  		if err == lab.ErrNotModified {
    33  			log.Fatalf("Todo entry already exists for Issue !%d", issueNum)
    34  		}
    35  		log.Fatal(err)
    36  	}
    37  
    38  	issue, err := lab.IssueGet(project, issueNum)
    39  	if err != nil {
    40  		log.Fatal(err)
    41  	}
    42  	fmt.Println(todoID, issue.WebURL)
    43  }
    44  
    45  func init() {
    46  	todoCmd.AddCommand(todoIssueCmd)
    47  }