Initial commit

Signed-off-by: jolheiser <john.olheiser@gmail.com>
main
jolheiser 2022-08-23 12:04:13 -05:00
commit 2e3ee32df1
Signed by: jolheiser
GPG Key ID: B853ADA5DA7BBF7A
10 changed files with 211 additions and 0 deletions

2
.gitignore vendored 100644
View File

@ -0,0 +1,2 @@
.idea/
/git-ea*

25
.goreleaser.yaml 100644
View File

@ -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

View File

@ -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

19
LICENSE 100644
View File

@ -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.

7
README.md 100644
View File

@ -0,0 +1,7 @@
# git-ea
A git extension for Gitea stuff
# License
[MIT](LICENSE)

38
cmd/branch.go 100644
View File

@ -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 <name> [base=main]",
ShortHelp: "branch creates a new branch called <name> 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)
},
}
)

17
cmd/cmd.go 100644
View File

@ -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()
}

14
go.mod 100644
View File

@ -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
)

15
go.sum 100644
View File

@ -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=

35
main.go 100644
View File

@ -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 <cmd>",
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("")
}
}