Skip to content

Commit

Permalink
Merge main into sweep/add-sweep-config
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] authored Nov 11, 2023
2 parents 14e6dba + d7d9261 commit bbd3bee
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 704 deletions.
8 changes: 5 additions & 3 deletions .custom-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
PROJECT_BASE_PATH=$(git rev-parse --show-toplevel)
cd $PROJECT_BASE_PATH

GO_FILES_STAGED=$(git diff --name-only --cached | grep .go | wc -l)
GO_FILES_STAGED=$(git diff --name-only --cached | egrep '\.go$' | wc -l)

echo "[pre-commit] GO_FILES_STAGED=$GO_FILES_STAGED"

if [ ! -z "$GO_FILES_STAGED" ] && [ "$GO_FILES_STAGED" != "0" ]; then
GOLINT_BIN=$(which golangci-lint)

if [ ! -z "$GOLINT_BIN" ]; then
LAST_COMMIT=$(git rev-parse HEAD)
SRC_PATHS=$(find . -name "*.go" -printf '%h/**\n' | egrep -v '(\./\..+|tools|build|dist)')
SRC_PATHS=$(find . -name "*.go" -printf '%h/**\n' | egrep -v '(\./\..+|tools|build|dist)') | tr '\n' ' '

if [ -z "$SRC_PATHS" ]; then
SRC_PATHS="./**"
SRC_PATHS="./app ./cmd"
fi

echo "[pre-commit] $GOLINT_BIN run -c ./.golangci.yaml --new-from-rev $LAST_COMMIT $SRC_PATHS"
Expand Down
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github: {{project.vendor.github}}
github: permafrost-dev
2 changes: 1 addition & 1 deletion .github/SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Security Policy

If you discover any security related issues, please email {{project.author.email}} instead of using the issue tracker.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.

13 changes: 1 addition & 12 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ archives:

builds:
- main: './main.go'
binary: '{{project.name}}'
binary: 'gn'
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath
Expand All @@ -27,17 +27,6 @@ builds:
- darwin_arm64
- darwin_amd64

brews:
-
name: '{{project.name}}'
homepage: 'https://github.com/{{project.vendor.github}}/{{project.name}}'
description: '{{project.description}}'
license: "MIT"
tap:
owner: '{{project.vendor.github}}'
name: homebrew-{{project.name}}
branch: main

checksum:
name_template: "checksums.txt"
algorithm: sha256
Expand Down
8 changes: 0 additions & 8 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,8 +0,0 @@
The MIT License (MIT)
Copyright © {{date.year}} {{project.vendor.name}}

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.
38 changes: 3 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,10 @@
# {{project.name.full}}
# git-ninja

---

<!-- ==START TEMPLATE README== -->

<p align="center">
<img style="width: 80%;" src="assets/social-card.png" alt="go project template" />
</p>

## Description

This repository is a starter template for Golang projects using the latest version of Go.
Use it to create command-line applications, web apps, and more.

It includes:

- configuration and workflow for `goreleaser`, a tool for building and publishing Go binaries.
- configuration for `golangci-lint`, a tool for Go that runs many linters in parallel.
- configuration for `task`, a tool similar to `make`. To download `task`, see the [task project page](https://github.com/go-task/task/).

Also included is a configuration and workflow for Dependabot, a tool for keeping dependencies up to date.
Dependencies are updated automatically and pull requests are created to merge the changes; minor and patch version updates are automatically merged.

## Template Setup

To configure, run:

```bash
go run tools/configure-project.go
```

The configure script will ask you a series of questions that will customize the template with values such as your name, GitHub username, email address, use of optional packages, and more.

Some of the default values are automatically determined based on your git configuration, but you may change any of the values when prompted.

<!-- ==END TEMPLATE README== -->

{{project.description}}
Git alias commands

## Setup

Expand Down Expand Up @@ -67,7 +35,7 @@ Please review [our security policy](../../security/policy) on how to report secu

## Credits

- [{{project.author.name}}](https://github.com/{{project.author.github}})
- [Patrick Organ](https://github.com/patinthehat)
- [All Contributors](../../contributors)

## License
Expand Down
18 changes: 9 additions & 9 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ tasks:
deps:
- task: update-version-file
cmds:
- task: build-{{project.name}}
- task: build-git-ninja

clean:
desc: Cleans up build artifacts
preconditions:
- test -d ./dist
- test -f ./dist/{{project.name}}
- test -f ./dist/git-ninja
cmds:
- rm -f ./dist/{{project.name}}
- rm -f ./dist/git-ninja

lint:
cmds:
- task: lint-dotenv
- task: lint-{{project.name}}
- task: lint-git-ninja

update-version-file:
vars:
Expand All @@ -48,7 +48,7 @@ tasks:
cmds:
- dotenv-linter {{.DOTENV_FILES}}

lint-{{project.name}}:
lint-git-ninja:
internal: true
vars:
GO_SRC_DIRS:
Expand All @@ -59,8 +59,8 @@ tasks:
cmds:
- golangci-lint run {{.GO_SRC_DIRS}}

build-{{project.name}}:
desc: Builds {{project.name}} binary
build-git-ninja:
desc: Builds git-ninja binary
vars:
GIT_COMMIT:
sh: git log -n 1 --format=%h
Expand All @@ -70,10 +70,10 @@ tasks:
- './internal/**/*.go'
- './main.go'
generates:
- ./dist/{{project.name}}
- ./dist/git-ninja
cmds:
- mkdir -p ./dist
- go build -trimpath -ldflags="-s -w -X main.Version={{.VERSION}}-{{.GIT_COMMIT}}" -o dist/{{project.name}} .
- go build -trimpath -ldflags="-s -w -X main.Version={{.VERSION}}-{{.GIT_COMMIT}}" -o dist/git-ninja .

release:
desc: Creates a new snapshot release
Expand Down
39 changes: 39 additions & 0 deletions app/helpers/git-helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package githelpers

import (
"bufio"
"bytes"
"fmt"
"os/exec"
"strings"
)

func GetLastCheckedoutBranchName() (string, error) {
var out bytes.Buffer

cmd := exec.Command("git", "reflog", "show", "--pretty=format:%gs", "--date=relative")
cmd.Stdout = &out

if err := cmd.Run(); err != nil {
return "", err
}

// Scan through each line of output
scanner := bufio.NewScanner(strings.NewReader(out.String()))
for scanner.Scan() {
line := scanner.Text()
// Check if the line contains 'checkout:'
if strings.Contains(line, "checkout:") {
fields := strings.Fields(line)
if len(fields) >= 4 {
return fields[3], nil // Return the fourth word (branch name)
}
}
}

if err := scanner.Err(); err != nil {
return "", err
}

return "", fmt.Errorf("no checkout entries found")
}
2 changes: 1 addition & 1 deletion app/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package app
package main

var Version = "0.0.0"
Binary file removed assets/social-card.png
Binary file not shown.
Binary file removed assets/social-card.xcf
Binary file not shown.
51 changes: 51 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"os"

"github.com/spf13/cobra"
)



// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "git-ninja",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.git-ninja.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}


40 changes: 40 additions & 0 deletions cmd/showLastBranch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
githelpers "github.com/vendor-name/git-ninja/app/helpers"
)

// showLastBranchCmd represents the showLastBranch command
var showLastBranchCmd = &cobra.Command{
Use: "branch:show-last",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(githelpers.GetLastCheckedoutBranchName())
},
}

func init() {
rootCmd.AddCommand(showLastBranchCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// showLastBranchCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// showLastBranchCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
module github.com/vendor-name/project-name
module github.com/vendor-name/git-ninja

go 1.19

require github.com/blang/semver v3.5.1+incompatible

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
11 changes: 11 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
*/
package main

import "github.com/vendor-name/git-ninja/cmd"

func main() {
cmd.Execute()
}
Loading

0 comments on commit bbd3bee

Please sign in to comment.