mirror of
https://gitea.com/jolheiser/sip
synced 2024-11-22 19:51:58 +01:00
67326a7948
Signed-off-by: jolheiser <john.olheiser@gmail.com>
89 lines
1.7 KiB
Go
89 lines
1.7 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"gitea.com/jolheiser/sip/prompt"
|
|
|
|
"gitea.com/jolheiser/sip/flag"
|
|
"gitea.com/jolheiser/sip/markdown"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
"github.com/urfave/cli/v2"
|
|
"go.jolheiser.com/beaver/color"
|
|
)
|
|
|
|
var (
|
|
titleFlag = &cli.StringFlag{
|
|
Name: "title",
|
|
Usage: "Title",
|
|
}
|
|
descriptionFlag = &cli.StringFlag{
|
|
Name: "description",
|
|
Usage: "Description",
|
|
}
|
|
confirmFlag = &cli.BoolFlag{
|
|
Name: "confirm",
|
|
Usage: "Confirm",
|
|
}
|
|
)
|
|
|
|
var IssuesCreate = cli.Command{
|
|
Name: "create",
|
|
Aliases: []string{"new"},
|
|
Usage: "Create a new issue",
|
|
Action: doIssueCreate,
|
|
}
|
|
|
|
func doIssueCreate(ctx *cli.Context) error {
|
|
fmt.Println()
|
|
url := color.New(color.FgYellow).Format(flag.FullURL())
|
|
fmt.Println(color.New(color.FgCyan).Format("Creating a new issue for"), url)
|
|
|
|
client, err := getClient(true)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var confirmed bool
|
|
var title, body string
|
|
|
|
for !confirmed {
|
|
t, err := prompt.Input(ctx, titleFlag, title, true)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
d, err := prompt.Multi(ctx, descriptionFlag, body, false)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
title = t
|
|
body = d
|
|
|
|
preview, err := markdown.Render(body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Printf("%s\n\n%s\n", title, preview)
|
|
|
|
c, err := prompt.Confirm(ctx, confirmFlag, true, true)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
confirmed = c
|
|
}
|
|
|
|
issue, _, err := client.CreateIssue(flag.Owner, flag.Repo, gitea.CreateIssueOption{Title: title, Body: body})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
info := color.Info
|
|
cyan := color.New(color.FgCyan)
|
|
fmt.Println(info.Format("Issue"), cyan.Format(fmt.Sprintf("#%d", issue.Index)), info.Format("created!"))
|
|
fmt.Println(cyan.Format(fmt.Sprintf("%s/issues/%d", flag.FullURL(), issue.Index)))
|
|
return nil
|
|
}
|