Compare commits
No commits in common. "190ea6c7f39357634303cdc214bf6808bb0d4f71" and "b49dbe94b977ce39fb14af6c2c0fd9030f95261d" have entirely different histories.
190ea6c7f3
...
b49dbe94b9
|
@ -85,7 +85,7 @@ func (h *Handler) Backport() *ffcli.Command {
|
||||||
index = m[1]
|
index = m[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
branch := fmt.Sprintf("backport-%s-%s", to, index)
|
branch := fmt.Sprintf("backport-%s", index)
|
||||||
base := fmt.Sprintf("upstream/release/v1.%s", to)
|
base := fmt.Sprintf("upstream/release/v1.%s", to)
|
||||||
if err := h.Branch().ParseAndRun(ctx, []string{"--base", base, branch}); err != nil {
|
if err := h.Branch().ParseAndRun(ctx, []string{"--base", base, branch}); err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -11,8 +11,6 @@ import (
|
||||||
|
|
||||||
func (h *Handler) Cleanup() *ffcli.Command {
|
func (h *Handler) Cleanup() *ffcli.Command {
|
||||||
fs := flag.NewFlagSet("cleanup", flag.ContinueOnError)
|
fs := flag.NewFlagSet("cleanup", flag.ContinueOnError)
|
||||||
forceFlag := fs.Bool("force", false, "Force cleanup")
|
|
||||||
fs.BoolVar(forceFlag, "f", *forceFlag, "--force")
|
|
||||||
return &ffcli.Command{
|
return &ffcli.Command{
|
||||||
Name: "cleanup",
|
Name: "cleanup",
|
||||||
FlagSet: fs,
|
FlagSet: fs,
|
||||||
|
@ -25,7 +23,7 @@ func (h *Handler) Cleanup() *ffcli.Command {
|
||||||
|
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
if err := removeWorktree(h, ctx, arg, *forceFlag); err != nil {
|
if err := removeWorktree(h, ctx, arg); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +48,7 @@ func (h *Handler) Cleanup() *ffcli.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, rm := range remove {
|
for _, rm := range remove {
|
||||||
if err := removeWorktree(h, ctx, rm, *forceFlag); err != nil {
|
if err := removeWorktree(h, ctx, rm); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,13 +58,8 @@ func (h *Handler) Cleanup() *ffcli.Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func removeWorktree(h *Handler, ctx context.Context, name string, force bool) error {
|
func removeWorktree(h *Handler, ctx context.Context, name string) error {
|
||||||
args := []string{"worktree", "remove"}
|
if err := h.run(ctx, "git", "worktree", "remove", name); err != nil {
|
||||||
if force {
|
|
||||||
args = append(args, "--force")
|
|
||||||
}
|
|
||||||
args = append(args, name)
|
|
||||||
if err := h.run(ctx, "git", args...); err != nil {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return h.run(ctx, "git", "branch", "-D", name)
|
return h.run(ctx, "git", "branch", "-D", name)
|
||||||
|
|
|
@ -53,7 +53,6 @@ func New() (*ffcli.Command, error) {
|
||||||
handler.Init(),
|
handler.Init(),
|
||||||
handler.Post(),
|
handler.Post(),
|
||||||
handler.PR(),
|
handler.PR(),
|
||||||
handler.Tag(),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
c.Exec = func(_ context.Context, _ []string) error {
|
c.Exec = func(_ context.Context, _ []string) error {
|
||||||
|
|
|
@ -70,7 +70,7 @@ func (h *Handler) Frontport() *ffcli.Command {
|
||||||
index = m[1]
|
index = m[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
branch := fmt.Sprintf("frontport-%s-%s", from, index)
|
branch := fmt.Sprintf("frontport-%s", index)
|
||||||
|
|
||||||
base := *toFlag
|
base := *toFlag
|
||||||
if base == "" {
|
if base == "" {
|
||||||
|
|
|
@ -3,11 +3,10 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
|
|
||||||
"github.com/AlecAivazis/survey/v2"
|
"github.com/AlecAivazis/survey/v2"
|
||||||
"github.com/peterbourgon/ff/v3/ffcli"
|
"github.com/peterbourgon/ff/v3/ffcli"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *Handler) IDE() *ffcli.Command {
|
func (h *Handler) IDE() *ffcli.Command {
|
||||||
|
|
113
cmd/tag.go
113
cmd/tag.go
|
@ -1,113 +0,0 @@
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"regexp"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/AlecAivazis/survey/v2"
|
|
||||||
"github.com/go-git/go-git/v5"
|
|
||||||
"github.com/peterbourgon/ff/v3/ffcli"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
treeURL = "https://github.com/go-gitea/gitea/tree/%s"
|
|
||||||
versionRe = regexp.MustCompile(`v\d+\.\d+\.\d+`)
|
|
||||||
)
|
|
||||||
|
|
||||||
func (h *Handler) Tag() *ffcli.Command {
|
|
||||||
fs := flag.NewFlagSet("tag", flag.ContinueOnError)
|
|
||||||
return &ffcli.Command{
|
|
||||||
Name: "tag",
|
|
||||||
FlagSet: fs,
|
|
||||||
ShortUsage: "tag <branch>",
|
|
||||||
ShortHelp: "tag makes a signed tag for `branch`",
|
|
||||||
Exec: func(ctx context.Context, args []string) error {
|
|
||||||
if err := h.checkInit(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
h.fetch(ctx)
|
|
||||||
|
|
||||||
var branch string
|
|
||||||
if len(args) > 0 {
|
|
||||||
branch = args[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
if branch == "" {
|
|
||||||
var branches []string
|
|
||||||
remote, err := h.repo().Remote("upstream")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
refs, err := remote.List(&git.ListOptions{})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, ref := range refs {
|
|
||||||
if ref.Name().IsBranch() {
|
|
||||||
branches = append(branches, strings.TrimPrefix(ref.Name().String(), "refs/heads/"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sort.Strings(branches)
|
|
||||||
if err := survey.AskOne(&survey.Select{
|
|
||||||
Message: "Branch",
|
|
||||||
Options: branches,
|
|
||||||
}, &branch, survey.WithValidator(survey.Required)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !strings.HasPrefix(branch, "release") {
|
|
||||||
if !strings.HasPrefix(branch, "v") {
|
|
||||||
branch = fmt.Sprintf("v%s", branch)
|
|
||||||
}
|
|
||||||
branch = fmt.Sprintf("release/%s", branch)
|
|
||||||
}
|
|
||||||
|
|
||||||
var version string
|
|
||||||
if err := survey.AskOne(&survey.Input{
|
|
||||||
Message: "Version",
|
|
||||||
}, &version, survey.WithValidator(func(ans any) error {
|
|
||||||
if !versionRe.MatchString(fmt.Sprint(ans)) {
|
|
||||||
return errors.New("version isn't valid v$maj.$min.$")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
})); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
workspaceName := strings.ReplaceAll(branch, "/", "-")
|
|
||||||
if err := h.Branch().ParseAndRun(ctx, []string{"--base", branch, workspaceName}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var changelog string
|
|
||||||
if err := survey.AskOne(&survey.Editor{
|
|
||||||
Message: "Changelog",
|
|
||||||
FileName: "*.md",
|
|
||||||
}, &changelog, survey.WithValidator(survey.Required)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
fi, err := os.Create(filepath.Join(h.Config.WorkspaceBranch(workspaceName), "release.notes"))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := fi.WriteString(changelog); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := fi.Close(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
run(ctx, h.Config.WorkspaceBranch(workspaceName), "git", "tag", "-s", "-F", "release.notes", version)
|
|
||||||
|
|
||||||
fmt.Printf("cd %s && git push upstream %s \n", h.Config.WorkspaceBranch(workspaceName), version)
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue