1
0
mirror of https://gitea.com/jolheiser/sip synced 2024-11-22 11:41:59 +01:00

Update Beaver and fix bugs (#6)

Fix CI test

Fix origin names in PR create

Add aliases for new issue/PR and fix issues search

Update beaver and squash some bugs

Signed-off-by: jolheiser <john.olheiser@gmail.com>

Co-authored-by: jolheiser <john.olheiser@gmail.com>
Reviewed-on: https://gitea.com/jolheiser/sip/pulls/6
This commit is contained in:
John Olheiser 2020-02-27 02:53:11 +00:00
parent 5929bebe01
commit bb773780df
17 changed files with 67 additions and 42 deletions

@ -17,7 +17,7 @@ steps:
environment:
GOPROXY: https://goproxy.cn
commands:
- go test -race
- make test
- go build
- name: check

@ -2,11 +2,13 @@ package cmd
import (
"code.gitea.io/sdk/gitea"
"errors"
"fmt"
"gitea.com/jolheiser/sip/modules/config"
"gitea.com/jolheiser/sip/modules/git"
"github.com/AlecAivazis/survey/v2"
"github.com/urfave/cli/v2"
"go.jolheiser.com/beaver/color"
"sync"
)
@ -56,6 +58,9 @@ func requireToken(ctx *cli.Context) (string, error) {
if ctx.IsSet("token") {
return getToken(ctx.String("token")), nil
}
if len(config.Tokens) == 0 {
return "", errors.New(color.Error.Wrap("No tokens found! Add one with #{sip token create}", color.New(color.FgMagenta)))
}
tokenMap := make(map[string]config.Token)
opts := make([]string, len(config.Tokens))
for idx, token := range config.Tokens {
@ -87,11 +92,19 @@ func getClient(ctx *cli.Context) *gitea.Client {
return gitea.NewClient(ctx.String("url"), getToken(ctx.String("token")))
}
func defRemote(remote, def string) string {
if remote == "" {
return def
}
return remote
}
func getUpstreamRepo() []string {
upstreamOnce.Do(func() {
upstreamRepo = git.GetRepo(config.Upstream)
if upstreamRepo == nil {
upstreamRepo = git.GetRepo(config.Origin)
var err error
upstreamRepo, err = git.GetRepo(defRemote(config.Upstream, "upstream"))
if err != nil {
upstreamRepo = getOriginRepo()
}
})
return upstreamRepo
@ -99,7 +112,11 @@ func getUpstreamRepo() []string {
func getOriginRepo() []string {
originOnce.Do(func() {
originRepo = git.GetRepo(config.Origin)
var err error
originRepo, err = git.GetRepo(defRemote(config.Origin, "origin"))
if err != nil {
originRepo = []string{"https://gitea.com", "jolheiser", "sip"}
}
})
return originRepo
}

@ -1,10 +1,10 @@
package cmd
import (
"gitea.com/jolheiser/beaver"
"gitea.com/jolheiser/sip/modules/config"
"github.com/AlecAivazis/survey/v2"
"github.com/urfave/cli/v2"
"go.jolheiser.com/beaver"
)
var Config = cli.Command{

@ -4,12 +4,12 @@ import (
"code.gitea.io/sdk/gitea"
"errors"
"fmt"
"gitea.com/jolheiser/beaver"
"gitea.com/jolheiser/beaver/color"
"gitea.com/jolheiser/sip/modules/markdown"
"gitea.com/jolheiser/sip/modules/sdk"
"github.com/AlecAivazis/survey/v2"
"github.com/urfave/cli/v2"
"go.jolheiser.com/beaver"
"go.jolheiser.com/beaver/color"
"strconv"
"strings"
)
@ -115,10 +115,8 @@ func queryIssues(ctx *cli.Context, client *gitea.Client, pulls bool) ([]*gitea.I
filtered := make([]*gitea.Issue, 0)
for _, issue := range issues {
if pulls {
if issue.PullRequest != nil {
filtered = append(filtered, issue)
}
if (pulls && issue.PullRequest == nil) ||
(!pulls && issue.PullRequest != nil) {
continue
}
filtered = append(filtered, issue)

@ -3,16 +3,17 @@ package cmd
import (
"code.gitea.io/sdk/gitea"
"fmt"
"gitea.com/jolheiser/beaver/color"
"gitea.com/jolheiser/sip/modules/markdown"
"github.com/AlecAivazis/survey/v2"
"github.com/urfave/cli/v2"
"go.jolheiser.com/beaver/color"
)
var IssuesCreate = cli.Command{
Name: "create",
Usage: "Create a new issue",
Action: doIssueCreate,
Name: "create",
Aliases: []string{"new"},
Usage: "Create a new issue",
Action: doIssueCreate,
}
func doIssueCreate(ctx *cli.Context) error {

@ -4,11 +4,11 @@ import (
"code.gitea.io/sdk/gitea"
"errors"
"fmt"
"gitea.com/jolheiser/beaver"
"gitea.com/jolheiser/sip/modules/config"
"github.com/AlecAivazis/survey/v2"
"github.com/huandu/xstrings"
"github.com/urfave/cli/v2"
"go.jolheiser.com/beaver"
"os"
"os/exec"
"strconv"

@ -3,17 +3,18 @@ package cmd
import (
"code.gitea.io/sdk/gitea"
"fmt"
"gitea.com/jolheiser/beaver/color"
"gitea.com/jolheiser/sip/modules/git"
"gitea.com/jolheiser/sip/modules/markdown"
"github.com/AlecAivazis/survey/v2"
"github.com/urfave/cli/v2"
"go.jolheiser.com/beaver/color"
)
var PullsCreate = cli.Command{
Name: "create",
Usage: "Create a new pull request",
Action: doPullCreate,
Name: "create",
Aliases: []string{"new"},
Usage: "Create a new pull request",
Action: doPullCreate,
}
func doPullCreate(ctx *cli.Context) error {
@ -48,10 +49,14 @@ func doPullCreate(ctx *cli.Context) error {
heads := make([]string, len(origins))
defOrigin := origins[0].Name
for idx, origin := range origins {
if origin.Name == git.Branch() {
defOrigin = getOriginRepo()[1] + ":" + origin.Name
originName := origin.Name
if ctx.String("owner") != getOriginRepo()[1] {
originName = getOriginRepo()[1] + ":" + originName
}
heads[idx] = getOriginRepo()[1] + ":" + origin.Name
if origin.Name == git.Branch() {
defOrigin = originName
}
heads[idx] = originName
}
var confirmed bool

@ -3,10 +3,10 @@ package cmd
import (
"code.gitea.io/sdk/gitea"
"fmt"
"gitea.com/jolheiser/beaver/color"
"gitea.com/jolheiser/sip/modules/git"
"gitea.com/jolheiser/sip/modules/sdk"
"github.com/urfave/cli/v2"
"go.jolheiser.com/beaver/color"
"strconv"
)

@ -2,10 +2,10 @@ package cmd
import (
"code.gitea.io/sdk/gitea"
"gitea.com/jolheiser/beaver"
"gitea.com/jolheiser/beaver/color"
"gitea.com/jolheiser/sip/modules/sdk"
"github.com/urfave/cli/v2"
"go.jolheiser.com/beaver"
"go.jolheiser.com/beaver/color"
"strconv"
)

@ -1,10 +1,10 @@
package cmd
import (
"gitea.com/jolheiser/beaver"
"gitea.com/jolheiser/beaver/color"
"gitea.com/jolheiser/sip/modules/config"
"github.com/urfave/cli/v2"
"go.jolheiser.com/beaver"
"go.jolheiser.com/beaver/color"
)
var Tokens = cli.Command{
@ -20,7 +20,7 @@ var Tokens = cli.Command{
func doTokenList(ctx *cli.Context) error {
if len(config.Tokens) == 0 {
beaver.Errorf("No tokens found! Add one with %s", color.New(color.FgMagenta).Format("sip token create"))
beaver.Errorf("No tokens found! Add one with %s", color.FgMagenta.Format("sip token create"))
}
for idx, token := range config.Tokens {
beaver.Infof("%d. %s (%s)", idx+1, token.Name, token.URL)

@ -3,10 +3,10 @@ package cmd
import (
"code.gitea.io/sdk/gitea"
"errors"
"gitea.com/jolheiser/beaver"
"gitea.com/jolheiser/sip/modules/config"
"github.com/AlecAivazis/survey/v2"
"github.com/urfave/cli/v2"
"go.jolheiser.com/beaver"
)
var TokensAdd = cli.Command{

@ -2,10 +2,10 @@ package cmd
import (
"fmt"
"gitea.com/jolheiser/beaver"
"gitea.com/jolheiser/sip/modules/config"
"github.com/AlecAivazis/survey/v2"
"github.com/urfave/cli/v2"
"go.jolheiser.com/beaver"
)
var TokensRemove = cli.Command{

4
go.mod

@ -4,7 +4,6 @@ go 1.13
require (
code.gitea.io/sdk/gitea v0.11.0
gitea.com/jolheiser/beaver v1.0.0
github.com/AlecAivazis/survey/v2 v2.0.5
github.com/BurntSushi/toml v0.3.1
github.com/charmbracelet/glamour v0.1.0
@ -15,7 +14,8 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/sergi/go-diff v1.1.0 // indirect
github.com/urfave/cli/v2 v2.1.1
go.jolheiser.com/beaver v1.0.2
golang.org/x/crypto v0.0.0-20200210222208-86ce3cb69678 // indirect
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 // indirect
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect
)

8
go.sum

@ -1,7 +1,7 @@
code.gitea.io/sdk/gitea v0.11.0 h1:XgZtmImZsjMC+Z1WBfO6bYTCOJiGp+7w0HKmfhTwytw=
code.gitea.io/sdk/gitea v0.11.0/go.mod h1:z3uwDV/b9Ls47NGukYM9XhnHtqPh/J+t40lsUrR6JDY=
gitea.com/jolheiser/beaver v1.0.0 h1:IfNMhp7+DUaM0kaNwho4RWfuebCsa8A/kxtZBngFjHk=
gitea.com/jolheiser/beaver v1.0.0/go.mod h1:2mUGl6ZGKY/Y9u36iR4bqOPrHhr4C22cxkR8ei2G06I=
go.jolheiser.com/beaver v1.0.0 h1:IfNMhp7+DUaM0kaNwho4RWfuebCsa8A/kxtZBngFjHk=
go.jolheiser.com/beaver v1.0.0/go.mod h1:2mUGl6ZGKY/Y9u36iR4bqOPrHhr4C22cxkR8ei2G06I=
github.com/AlecAivazis/survey/v2 v2.0.5 h1:xpZp+Q55wi5C7Iaze+40onHnEkex1jSc34CltJjOoPM=
github.com/AlecAivazis/survey/v2 v2.0.5/go.mod h1:WYBhg6f0y/fNYUuesWQc0PKbJcEliGcYHB9sNT3Bg74=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
@ -111,6 +111,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/yuin/goldmark v1.1.19 h1:0s2/60x0XsFCXHeFut+F3azDVAAyIMyUfJRbRexiTYs=
github.com/yuin/goldmark v1.1.19/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
go.jolheiser.com/beaver v1.0.2 h1:KA2D6iO8MQhZi1nZYi/Chak/f1Cxfrs6b1XO623+Khk=
go.jolheiser.com/beaver v1.0.2/go.mod h1:7X4F5+XOGSC3LejTShoBdqtRCnPWcnRgmYGmG3EKW8g=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200210222208-86ce3cb69678 h1:wCWoJcFExDgyYx2m2hpHgwz8W3+FPdfldvIgzqDIhyg=
@ -127,6 +129,8 @@ golang.org/x/sys v0.0.0-20190530182044-ad28b68e88f1/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 h1:sfkvUWPNGwSV+8/fNqctR5lS2AqCSqYwXdrjCxp/dXo=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=

@ -1,9 +1,9 @@
package main
import (
"gitea.com/jolheiser/beaver"
"gitea.com/jolheiser/sip/cmd"
"github.com/urfave/cli/v2"
"go.jolheiser.com/beaver"
"os"
)

@ -2,9 +2,9 @@ package config
import (
"fmt"
"gitea.com/jolheiser/beaver"
"github.com/BurntSushi/toml"
"github.com/mitchellh/go-homedir"
"go.jolheiser.com/beaver"
"os"
"path"
)

@ -6,11 +6,11 @@ import (
)
// GetRepo returns a repositories parts
func GetRepo(remoteName string) []string {
func GetRepo(remoteName string) ([]string, error) {
cmd := exec.Command("git", "remote", "get-url", remoteName)
out, err := cmd.Output()
if err != nil {
return []string{"https://gitea.com", "jolheiser", "sip"}
return nil, err
}
remote := strings.TrimSpace(string(out))
@ -21,14 +21,14 @@ func GetRepo(remoteName string) []string {
parts := strings.Split(remote, ":")
domain := "https://" + parts[0]
ownerRepo := strings.Split(parts[1], "/")
return []string{domain, ownerRepo[0], strings.TrimSuffix(ownerRepo[1], ".git")}
return []string{domain, ownerRepo[0], strings.TrimSuffix(ownerRepo[1], ".git")}, nil
}
// HTTP(S)
parts := strings.Split(remote, "/")
domain := parts[:len(parts)-2]
ownerRepo := parts[len(parts)-2:]
return []string{strings.Join(domain, "/"), ownerRepo[0], strings.TrimSuffix(ownerRepo[1], ".git")}
return []string{strings.Join(domain, "/"), ownerRepo[0], strings.TrimSuffix(ownerRepo[1], ".git")}, nil
}
// Branches returns current branch