commit 2e3ee32df18ed637e07387031b8e36cd4fe76302 Author: jolheiser Date: Tue Aug 23 12:04:13 2022 -0500 Initial commit Signed-off-by: jolheiser diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4bd6d74 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea/ +/git-ea* \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..6456373 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,25 @@ +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + ldflags: + - "-s -w -X main.Version={{.Version}}" +archives: + - replacements: + 386: i386 + amd64: x86_64 + format_overrides: + - goos: windows + format: zip +checksum: + name_template: 'checksums.txt' +release: + gitea: + owner: jolheiser + name: git-ea +gitea_urls: + api: https://git.jojodev.com/api/v1/ + download: https://git.jojodev.com diff --git a/.woodpecker/goreleaser.yml b/.woodpecker/goreleaser.yml new file mode 100644 index 0000000..f31aa36 --- /dev/null +++ b/.woodpecker/goreleaser.yml @@ -0,0 +1,39 @@ +clone: + git: + image: woodpeckerci/plugin-git + settings: + tags: true + +pipeline: + compliance: + image: golang:1.18 + commands: + - go test -race ./... + - go vet ./... + - go run github.com/rs/zerolog/cmd/lint@latest go.jolheiser.com/git-ea + when: + event: pull_request + + build: + image: goreleaser/goreleaser + commands: + - goreleaser build --snapshot + when: + event: pull_request + + release: + image: goreleaser/goreleaser + commands: + - goreleaser release + secrets: [ gitea_token ] + when: + event: tag + + prune: + image: jolheiser/drone-gitea-prune + settings: + base: https://git.jojodev.com + token: + from_secret: gitea_token + when: + event: tag diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ec2045e --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2022 John Olheiser + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..3e0af21 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# git-ea + +A git extension for Gitea stuff + +# License + +[MIT](LICENSE) \ No newline at end of file diff --git a/cmd/branch.go b/cmd/branch.go new file mode 100644 index 0000000..b1f1d62 --- /dev/null +++ b/cmd/branch.go @@ -0,0 +1,38 @@ +package cmd + +import ( + "context" + "errors" + "flag" + + "github.com/peterbourgon/ff/v3/ffcli" +) + +var ( + branchFS = flag.NewFlagSet("branch", flag.ContinueOnError) + branchNoFetch = branchFS.Bool("no-fetch", false, "Skip fetching") + Branch = &ffcli.Command{ + Name: "branch", + FlagSet: branchFS, + ShortUsage: "branch [base=main]", + ShortHelp: "branch creates a new branch called based on [base]", + Exec: func(ctx context.Context, args []string) error { + if len(args) < 1 { + return errors.New("branch requires at least one argument") + } + + name, base := args[0], "upstream/main" + if len(args) > 1 { + base = args[1] + } + + if !*branchNoFetch { + if err := run(ctx, "git", "fetch", "upstream"); err != nil { + return err + } + } + + return run(ctx, "git", "checkout", "-b", name, base) + }, + } +) diff --git a/cmd/cmd.go b/cmd/cmd.go new file mode 100644 index 0000000..f3e8d2d --- /dev/null +++ b/cmd/cmd.go @@ -0,0 +1,17 @@ +package cmd + +import ( + "context" + "os" + "os/exec" + + +) + +func run(ctx context.Context, cmd string, args ...string) error { + c := exec.CommandContext(ctx, cmd, args...) + c.Stdout = os.Stdout + c.Stderr = os.Stderr + c.Stdin = os.Stdin + return c.Run() +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f5b877d --- /dev/null +++ b/go.mod @@ -0,0 +1,14 @@ +module go.jolheiser.com/git-ea + +go 1.19 + +require ( + github.com/peterbourgon/ff/v3 v3.3.0 + github.com/rs/zerolog v1.27.0 +) + +require ( + github.com/mattn/go-colorable v0.1.12 // indirect + github.com/mattn/go-isatty v0.0.14 // indirect + golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..9e66fa1 --- /dev/null +++ b/go.sum @@ -0,0 +1,15 @@ +github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= +github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= +github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/peterbourgon/ff/v3 v3.3.0 h1:PaKe7GW8orVFh8Unb5jNHS+JZBwWUMa2se0HM6/BI24= +github.com/peterbourgon/ff/v3 v3.3.0/go.mod h1:zjJVUhx+twciwfDl0zBcFzl4dW8axCRyXE/eKY9RztQ= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.27.0 h1:1T7qCieN22GVc8S4Q2yuexzBb1EqjbgjSH9RohbMjKs= +github.com/rs/zerolog v1.27.0/go.mod h1:7frBqO0oezxmnO7GF86FY++uy8I0Tk/If5ni1G9Qc0U= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 h1:foEbQz/B0Oz6YIqu/69kfXPYeFQAuuMYFkjaqXzl5Wo= +golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/main.go b/main.go new file mode 100644 index 0000000..f3a396c --- /dev/null +++ b/main.go @@ -0,0 +1,35 @@ +package main + +import ( + "context" + "os" + + "go.jolheiser.com/git-ea/cmd" + + "github.com/peterbourgon/ff/v3/ffcli" + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" +) + +var Version = "x.y.z" + +func main() { + log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}) + + c := &ffcli.Command{ + Name: "ea", + ShortUsage: "ea ", + ShortHelp: "ea is the base command", + Subcommands: []*ffcli.Command{ + cmd.Branch, + }, + Exec: func(_ context.Context, _ []string) error { + log.Info().Msgf("git-ea v%s", Version) + return nil + }, + } + + if err := c.ParseAndRun(context.Background(), os.Args[1:]); err != nil { + log.Err(err).Msg("") + } +}