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

Initial progress

Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
jolheiser 2020-02-14 14:46:02 -06:00
commit 5b7b970a06
No known key found for this signature in database
GPG Key ID: B853ADA5DA7BBF7A
16 changed files with 889 additions and 0 deletions

5
.gitignore vendored Normal file

@ -0,0 +1,5 @@
# GoLand
.idea/
# Tea
/tea*

23
.golangci.yml Normal file

@ -0,0 +1,23 @@
linters:
enable:
- deadcode
- dogsled
- dupl
- errcheck
- gocognit
- goconst
- gocritic
- gocyclo
- gofmt
- golint
- gosimple
- govet
- maligned
- misspell
- prealloc
- staticcheck
- structcheck
- typecheck
- unparam
- unused
- varcheck

35
Makefile Normal file

@ -0,0 +1,35 @@
GO ?= go
ifneq ($(DRONE_TAG),)
VERSION ?= $(subst v,,$(DRONE_TAG))
LONG_VERSION ?= $(VERSION)
else
ifneq ($(DRONE_BRANCH),)
VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
else
VERSION ?= master
endif
LONG_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
endif
LDFLAGS := $(LDFLAGS) -X "main.Version=$(LONG_VERSION)"
.PHONY: build
build:
$(GO) build -ldflags '-s -w $(LDFLAGS)'
.PHONY: lint
lint:
@hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
export BINARY="golangci-lint"; \
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.1; \
fi
golangci-lint run --timeout 5m
.PHONY: fmt
fmt:
$(GO) fmt ./...
.PHONY: test
test:
$(GO) test -race ./...

2
README.md Normal file

@ -0,0 +1,2 @@
# Tea (alternative)
CLI for interacting with Gitea

101
cmd/cmd.go Normal file

@ -0,0 +1,101 @@
package cmd
import (
"context"
"errors"
"gitea.com/jolheiser/gitea-sdk"
"gitea.com/jolheiser/tea/modules/config"
"github.com/urfave/cli/v2"
"os/exec"
"strings"
"sync"
)
var (
Flags = []cli.Flag{
&cli.StringFlag{
Name: "url",
Aliases: []string{"u"},
Usage: "The base URL to the Gitea instance",
Value: getRepo()[0],
},
&cli.StringFlag{
Name: "owner",
Aliases: []string{"o"},
Usage: "The owner to target",
Value: getRepo()[1],
},
&cli.StringFlag{
Name: "repo",
Aliases: []string{"r"},
Usage: "The repo to target",
Value: getRepo()[2],
},
&cli.StringFlag{
Name: "login",
Aliases: []string{"l"},
Usage: "The login token to use (by name)",
},
}
once sync.Once
repo []string
)
func getAuth(name string) context.Context {
if name == "" {
return context.Background()
}
for _, login := range config.Logins {
if login.Name == name {
return context.WithValue(context.Background(), gitea.ContextAccessToken, login.Token)
}
}
return context.Background()
}
func getClient(baseURL string) *gitea.APIClient {
return gitea.NewAPIClient(&gitea.Configuration{
BasePath: baseURL + "/api/v1",
DefaultHeader: make(map[string]string),
UserAgent: "Tea/1.0.0/go",
})
}
func getRepo() []string {
once.Do(func() {
cmd := exec.Command("git", "remote", "get-url", "origin")
out, err := cmd.Output()
if err != nil {
repo = []string{"", ""}
}
remote := strings.TrimSpace(string(out))
if strings.Contains(remote, "@") { // SSH
remote = remote[strings.Index(remote, "@")+1:]
parts := strings.Split(remote, ":")
domain := "https://" + parts[0]
ownerRepo := strings.Split(parts[1], "/")
repo = []string{domain, ownerRepo[0], strings.TrimRight(ownerRepo[1], ".git")}
} else { // HTTP(S)
parts := strings.Split(remote, "/")
domain := parts[:len(parts)-2]
ownerRepo := parts[len(parts)-2:]
repo = []string{strings.Join(domain, "/"), ownerRepo[0], strings.TrimRight(ownerRepo[1], ".git")}
}
})
return repo
}
func fullName() string {
return repo[1] + "/" + repo[2]
}
func validateFullName(ans interface{}) error {
fullName := ans.(string)
ownerRepo := strings.Split(fullName, "/")
if len(ownerRepo) != 2 {
return errors.New("full repo name should be in form `owner/repo`")
}
return nil
}

126
cmd/issues.go Normal file

@ -0,0 +1,126 @@
package cmd
import (
"context"
"fmt"
"gitea.com/jolheiser/beaver/color"
"gitea.com/jolheiser/gitea-sdk"
"gitea.com/jolheiser/tea/modules/markdown"
"gitea.com/jolheiser/tea/modules/stdout"
"github.com/AlecAivazis/survey/v2"
"github.com/antihax/optional"
"github.com/urfave/cli/v2"
"strconv"
"strings"
)
var Issues = cli.Command{
Name: "issues",
Aliases: []string{"issue"},
Usage: "Commands for interacting with issues",
Action: doSearchIssues,
}
func doSearchIssues(ctx *cli.Context) error {
auth := getAuth(ctx.String("login"))
client := getClient(ctx.String("url"))
questions := []*survey.Question{
{
Name: "repo",
Prompt: &survey.Input{Message: "Full repository name", Default: fullName()},
Validate: validateFullName,
},
{
Name: "query",
Prompt: &survey.Input{Message: "Search query"},
},
}
answers := struct {
Repo string
Query string
}{}
if err := survey.Ask(questions, &answers); err != nil {
return err
}
ownerRepo := strings.Split(answers.Repo, "/")
issues, err := getAllIssues(auth, client, ownerRepo[0], ownerRepo[1], &gitea.IssueListIssuesOpts{Q: optional.NewString(answers.Query)})
if err != nil {
return err
}
if len(issues) == 0 {
stdout.Red("No issues found")
return nil
}
issueMap := make(map[string]gitea.Issue)
for _, issue := range issues {
index := color.New(color.FgCyan).Format("#" + strconv.Itoa(int(issue.Number)))
title := color.New(color.FgYellow).Format(issue.Title)
lbls := make([]string, len(issue.Labels))
for idx, label := range issue.Labels {
lbls[idx] = label.Name
}
var labels string
if len(lbls) > 0 {
labels = color.New(color.FgHiBlack).Format("(" + strings.Join(lbls, ",") + ")")
}
issueMap[fmt.Sprintf("%s %s %s", index, title, labels)] = issue
}
list := make([]string, 0)
for key := range issueMap {
list = append(list, key)
}
sel := &survey.Select{Options: list, Message: "Matching issues, select one to see more details"}
var selection string
if err := survey.AskOne(sel, &selection); err != nil {
return err
}
body, err := markdown.Render(issueMap[selection].Body)
if err != nil {
return err
}
fmt.Println(body)
return nil
}
func getAllIssues(auth context.Context, client *gitea.APIClient, owner, repo string, opts *gitea.IssueListIssuesOpts) ([]gitea.Issue, error) {
opts.State = optional.NewString("open")
issuesOpen, err := getIssues(auth, client, owner, repo, opts)
if err != nil {
return nil, err
}
opts.State = optional.NewString("closed")
issuesClosed, err := getIssues(auth, client, owner, repo, opts)
if err != nil {
return nil, err
}
return append(issuesOpen, issuesClosed...), nil
}
func getIssues(auth context.Context, client *gitea.APIClient, owner, repo string, opts *gitea.IssueListIssuesOpts) ([]gitea.Issue, error) {
issues := make([]gitea.Issue, 0)
opts.Type_ = optional.NewString("issues")
var p int32 = 1
for {
opts.Page = optional.NewInt32(p)
list, _, err := client.IssueApi.IssueListIssues(auth, owner, repo, opts)
if err != nil {
return issues, err
}
p++
issues = append(issues, list...)
if len(list) == 0 {
break
}
}
return issues, nil
}

169
cmd/login.go Normal file

@ -0,0 +1,169 @@
package cmd
import (
"context"
"encoding/json"
"errors"
"fmt"
"gitea.com/jolheiser/beaver"
"gitea.com/jolheiser/gitea-sdk"
"gitea.com/jolheiser/tea/modules/config"
"github.com/AlecAivazis/survey/v2"
"github.com/antihax/optional"
"github.com/urfave/cli/v2"
"io/ioutil"
"net/http"
)
var (
Login = cli.Command{
Name: "login",
Usage: "Log in to a Gitea server",
Action: doLogin,
Subcommands: []*cli.Command{
{
Name: "auto",
Usage: "Create a new token via API",
Action: doLoginAuto,
},
},
}
)
func doLogin(ctx *cli.Context) error {
questions := []*survey.Question{
{
Name: "name",
Prompt: &survey.Input{Message: "Name for this login"},
Validate: validateLoginName,
},
{
Name: "url",
Prompt: &survey.Input{Message: "URL for the Gitea instance", Default: ctx.String("url")},
Validate: survey.Required,
},
{
Name: "token",
Prompt: &survey.Input{Message: "API Token"},
Validate: survey.Required,
},
}
answers := struct {
Name string
URL string
Token string
}{}
if err := survey.Ask(questions, &answers); err != nil {
return err
}
config.Logins = append(config.Logins, config.Login{
Name: answers.Name,
URL: answers.URL,
Token: answers.Token,
})
if err := config.Save(); err != nil {
return err
}
beaver.Infof("Login saved! You can refer to it by using `--login %s` with commands!", answers.Name)
return nil
}
func doLoginAuto(ctx *cli.Context) error {
questions := []*survey.Question{
{
Name: "name",
Prompt: &survey.Input{Message: "Name for this login", Default: "gitea"},
Validate: validateLoginName,
},
{
Name: "token",
Prompt: &survey.Input{Message: "Name for this token", Default: "tea"},
Validate: survey.Required,
},
{
Name: "url",
Prompt: &survey.Input{Message: "URL for the Gitea instance", Default: ctx.String("url")},
Validate: survey.Required,
},
{
Name: "username",
Prompt: &survey.Input{Message: "Username the Gitea instance"},
Validate: survey.Required,
},
{
Name: "password",
Prompt: &survey.Password{Message: "Password for the Gitea instance"},
Validate: survey.Required,
},
}
answers := struct {
Name string
Token string
URL string
Username string
Password string
}{}
if err := survey.Ask(questions, &answers); err != nil {
return err
}
auth := context.WithValue(context.Background(), gitea.ContextBasicAuth, gitea.BasicAuth{
UserName: answers.Username,
Password: answers.Password,
})
client := getClient(answers.URL)
resp, err := client.UserApi.UserCreateToken(auth, answers.Username, &gitea.UserCreateTokenOpts{AccessToken: optional.NewInterface(gitea.AccessToken{Name: answers.Token})})
if err != nil {
return err
}
if resp.StatusCode != http.StatusCreated {
return fmt.Errorf("could not create new access token: %s", resp.Status)
}
sha1 := struct {
Token string `json:"sha1"`
}{}
data, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
defer resp.Body.Close()
if err := json.Unmarshal(data, &sha1); err != nil {
return err
}
config.Logins = append(config.Logins, config.Login{
Name: answers.Name,
URL: answers.URL,
Token: sha1.Token,
})
if err := config.Save(); err != nil {
return err
}
beaver.Infof("Login saved! You can refer to it by using `--login %s` with commands!", answers.Name)
return nil
}
func validateLoginName(ans interface{}) error {
name := ans.(string)
for _, login := range config.Logins {
if name == login.Name {
return errors.New("login name already exists")
}
}
return survey.Required(ans)
}

55
cmd/logout.go Normal file

@ -0,0 +1,55 @@
package cmd
import (
"fmt"
"gitea.com/jolheiser/beaver"
"gitea.com/jolheiser/tea/modules/config"
"github.com/AlecAivazis/survey/v2"
"github.com/urfave/cli/v2"
)
var (
Logout = cli.Command{
Name: "logout",
Usage: "Log out of a Gitea server",
Action: doLogout,
}
)
func doLogout(ctx *cli.Context) error {
opts := make([]string, len(config.Logins))
for idx, login := range config.Logins {
opts[idx] = fmt.Sprintf("%s (%s)", login.Name, login.URL)
}
question := &survey.MultiSelect{
Message: "Which would you like to remove?",
Options: opts,
PageSize: 10,
}
answers := make([]string, 0)
if err := survey.AskOne(question, &answers); err != nil {
return err
}
idxs := make([]int, len(answers))
for idx, answer := range answers {
for idy, login := range config.Logins {
if answer == fmt.Sprintf("%s (%s)", login.Name, login.URL) {
idxs[len(answers)-idx-1] = idy
}
}
}
for _, idx := range idxs {
config.Logins = append(config.Logins[:idx], config.Logins[idx+1:]...)
}
if err := config.Save(); err != nil {
return err
}
beaver.Infof("Logged out of %d accounts! Remember to clean up your tokens!", len(answers))
return nil
}

26
cmd/pulls.go Normal file

@ -0,0 +1,26 @@
package cmd
import (
"context"
"gitea.com/jolheiser/gitea-sdk"
"github.com/antihax/optional"
)
func getPulls(auth context.Context, client *gitea.APIClient, owner, repo string, opts *gitea.RepoListPullRequestsOpts) ([]gitea.PullRequest, error) {
pulls := make([]gitea.PullRequest, 0)
var p int32 = 1
for {
opts.Page = optional.NewInt32(p)
list, _, err := client.RepositoryApi.RepoListPullRequests(auth, owner, repo, opts)
if err != nil {
return pulls, err
}
p++
pulls = append(pulls, list...)
if len(list) == 0 {
break
}
}
return pulls, nil
}

44
cmd/repo.go Normal file

@ -0,0 +1,44 @@
package cmd
import (
"gitea.com/jolheiser/beaver"
"gitea.com/jolheiser/beaver/color"
"gitea.com/jolheiser/gitea-sdk"
"github.com/antihax/optional"
"github.com/urfave/cli/v2"
"strconv"
)
var Repo = cli.Command{
Name: "repo",
Usage: "Commands for interacting with a Gitea repository",
Action: doRepo,
}
func doRepo(ctx *cli.Context) error {
auth := getAuth(ctx.String("login"))
client := getClient(ctx.String("url"))
issues, err := getIssues(auth, client, ctx.String("owner"), ctx.String("repo"), &gitea.IssueListIssuesOpts{
State: optional.NewString("open"),
Type_: optional.NewString("issues"),
})
if err != nil {
return err
}
pulls, err := getPulls(auth, client, ctx.String("owner"), ctx.String("repo"), &gitea.RepoListPullRequestsOpts{
State: optional.NewString("open"),
})
if err != nil {
return err
}
beaver.Infof("Repository: %s", color.New(color.FgYellow).Format(ctx.String("owner")+"/"+ctx.String("repo")))
beaver.Infof("URL: %s", color.New(color.FgYellow).Format(ctx.String("url")+"/"+ctx.String("owner")+"/"+ctx.String("repo")))
beaver.Info()
beaver.Infof("Open Issues: %s", color.New(color.FgYellow).Format(strconv.Itoa(len(issues))))
beaver.Infof("Open Pulls: %s", color.New(color.FgYellow).Format(strconv.Itoa(len(pulls))))
return nil
}

22
go.mod Normal file

@ -0,0 +1,22 @@
module gitea.com/jolheiser/tea
go 1.13
require (
gitea.com/jolheiser/beaver v1.0.0
gitea.com/jolheiser/gitea-sdk v0.0.0-20200214045217-39e76ea80552
github.com/AlecAivazis/survey/v2 v2.0.5
github.com/BurntSushi/toml v0.3.1
github.com/antihax/optional v1.0.0
github.com/charmbracelet/glamour v0.1.0
github.com/golang/protobuf v1.3.3 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/kr/pty v1.1.8 // indirect
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
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
google.golang.org/appengine v1.6.5 // indirect
)

150
go.sum Normal file

@ -0,0 +1,150 @@
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
gitea.com/jolheiser/beaver v1.0.0 h1:IfNMhp7+DUaM0kaNwho4RWfuebCsa8A/kxtZBngFjHk=
gitea.com/jolheiser/beaver v1.0.0/go.mod h1:2mUGl6ZGKY/Y9u36iR4bqOPrHhr4C22cxkR8ei2G06I=
gitea.com/jolheiser/gitea-sdk v0.0.0-20200214045217-39e76ea80552 h1:3x3f9iy9Zo8K5RETV6r1VD/ZVB1Zr8V3KKiFV0hNC2k=
gitea.com/jolheiser/gitea-sdk v0.0.0-20200214045217-39e76ea80552/go.mod h1:c+DLe4/JxFQw5j1/7g0r2P5ehFwcALONUA/gXy/kBU0=
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=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtixis4Tib9if0=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8 h1:xzYJEypr/85nBpB11F9br+3HUrpgb+fcm5iADzXXYEw=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U=
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI=
github.com/alecthomas/chroma v0.7.0 h1:z+0HgTUmkpRDRz0SRSdMaqOLfJV4F+N1FPDZUZIDUzw=
github.com/alecthomas/chroma v0.7.0/go.mod h1:1U/PfCsTALWWYHDnsIQkxEBM0+6LLe0v8+RSVMOwxeY=
github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721 h1:JHZL0hZKJ1VENNfmXvHbgYlbUOvpzYzvy2aZU5gXVeo=
github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0=
github.com/alecthomas/kong v0.1.17-0.20190424132513-439c674f7ae0/go.mod h1:+inYUSluD+p4L8KdviBSgzcqEjUQOfC5fQDRFuc36lI=
github.com/alecthomas/kong v0.2.1-0.20190708041108-0548c6b1afae/go.mod h1:+inYUSluD+p4L8KdviBSgzcqEjUQOfC5fQDRFuc36lI=
github.com/alecthomas/kong-hcl v0.1.8-0.20190615233001-b21fea9723c8/go.mod h1:MRgZdU3vrFd05IQ89AxUZ0aYdF39BYoNFa324SodPCA=
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 h1:p9Sln00KOTlrYkxI1zYWl1QLnEqAqEARBEYa8FQnQcY=
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/charmbracelet/glamour v0.1.0 h1:BHCtc+YJjoBjNUnFKBtXyyM4Bp9u7L2kf49qV+/AGYw=
github.com/charmbracelet/glamour v0.1.0/go.mod h1:Z1C2JkVGBom/RYfoKcPBZ81lHMR3xp3W6OCLNWWEIMc=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.7 h1:6pwm8kMQKCmgUg0ZHTm5+/YvRK0s3THD/28+T6/kk4A=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ=
github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dlclark/regexp2 v1.1.6 h1:CqB4MjHw0MFCDj+PHHjiESmHX+N7t0tJzKvC6M97BRg=
github.com/dlclark/regexp2 v1.1.6/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/gorilla/csrf v1.6.0/go.mod h1:7tSf8kmjNYr7IWDCYhd3U8Ck34iQ/Yw5CJu7bAkHEGI=
github.com/gorilla/handlers v1.4.1/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDGgJGQpNflI3+MJSBhsgT5PCtzBQ=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.8 h1:AkaSdXYQOWeaO3neb8EM634ahkXXe3jYbVh/F9lq+GI=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/logrusorgru/aurora v0.0.0-20191116043053-66b7ad493a23 h1:Wp7NjqGKGN9te9N/rvXYRhlVcrulGdxnz8zadXWs7fc=
github.com/logrusorgru/aurora v0.0.0-20191116043053-66b7ad493a23/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
github.com/lucasb-eyer/go-colorful v1.0.3 h1:QIbQXiugsb+q10B+MI+7DI1oQLdmnep86tWFlaaUAac=
github.com/lucasb-eyer/go-colorful v1.0.3/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s=
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
github.com/muesli/reflow v0.0.0-20191216070243-e5efeac4e302 h1:jOh3Kh03uOFkRPV3PI4Am5tqACv2aELgbPgr7YgNX00=
github.com/muesli/reflow v0.0.0-20191216070243-e5efeac4e302/go.mod h1:I9bWAt7QTg/que/qmUCJBGlj7wEq8OAFBjPNjc6xK4I=
github.com/nkovacs/streamquote v0.0.0-20170412213628-49af9bddb229/go.mod h1:0aYXnNPJ8l7uZxf45rWW1a/uME32OF0rhiYGNQ2oF2E=
github.com/olekukonko/tablewriter v0.0.4 h1:vHD/YYe1Wolo78koG299f7V/VAS08c6IpCLn+Ejf/w8=
github.com/olekukonko/tablewriter v0.0.4/go.mod h1:zq6QwlOf5SlnkVbMSr5EoBv3636FWnp+qbPhuoO21uA=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/urfave/cli/v2 v2.1.1 h1:Qt8FeAtxE/vfdrLmR3rxR6JRE0RoVmbXu8+6kZtYU4k=
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
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=
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=
golang.org/x/crypto v0.0.0-20200210222208-86ce3cb69678/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20181128092732-4ed8d59d0b35/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190530182044-ad28b68e88f1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
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/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.6.5 h1:tycE03LOZYQNhDpS27tcQdAzLCVMaj7QT2SXxebnpCM=
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
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=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

29
main.go Normal file

@ -0,0 +1,29 @@
package main
import (
"gitea.com/jolheiser/beaver"
"gitea.com/jolheiser/tea/cmd"
"github.com/urfave/cli/v2"
"os"
)
var Version = "develop"
func main() {
app := cli.NewApp()
app.Name = "Tea"
app.Usage = "Command line tool to interact with Gitea"
app.Version = Version
app.Commands = []*cli.Command{
&cmd.Login,
&cmd.Logout,
&cmd.Repo,
&cmd.Issues,
}
app.Flags = cmd.Flags
app.EnableBashCompletion = true
err := app.Run(os.Args)
if err != nil {
beaver.Fatalf("Failed to run app with %s: %v", os.Args, err)
}
}

67
modules/config/config.go Normal file

@ -0,0 +1,67 @@
package config
import (
"fmt"
"gitea.com/jolheiser/beaver"
"github.com/BurntSushi/toml"
"github.com/mitchellh/go-homedir"
"os"
"path"
)
var (
configPath string
cfg *config
Logins []Login
)
type config struct {
Logins []Login `toml:"login"`
}
type Login struct {
Name string `toml:"name"`
URL string `toml:"url"`
Token string `toml:"token"`
}
func init() {
home, err := homedir.Dir()
if err != nil {
beaver.Fatalf("could not locate home directory: %v", err)
}
configPath = fmt.Sprintf("%s/.tea/config.toml", home)
if _, err := os.Stat(configPath); os.IsNotExist(err) {
if err := os.MkdirAll(path.Dir(configPath), os.ModePerm); err != nil {
beaver.Fatalf("could not create Tea home: %v", err)
}
if _, err := os.Create(configPath); err != nil {
beaver.Fatalf("could not create Tea config: %v", err)
}
}
if _, err := toml.DecodeFile(configPath, &cfg); err != nil {
beaver.Fatalf("could not decode Tea config: %v", err)
}
Logins = cfg.Logins
}
func Save() error {
cfg.Logins = Logins
fi, err := os.Create(configPath)
if err != nil {
return err
}
defer fi.Close()
if err := toml.NewEncoder(fi).Encode(cfg); err != nil {
return err
}
return nil
}

@ -0,0 +1,16 @@
package markdown
import (
"github.com/charmbracelet/glamour"
"strings"
)
func normalizeNewlines(s string) string {
s = strings.ReplaceAll(s, "\r\n", "\n")
s = strings.ReplaceAll(s, "\r", "\n")
return s
}
func Render(text string) (string, error) {
return glamour.Render(normalizeNewlines(text), "dark")
}

19
modules/stdout/stdout.go Normal file

@ -0,0 +1,19 @@
package stdout
import (
"fmt"
"gitea.com/jolheiser/beaver/color"
)
var (
red = color.New(color.FgRed)
green = color.New(color.FgGreen)
)
func Red(format string, args ...interface{}) {
fmt.Println(red.Format(fmt.Sprintf(format, args...)))
}
func Green(format string, args ...interface{}) {
fmt.Println(green.Format(fmt.Sprintf(format, args...)))
}