2020-12-17 00:18:10 +08:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2023-09-08 09:40:02 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2018-09-03 14:43:00 +08:00
|
|
|
|
|
|
|
// Tea is command line tool for Gitea.
|
|
|
|
package main // import "code.gitea.io/tea"
|
|
|
|
|
|
|
|
import (
|
2020-12-17 00:18:10 +08:00
|
|
|
"fmt"
|
2018-09-03 14:43:00 +08:00
|
|
|
"os"
|
2022-06-18 22:34:18 +08:00
|
|
|
"runtime"
|
2018-09-03 14:43:00 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
"code.gitea.io/tea/cmd"
|
|
|
|
|
2020-01-05 01:44:25 +08:00
|
|
|
"github.com/urfave/cli/v2"
|
2018-09-03 14:43:00 +08:00
|
|
|
)
|
|
|
|
|
2020-04-23 03:11:03 +08:00
|
|
|
// Version holds the current tea version
|
|
|
|
var Version = "development"
|
2018-09-03 14:43:00 +08:00
|
|
|
|
|
|
|
// Tags holds the build tags used
|
|
|
|
var Tags = ""
|
|
|
|
|
2022-06-18 22:34:18 +08:00
|
|
|
// SDK holds the sdk version from go.mod
|
|
|
|
var SDK = ""
|
|
|
|
|
2018-09-03 14:43:00 +08:00
|
|
|
func main() {
|
2020-12-21 21:37:20 +08:00
|
|
|
// make parsing tea --version easier, by printing /just/ the version string
|
|
|
|
cli.VersionPrinter = func(c *cli.Context) { fmt.Fprintln(c.App.Writer, c.App.Version) }
|
|
|
|
|
2018-09-03 14:43:00 +08:00
|
|
|
app := cli.NewApp()
|
2020-03-06 11:43:28 +08:00
|
|
|
app.Name = "tea"
|
2020-12-21 21:37:20 +08:00
|
|
|
app.Usage = "command line tool to interact with Gitea"
|
|
|
|
app.Description = appDescription
|
|
|
|
app.CustomAppHelpTemplate = helpTemplate
|
2022-06-18 22:34:18 +08:00
|
|
|
app.Version = formatVersion()
|
2020-01-05 01:44:25 +08:00
|
|
|
app.Commands = []*cli.Command{
|
|
|
|
&cmd.CmdLogin,
|
|
|
|
&cmd.CmdLogout,
|
2020-12-21 21:37:20 +08:00
|
|
|
&cmd.CmdAutocomplete,
|
2021-10-05 01:41:59 +08:00
|
|
|
&cmd.CmdWhoami,
|
2020-12-21 21:37:20 +08:00
|
|
|
|
2020-01-05 01:44:25 +08:00
|
|
|
&cmd.CmdIssues,
|
|
|
|
&cmd.CmdPulls,
|
|
|
|
&cmd.CmdLabels,
|
2020-12-21 21:37:20 +08:00
|
|
|
&cmd.CmdMilestones,
|
|
|
|
&cmd.CmdReleases,
|
2020-03-06 11:43:28 +08:00
|
|
|
&cmd.CmdTrackedTimes,
|
2020-12-21 21:37:20 +08:00
|
|
|
&cmd.CmdOrgs,
|
|
|
|
&cmd.CmdRepos,
|
tea branches list/protect/unprotect (#645)
Hello,
This is a proposal to support consulting / protecting / unprotecting branches for a specific repository.
I copied the existing code for "issues" report and adapted to branches. There is no change of legacy code so I do not expect any impact.
Supported commands are "list", "protect", "unprotect":
- "List" print the list of branches with some available fields from gitea.Branch type.
- "protect" creates a gitea.BranchProtection with some default parameters for some specific branches
- "unprotect" destroys gitea.BranchProtection for some specific branches
What is printed now could be enriched with additional information gitea datatypes already offer.
Could you please evaluate this proposal?
I would be happy to receive any comment or remark to take into account.
**tea branches unprotect** --login opsi --repo opensky main
**tea branches list** --login opsi --repo opensky --fields name,protected,user-can-merge,user-can-push,protection
[name protected user-can-merge user-can-push protection]
+--------+-----------+----------------+---------------+------------+
| NAME | PROTECTED | USER-CAN-MERGE | USER-CAN-PUSH | PROTECTION |
+--------+-----------+----------------+---------------+------------+
| b_test | false | true | true | <None> |
| main | false | true | true | <None> |
+--------+-----------+----------------+---------------+------------+
**tea branches protect** --login opsi --repo opensky main
**tea branches list** --login opsi --repo opensky --fields name,protected,user-can-merge,user-can-push,protection
[name protected user-can-merge user-can-push protection]
+--------+-----------+----------------+---------------+----------------------+
| NAME | PROTECTED | USER-CAN-MERGE | USER-CAN-PUSH | PROTECTION |
+--------+-----------+----------------+---------------+----------------------+
| b_test | false | true | true | <None> |
| main | true | true | false | - enable-push: false |
| | | | | - approving: - |
| | | | | merging: - pushing: |
| | | | | |
+--------+-----------+----------------+---------------+----------------------+
Following commands run OK:
> make test
> make fmt
> make lint
Co-authored-by: Leonard Vimond <leonard.vimond.e@thalesdigital.io>
Co-authored-by: techknowlogick <techknowlogick@noreply.gitea.com>
Reviewed-on: https://gitea.com/gitea/tea/pulls/645
Reviewed-by: techknowlogick <techknowlogick@noreply.gitea.com>
Co-authored-by: leonard.vimond <leonard.vimond@noreply.gitea.com>
Co-committed-by: leonard.vimond <leonard.vimond@noreply.gitea.com>
2024-07-27 00:02:07 +08:00
|
|
|
&cmd.CmdBranches,
|
2020-12-22 00:07:35 +08:00
|
|
|
&cmd.CmdAddComment,
|
2020-12-21 21:37:20 +08:00
|
|
|
|
2020-04-01 11:22:24 +08:00
|
|
|
&cmd.CmdOpen,
|
2020-07-17 23:30:02 +08:00
|
|
|
&cmd.CmdNotifications,
|
2021-10-18 20:09:27 +08:00
|
|
|
&cmd.CmdRepoClone,
|
2022-09-14 03:49:34 +08:00
|
|
|
|
|
|
|
&cmd.CmdAdmin,
|
2023-09-01 23:34:13 +08:00
|
|
|
&cmd.CmdDocs,
|
2018-09-03 14:43:00 +08:00
|
|
|
}
|
2019-08-13 18:59:13 +08:00
|
|
|
app.EnableBashCompletion = true
|
2018-09-03 14:43:00 +08:00
|
|
|
err := app.Run(os.Args)
|
|
|
|
if err != nil {
|
2020-12-17 00:18:10 +08:00
|
|
|
// app.Run already exits for errors implementing ErrorCoder,
|
|
|
|
// so we only handle generic errors with code 1 here.
|
|
|
|
fmt.Fprintf(app.ErrWriter, "Error: %v\n", err)
|
|
|
|
os.Exit(1)
|
2018-09-03 14:43:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-18 22:34:18 +08:00
|
|
|
func formatVersion() string {
|
|
|
|
version := fmt.Sprintf("Version: %s\tgolang: %s",
|
|
|
|
bold(Version),
|
|
|
|
strings.ReplaceAll(runtime.Version(), "go", ""))
|
|
|
|
|
|
|
|
if len(Tags) != 0 {
|
|
|
|
version += fmt.Sprintf("\tbuilt with: %s", strings.Replace(Tags, " ", ", ", -1))
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(SDK) != 0 {
|
|
|
|
version += fmt.Sprintf("\tgo-sdk: %s", SDK)
|
2018-09-03 14:43:00 +08:00
|
|
|
}
|
|
|
|
|
2022-06-18 22:34:18 +08:00
|
|
|
return version
|
2018-09-03 14:43:00 +08:00
|
|
|
}
|
2020-12-21 21:37:20 +08:00
|
|
|
|
2021-12-03 02:33:56 +08:00
|
|
|
var appDescription = `tea is a productivity helper for Gitea. It can be used to manage most entities on
|
|
|
|
one or multiple Gitea instances & provides local helpers like 'tea pr checkout'.
|
|
|
|
|
|
|
|
tea tries to make use of context provided by the repository in $PWD if available.
|
|
|
|
tea works best in a upstream/fork workflow, when the local main branch tracks the
|
|
|
|
upstream repo. tea assumes that local git state is published on the remote before
|
|
|
|
doing operations with tea. Configuration is persisted in $XDG_CONFIG_HOME/tea.
|
2020-12-21 21:37:20 +08:00
|
|
|
`
|
|
|
|
|
|
|
|
var helpTemplate = bold(`
|
|
|
|
{{.Name}}{{if .Usage}} - {{.Usage}}{{end}}`) + `
|
|
|
|
{{if .Version}}{{if not .HideVersion}}version {{.Version}}{{end}}{{end}}
|
|
|
|
|
|
|
|
USAGE
|
|
|
|
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .Commands}} command [subcommand] [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{if .Description}}
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
{{.Description | nindent 3 | trim}}{{end}}{{if .VisibleCommands}}
|
|
|
|
|
|
|
|
COMMANDS{{range .VisibleCategories}}{{if .Name}}
|
|
|
|
{{.Name}}:{{range .VisibleCommands}}
|
|
|
|
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}}
|
|
|
|
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
|
|
|
|
|
|
|
|
OPTIONS
|
|
|
|
{{range $index, $option := .VisibleFlags}}{{if $index}}
|
|
|
|
{{end}}{{$option}}{{end}}{{end}}
|
|
|
|
|
|
|
|
EXAMPLES
|
|
|
|
tea login add # add a login once to get started
|
|
|
|
|
|
|
|
tea pulls # list open pulls for the repo in $PWD
|
|
|
|
tea pulls --repo $HOME/foo # list open pulls for the repo in $HOME/foo
|
|
|
|
tea pulls --remote upstream # list open pulls for the repo pointed at by
|
|
|
|
# your local "upstream" git remote
|
|
|
|
# list open pulls for any gitea repo at the given login instance
|
|
|
|
tea pulls --repo gitea/tea --login gitea.com
|
|
|
|
|
|
|
|
tea milestone issues 0.7.0 # view open issues for milestone '0.7.0'
|
|
|
|
tea issue 189 # view contents of issue 189
|
|
|
|
tea open 189 # open web ui for issue 189
|
|
|
|
tea open milestones # open web ui for milestones
|
|
|
|
|
|
|
|
# send gitea desktop notifications every 5 minutes (bash + libnotify)
|
2021-09-29 03:29:48 +08:00
|
|
|
while :; do tea notifications --mine -o simple | xargs -i notify-send {}; sleep 300; done
|
2020-12-21 21:37:20 +08:00
|
|
|
|
|
|
|
ABOUT
|
|
|
|
Written & maintained by The Gitea Authors.
|
|
|
|
If you find a bug or want to contribute, we'll welcome you at https://gitea.com/gitea/tea.
|
2023-09-08 09:40:02 +08:00
|
|
|
More info about Gitea itself on https://about.gitea.com.
|
2020-12-21 21:37:20 +08:00
|
|
|
`
|
|
|
|
|
|
|
|
func bold(t string) string {
|
|
|
|
return fmt.Sprintf("\033[1m%s\033[0m", t)
|
|
|
|
}
|