From 5bd2eee592e83c67c68adac13e3ef82d573b1d63 Mon Sep 17 00:00:00 2001 From: Andreas Ulm Date: Mon, 15 Apr 2019 22:40:27 +0200 Subject: [PATCH 01/11] initial imlementation of list repos (#3) Signed-off-by: Andreas Ulm --- cmd/repos.go | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 1 + 2 files changed, 85 insertions(+) create mode 100644 cmd/repos.go diff --git a/cmd/repos.go b/cmd/repos.go new file mode 100644 index 0000000..f0fec30 --- /dev/null +++ b/cmd/repos.go @@ -0,0 +1,84 @@ +// Copyright 2018 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package cmd + +import ( + "fmt" + "log" + + //"code.gitea.io/sdk/gitea" + + "github.com/urfave/cli" +) + +// CmdRepos represents to login a gitea server. +var CmdRepos = cli.Command{ + Name: "repos", + Usage: "Operate with repositories", + Description: `Operate with repositories`, + Action: runRepos, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "login, l", + Usage: "Indicate one login, optional when inside a gitea repository", + }, + cli.BoolFlag{ + Name: "noheader", + Usage: "Skip header on output.", + }, + }, +} + +func runRepos(ctx *cli.Context) error { + login := initCommandLoginOnly(ctx) + + rps, err := login.Client().ListMyRepos() + + if err != nil { + log.Fatal(err) + } + + if len(rps) == 0 { + fmt.Println("No repositories found") + return nil + } + + if noheader := getGlobalFlag(ctx, "noheader"); noheader != "true" { + fmt.Printf("Name\tType/Mode\tSSH-URL\tOwner\n") + } + for _, rp := range rps { + var mode = "source" + if rp.Fork { + mode = "fork" + } + if rp.Mirror { + mode = "mirror" + } + fmt.Printf("%s\t%s\t%s\t%s\n", rp.FullName, mode, rp.SSHURL, rp.Owner.UserName) + } + + return nil +} + +func initCommandLoginOnly(ctx *cli.Context) (*Login) { + err := loadConfig(yamlConfigPath) + if err != nil { + log.Fatal("load config file failed", yamlConfigPath) + } + + var login *Login + if loginFlag := getGlobalFlag(ctx, "login"); loginFlag == "" { + login, err = getActiveLogin() + if err != nil { + log.Fatal(err) + } + } else { + login = getLoginByName(loginFlag) + if login == nil { + log.Fatal("indicated login name", loginFlag, "does not exist") + } + } + return login +} diff --git a/main.go b/main.go index e5b0a42..a67c6f4 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,7 @@ func main() { cmd.CmdIssues, cmd.CmdPulls, cmd.CmdReleases, + cmd.CmdRepos, } err := app.Run(os.Args) if err != nil { From 2599cff8a63263bbf7d7c25595ac19d4cf5e9659 Mon Sep 17 00:00:00 2001 From: Andreas Ulm Date: Mon, 15 Apr 2019 22:58:32 +0200 Subject: [PATCH 02/11] improved code style Signed-off-by: Andreas Ulm --- cmd/repos.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmd/repos.go b/cmd/repos.go index f0fec30..a50f29d 100644 --- a/cmd/repos.go +++ b/cmd/repos.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Gitea Authors. All rights reserved. +// Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -8,8 +8,6 @@ import ( "fmt" "log" - //"code.gitea.io/sdk/gitea" - "github.com/urfave/cli" ) From b96a190c7485318ba709e62ac20b7c703f7374f5 Mon Sep 17 00:00:00 2001 From: Andreas Ulm Date: Thu, 25 Apr 2019 15:59:41 +0200 Subject: [PATCH 03/11] removed header & changed delimiter to pipe Signed-off-by: Andreas Ulm --- cmd/repos.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/cmd/repos.go b/cmd/repos.go index a50f29d..956450f 100644 --- a/cmd/repos.go +++ b/cmd/repos.go @@ -22,10 +22,6 @@ var CmdRepos = cli.Command{ Name: "login, l", Usage: "Indicate one login, optional when inside a gitea repository", }, - cli.BoolFlag{ - Name: "noheader", - Usage: "Skip header on output.", - }, }, } @@ -43,9 +39,7 @@ func runRepos(ctx *cli.Context) error { return nil } - if noheader := getGlobalFlag(ctx, "noheader"); noheader != "true" { - fmt.Printf("Name\tType/Mode\tSSH-URL\tOwner\n") - } + fmt.Println("Name | Type/Mode | SSH-URL | Owner") for _, rp := range rps { var mode = "source" if rp.Fork { @@ -54,7 +48,7 @@ func runRepos(ctx *cli.Context) error { if rp.Mirror { mode = "mirror" } - fmt.Printf("%s\t%s\t%s\t%s\n", rp.FullName, mode, rp.SSHURL, rp.Owner.UserName) + fmt.Printf("%s | %s | %s | %s\n", rp.FullName, mode, rp.SSHURL, rp.Owner.UserName) } return nil From bf9620d18e1391ce96b10544d5a8efec9f56100c Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 26 Apr 2019 19:51:03 +0800 Subject: [PATCH 04/11] chore: go support combine all coverage file (#24) * Combine all coverage file in one command * remove generate-coverage * remove unused method: errCheck Signed-off-by: Bo-Yi Wu --- .drone.yml | 13 +------------ Makefile | 14 -------------- README.md | 7 +++++++ 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/.drone.yml b/.drone.yml index 6db2aab..98c03dc 100644 --- a/.drone.yml +++ b/.drone.yml @@ -52,22 +52,11 @@ pipeline: when: event: [ tag ] - generate-coverage: - image: golang:1.12 - pull: true - environment: - TAGS: bindata - commands: - - make coverage - when: - event: [ push, pull_request ] - branch: [ master ] - coverage: image: robertstettner/drone-codecov secrets: [ codecov_token ] files: - - coverage.all + - coverage.out when: event: [ push, pull_request ] branch: [ master ] diff --git a/Makefile b/Makefile index 6ec9f86..56e8449 100644 --- a/Makefile +++ b/Makefile @@ -70,13 +70,6 @@ fmt: vet: $(GO) vet $(PACKAGES) -.PHONY: errcheck -errcheck: - @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ - $(GO) get -u github.com/kisielk/errcheck; \ - fi - errcheck $(PACKAGES) - .PHONY: lint lint: @hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ @@ -112,13 +105,6 @@ fmt-check: test: GO111MODULE=on $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' $(PACKAGES) -.PHONY: coverage -coverage: - @hash gocovmerge > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ - $(GO) get -u github.com/wadey/gocovmerge; \ - fi - gocovmerge $(shell find . -type f -name "coverage.out") > coverage.all;\ - .PHONY: unit-test-coverage unit-test-coverage: $(GO) test -tags='sqlite sqlite_unlock_notify' -cover -coverprofile coverage.out $(PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1 diff --git a/README.md b/README.md index 07fa5df..e0ee105 100644 --- a/README.md +++ b/README.md @@ -4,26 +4,32 @@ This project acts as a command line tool for operating one or multiple Gitea ins the Gitea API implementation. ## Installation + Currently no prebuilt binaries are provided. To install, a Go installation is needed. + ```sh go get code.gitea.io/tea go install code.gitea.io/tea ``` If the `tea` executable is not found, you might need to set up your `$GOPATH` and `$PATH` variables first: + ```sh export PATH=$PATH:$GOROOT/bin:$GOPATH/bin ``` ## Usage + First of all, you have to create a token on your `personal settings -> application` page of your gitea instance. Use this token to login with `tea`: + ```sh tea login add --name=try --url=https://try.gitea.io --token=xxxxxx ``` Now you can use the `tea` commands: + ```sh tea issues tea releases @@ -34,6 +40,7 @@ tea releases ## Compilation To compile the sources yourself run the following: + ```sh go get code.gitea.io/tea cd "${GOPATH}/src/code.gitea.io/tea" From 912803706a33d25c35e1ea6c82c2f5ed35f320db Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 27 Apr 2019 21:01:07 +0800 Subject: [PATCH 05/11] Add missing make-compress to fix release (#23) --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Makefile b/Makefile index 56e8449..9280859 100644 --- a/Makefile +++ b/Makefile @@ -176,6 +176,13 @@ endif release-copy: cd $(DIST); for file in `find /build -type f -name "*"`; do cp $${file} ./release/; done; +.PHONY: release-compress +release-compress: + @hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \ + $(GO) get -u github.com/ulikunitz/xz/cmd/gxz; \ + fi + cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done; + .PHONY: release-check release-check: cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done; From 9021a0e643e6bd39c737cb2b8416fab463606565 Mon Sep 17 00:00:00 2001 From: Andreas Ulm Date: Sun, 28 Apr 2019 14:27:33 +0200 Subject: [PATCH 06/11] ran 'make fmt' Signed-off-by: Andreas Ulm --- cmd/repos.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/repos.go b/cmd/repos.go index 956450f..08c0fa2 100644 --- a/cmd/repos.go +++ b/cmd/repos.go @@ -54,7 +54,7 @@ func runRepos(ctx *cli.Context) error { return nil } -func initCommandLoginOnly(ctx *cli.Context) (*Login) { +func initCommandLoginOnly(ctx *cli.Context) *Login { err := loadConfig(yamlConfigPath) if err != nil { log.Fatal("load config file failed", yamlConfigPath) From 1aa915ed88ee8b7de698b24a717a2d4c79156bce Mon Sep 17 00:00:00 2001 From: Andreas Ulm Date: Mon, 15 Apr 2019 22:40:27 +0200 Subject: [PATCH 07/11] initial imlementation of list repos (#3) Signed-off-by: Andreas Ulm --- cmd/repos.go | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ main.go | 1 + 2 files changed, 85 insertions(+) create mode 100644 cmd/repos.go diff --git a/cmd/repos.go b/cmd/repos.go new file mode 100644 index 0000000..f0fec30 --- /dev/null +++ b/cmd/repos.go @@ -0,0 +1,84 @@ +// Copyright 2018 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package cmd + +import ( + "fmt" + "log" + + //"code.gitea.io/sdk/gitea" + + "github.com/urfave/cli" +) + +// CmdRepos represents to login a gitea server. +var CmdRepos = cli.Command{ + Name: "repos", + Usage: "Operate with repositories", + Description: `Operate with repositories`, + Action: runRepos, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "login, l", + Usage: "Indicate one login, optional when inside a gitea repository", + }, + cli.BoolFlag{ + Name: "noheader", + Usage: "Skip header on output.", + }, + }, +} + +func runRepos(ctx *cli.Context) error { + login := initCommandLoginOnly(ctx) + + rps, err := login.Client().ListMyRepos() + + if err != nil { + log.Fatal(err) + } + + if len(rps) == 0 { + fmt.Println("No repositories found") + return nil + } + + if noheader := getGlobalFlag(ctx, "noheader"); noheader != "true" { + fmt.Printf("Name\tType/Mode\tSSH-URL\tOwner\n") + } + for _, rp := range rps { + var mode = "source" + if rp.Fork { + mode = "fork" + } + if rp.Mirror { + mode = "mirror" + } + fmt.Printf("%s\t%s\t%s\t%s\n", rp.FullName, mode, rp.SSHURL, rp.Owner.UserName) + } + + return nil +} + +func initCommandLoginOnly(ctx *cli.Context) (*Login) { + err := loadConfig(yamlConfigPath) + if err != nil { + log.Fatal("load config file failed", yamlConfigPath) + } + + var login *Login + if loginFlag := getGlobalFlag(ctx, "login"); loginFlag == "" { + login, err = getActiveLogin() + if err != nil { + log.Fatal(err) + } + } else { + login = getLoginByName(loginFlag) + if login == nil { + log.Fatal("indicated login name", loginFlag, "does not exist") + } + } + return login +} diff --git a/main.go b/main.go index e5b0a42..a67c6f4 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,7 @@ func main() { cmd.CmdIssues, cmd.CmdPulls, cmd.CmdReleases, + cmd.CmdRepos, } err := app.Run(os.Args) if err != nil { From 3797d6b1d138c85cfeaf5aaf7818c26e5762de08 Mon Sep 17 00:00:00 2001 From: Andreas Ulm Date: Mon, 15 Apr 2019 22:58:32 +0200 Subject: [PATCH 08/11] improved code style Signed-off-by: Andreas Ulm --- cmd/repos.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmd/repos.go b/cmd/repos.go index f0fec30..a50f29d 100644 --- a/cmd/repos.go +++ b/cmd/repos.go @@ -1,4 +1,4 @@ -// Copyright 2018 The Gitea Authors. All rights reserved. +// Copyright 2019 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -8,8 +8,6 @@ import ( "fmt" "log" - //"code.gitea.io/sdk/gitea" - "github.com/urfave/cli" ) From 0fb281bbe429cc6ed314f3203dd868e8679852a5 Mon Sep 17 00:00:00 2001 From: Andreas Ulm Date: Thu, 25 Apr 2019 15:59:41 +0200 Subject: [PATCH 09/11] removed header & changed delimiter to pipe Signed-off-by: Andreas Ulm --- cmd/repos.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/cmd/repos.go b/cmd/repos.go index a50f29d..956450f 100644 --- a/cmd/repos.go +++ b/cmd/repos.go @@ -22,10 +22,6 @@ var CmdRepos = cli.Command{ Name: "login, l", Usage: "Indicate one login, optional when inside a gitea repository", }, - cli.BoolFlag{ - Name: "noheader", - Usage: "Skip header on output.", - }, }, } @@ -43,9 +39,7 @@ func runRepos(ctx *cli.Context) error { return nil } - if noheader := getGlobalFlag(ctx, "noheader"); noheader != "true" { - fmt.Printf("Name\tType/Mode\tSSH-URL\tOwner\n") - } + fmt.Println("Name | Type/Mode | SSH-URL | Owner") for _, rp := range rps { var mode = "source" if rp.Fork { @@ -54,7 +48,7 @@ func runRepos(ctx *cli.Context) error { if rp.Mirror { mode = "mirror" } - fmt.Printf("%s\t%s\t%s\t%s\n", rp.FullName, mode, rp.SSHURL, rp.Owner.UserName) + fmt.Printf("%s | %s | %s | %s\n", rp.FullName, mode, rp.SSHURL, rp.Owner.UserName) } return nil From 01d4f929ac004902ebde688f0ac457a4f61a47d1 Mon Sep 17 00:00:00 2001 From: Andreas Ulm Date: Sun, 28 Apr 2019 14:27:33 +0200 Subject: [PATCH 10/11] ran 'make fmt' Signed-off-by: Andreas Ulm --- cmd/repos.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/repos.go b/cmd/repos.go index 956450f..08c0fa2 100644 --- a/cmd/repos.go +++ b/cmd/repos.go @@ -54,7 +54,7 @@ func runRepos(ctx *cli.Context) error { return nil } -func initCommandLoginOnly(ctx *cli.Context) (*Login) { +func initCommandLoginOnly(ctx *cli.Context) *Login { err := loadConfig(yamlConfigPath) if err != nil { log.Fatal("load config file failed", yamlConfigPath) From 2d1907ea9c1941c1325130a776656b73d242b6ed Mon Sep 17 00:00:00 2001 From: Andreas Ulm Date: Mon, 6 May 2019 18:56:14 +0200 Subject: [PATCH 11/11] added subcommand ls & filter flags Signed-off-by: Andreas Ulm --- cmd/repos.go | 78 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/cmd/repos.go b/cmd/repos.go index 08c0fa2..41ee698 100644 --- a/cmd/repos.go +++ b/cmd/repos.go @@ -8,6 +8,8 @@ import ( "fmt" "log" + "code.gitea.io/sdk/gitea" + "github.com/urfave/cli" ) @@ -16,7 +18,10 @@ var CmdRepos = cli.Command{ Name: "repos", Usage: "Operate with repositories", Description: `Operate with repositories`, - Action: runRepos, + Action: runReposList, + Subcommands: []cli.Command{ + CmdReposList, + }, Flags: []cli.Flag{ cli.StringFlag{ Name: "login, l", @@ -25,22 +30,87 @@ var CmdRepos = cli.Command{ }, } -func runRepos(ctx *cli.Context) error { +// CmdReposList represents a sub command of issues to list issues +var CmdReposList = cli.Command{ + Name: "ls", + Usage: "List available repositories", + Description: `List available repositories`, + Action: runReposList, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "login, l", + Usage: "Indicate one login, optional when inside a gitea repository", + }, + cli.StringFlag{ + Name: "mode", + Usage: "Indicate one login, optional when inside a gitea repository", + }, + cli.StringFlag{ + Name: "org", + Usage: "Indicate one login, optional when inside a gitea repository", + }, + cli.StringFlag{ + Name: "user", + Usage: "Indicate one login, optional when inside a gitea repository", + }, + }, +} + +// runReposList list repositories +func runReposList(ctx *cli.Context) error { login := initCommandLoginOnly(ctx) - rps, err := login.Client().ListMyRepos() + mode := ctx.String("mode") + org := ctx.String("org") + user := ctx.String("user") + var rps []*gitea.Repository + var err error + + if org != "" { + rps, err = login.Client().ListOrgRepos(org) + } else if user != "" { + rps, err = login.Client().ListUserRepos(user) + } else { + rps, err = login.Client().ListMyRepos() + } if err != nil { log.Fatal(err) } + var repos []*gitea.Repository + if mode == "" { + repos = rps + } else if mode == "fork" { + for _, rp := range rps { + if rp.Fork == true { + repos = append(repos, rp) + } + } + } else if mode == "mirror" { + for _, rp := range rps { + if rp.Mirror == true { + repos = append(repos, rp) + } + } + } else if mode == "source" { + for _, rp := range rps { + if rp.Mirror != true && rp.Fork != true { + repos = append(repos, rp) + } + } + } else { + fmt.Printf("Unknown mode '%s'\nUse one of the following:\n- fork\n- mirror\n- source\n", mode) + return nil + } + if len(rps) == 0 { fmt.Println("No repositories found") return nil } fmt.Println("Name | Type/Mode | SSH-URL | Owner") - for _, rp := range rps { + for _, rp := range repos { var mode = "source" if rp.Fork { mode = "fork"