mirror of
https://gitea.com/jolheiser/sip
synced 2024-11-22 19:51:58 +01:00
448e12ce38
Ran imp Signed-off-by: jolheiser <john.olheiser@gmail.com> Co-authored-by: jolheiser <john.olheiser@gmail.com> Reviewed-on: https://gitea.com/jolheiser/sip/pulls/17
90 lines
2.0 KiB
Go
90 lines
2.0 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gitea.com/jolheiser/sip/modules/git"
|
|
|
|
"code.gitea.io/sdk/gitea"
|
|
"github.com/AlecAivazis/survey/v2"
|
|
"github.com/urfave/cli/v2"
|
|
"go.jolheiser.com/beaver/color"
|
|
)
|
|
|
|
var ReleaseCreate = cli.Command{
|
|
Name: "create",
|
|
Aliases: []string{"new"},
|
|
Usage: "Create a new release",
|
|
Action: doReleaseCreate,
|
|
}
|
|
|
|
func doReleaseCreate(ctx *cli.Context) error {
|
|
client, err := getClient(ctx, true)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
questions := []*survey.Question{
|
|
{
|
|
Name: "tag",
|
|
Prompt: &survey.Input{Message: "Tag Name"},
|
|
Validate: survey.Required,
|
|
},
|
|
{
|
|
Name: "target",
|
|
Prompt: &survey.Input{Message: "Target", Default: git.Branch(), Help: "Target ref, branch name or commit SHA"},
|
|
Validate: survey.Required,
|
|
},
|
|
{
|
|
Name: "title",
|
|
Prompt: &survey.Input{Message: "Title"},
|
|
Validate: survey.Required,
|
|
},
|
|
{
|
|
Name: "note",
|
|
Prompt: &survey.Multiline{Message: "Notes"},
|
|
},
|
|
{
|
|
Name: "draft",
|
|
Prompt: &survey.Confirm{Message: "Draft", Default: false},
|
|
Validate: survey.Required,
|
|
},
|
|
{
|
|
Name: "pre",
|
|
Prompt: &survey.Confirm{Message: "Pre-Release", Default: false},
|
|
Validate: survey.Required,
|
|
},
|
|
}
|
|
answers := struct {
|
|
Tag string
|
|
Target string
|
|
Title string
|
|
Note string
|
|
Draft bool
|
|
Pre bool
|
|
}{}
|
|
|
|
if err := survey.Ask(questions, &answers); err != nil {
|
|
return err
|
|
}
|
|
|
|
release, err := client.CreateRelease(ctx.String("owner"), ctx.String("repo"), gitea.CreateReleaseOption{
|
|
TagName: answers.Tag,
|
|
Target: answers.Target,
|
|
Title: answers.Title,
|
|
Note: answers.Note,
|
|
IsDraft: answers.Draft,
|
|
IsPrerelease: answers.Pre,
|
|
})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
info := color.Info
|
|
cyan := color.New(color.FgCyan)
|
|
fmt.Println(info.Format("Release"), cyan.Format(release.TagName), info.Format("created!"))
|
|
// TODO Change to specific release page once supported
|
|
fmt.Println(cyan.Format(fmt.Sprintf("%s/%s/%s/releases/", ctx.String("url"), ctx.String("owner"), ctx.String("repo"))))
|
|
return nil
|
|
}
|