groomba

package module
v0.3.37 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

README

Groomba

GitHub Workflow Status Go Version go report PkgGoDev

Groomba is a simple utility written in Go to groom your git repositories. It will rename branches older than a defined age. Unlike other tools like the Stale Github Action, Groomba only depends on the git APIs and is agnostic of the software used to host your git repository. It will work just as well whether your repos are hosted in Github, Gitlab, Btbucket or something else.

Installation

Download and run latest version:

curl -sL https://git.io/groomba | bash

Download and run specific version, ex v0.3.17:

curl -sL https://git.io/groomba | VERSION=v0.3.17 bash

You can add the snippet above as a step in your CI pipeline on your main branch to periodically groom your repository.

Install using go install

go install github.com/avbm/groomba/cmd/groomba@latest

Pre-built binaries are available only for x86_64 linux and OSX. For other architectures and OS systems please build your binaries using the Build from souce section.

Build from source

To build Groomba from source you need to have the golang compiler installed and configured. Clone this repository and from the root of the repository run:

$ cd cmd/groomba && go build .

This should fetch all dependencies and create a binary called groomba in the current directory.

Configuration Options

To configure Groomba, you can set each configuration option in a .groomba.toml or .groomba.yaml file at the root of the repository you want to Groom. Alternately these options can also be set as environment variables. Options set as environment variables take the highest precedence.

Name Type Default Description
Auth string default Type of authentication to use, valid values:("default", "ssh-agent")
Clobber bool false Toggle to enable or disable clobber mode
DryRun bool false Toggle to enable or disable dry run mode
MaxConcurrency uint8 4 Set the maximum number of concurrent workers, set to 0 or 1 to disable concurrency
Prefix string stale/ Identifier that will be added to the beginning of stale branch names to mark them as stale
StaleAgeThreshold int 14 Threshold age in days for considering a branch as stale
StaticBranches []string ["master", "main"] List of branches that are considered as static or protected and will be ignored
Auth

Auth is a string that tells Groomba which authentication mechanism to use. Currently only 2 mechanisms are supported, default which uses the default credentials which were used to clone the repository and ssh-agent to use the keys available in a local ssh-agent session.

Default: default

To set to a different value, say ssh-agent:

# in .groomba.toml
auth = "ssh-agent"

# or in .groomba.yaml
auth: "ssh-agent"

# or as an environment variable
GROOMBA_AUTH="ssh-agent"
Clobber

Clobber is a bool that tells Groomba whether to run in clobber mode. In this mode, Groomba will clobber ie overwrite remote stale branches if they already exist and are not fast-forward merge-able. For example, if a repository has both branches abc and stale/abc already then with clobber mode enabled, branch abc will overwrite branch stale/abc. On the other hand if clobber mode is disabled(default), Groomba will fail to move abc to stale/abc.

Default: false

To set to a different value, say true:

# in .groomba.toml
clobber = true

# or in .groomba.yaml
clobber: true

# or as an environment variable
GROOMBA_CLOBBER="true"

Note: Any truthy value will enable: true, True, 1 or any falsy value will disable: false, False, 0

DryRun

DryRun is a bool that tells Groomba whether to run in dry run mode. In this mode, Groomba will only print out messages informing users about which branches would be moved without actually moving them.

Default: false

To set to a different value, say true:

# in .groomba.toml
dry_run = true

# or in .groomba.yaml
dry_run: true

# or as an environment variable
GROOMBA_DRY_RUN="true"

Note: Any truthy value will enable: true, True, 1 or any falsy value will disable: false, False, 0

MaxConcurrency

MaxConcurrency is a unit8 value that tells Groomba the number of worker processes to start. Each worker concurrently handles moving 1 branch.

Default: 4

To set to a different value, say 10:

# in .groomba.toml
max_concurrency = 10

# or in .groomba.yaml
max_concurrency: 10

# or as an environment variable
GROOMBA_DRY_RUN=10

Note: Since MaxConcurrency is a unit8 it can only be set to values from [0 ,255] inclusive. Setting the value to either 0 or 1 ensures only 1 worker is used ie only one branch is moved at a time.

Prefix

Prefix is a string that will be added to the beginning of stale branch names to mark them as stale.

Default: stale/

To set to a different value, say zzz_, to keep stale branches at the bottom during sorted views:

# in .groomba.toml
prefix = zzz_

# or in .groomba.yaml
prefix: zzz_

# or as an environment variable
GROOMBA_PREFIX="zzz_"
StaleAgeThreshold

StaleAgeThreshold is the threshold age in days for considering a branch as stale. It is expected to be an integer.

Default: 14

To set to a different value, say 30:

# in .groomba.toml
stale_age_threshold = 30

# or in .groomba.yaml
stale_age_threshold: 30

# or as an environment variable
GROOMBA_STALE_AGE_THRESHOLD=3
StaticBranches

StaticBranches is a list of branches that Groomba considers as static or protected and will ignore.

Default: ["master", "main"]

To set to a different value, say ["latest", "staging", "production"]:

# in .groomba.toml
static_branches = ["latest", "staging", "production"]

# or in .groomba.yaml
stale_age_threshold: ["latest", "staging", "production"]

# or this also works in yaml
stale_age_threshold:
  - latest
  - staging
  - production

# or as an environment variable
GROOMBA_STATIC_BRANCHES="latest,staging,production"

Planned Improvements

List of enhancements for Groomba in no particular order:

  • A good logo: every open source tool needs a good logo ;)
  • Passing command line flags and arguments: currently I am planning on adding support for arguments and flags using Cobra
  • Delete (really) old branches: delete branches older than a set threshold instead of renaming them
  • Add tests for failing to delete reference at remote

Bugs and feature requests

If you notice a bug or have a feature request please feel free to file an issue. Merge Requests with contributions or corrections are also welcome.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckIfError

func CheckIfError(err error, message ...string)

CheckIfError should be used to naively panic if an error is not nil.

Types

type Authenticator added in v0.3.10

type Authenticator interface {
	Get() transport.AuthMethod
}

type Config

type Config struct {
	Auth              auth.AuthType `yaml:"auth" toml:"auth"`
	Clobber           bool          `yaml:"clobber" toml:"clobber"`
	DryRun            bool          `yaml:"dry_run" toml:"dry_run"`
	MaxConcurrency    uint8         `yaml:"max_concurrency" toml:"max_concurrency"`
	Prefix            string        `yaml:"prefix" toml:"prefix"`
	StaleAgeThreshold int           `yaml:"stale_age_threshold" toml:"stale_age_threshold"`
	StaticBranches    []string      `yaml:"static_branches" toml:"static_branches"`
}

Config stores the configuration for Groomba

func GetConfig

func GetConfig(configPath string) (*Config, error)

type Groomba

type Groomba struct {
	// contains filtered or unexported fields
}

Groomba base type to store config and other shared references

func NewGroomba

func NewGroomba(config *Config, repo *git.Repository, a Authenticator) Groomba

func (Groomba) FilterBranches

func (g Groomba) FilterBranches(referenceDate time.Time) ([]*plumbing.Reference, error)

func (Groomba) IsStaticBranch

func (g Groomba) IsStaticBranch(name string) bool

func (Groomba) MoveBranch

func (g Groomba) MoveBranch(refName string) *MoveBranchError

func (Groomba) MoveStaleBranches

func (g Groomba) MoveStaleBranches(branches []*plumbing.Reference) error

func (Groomba) PrintBranchesGroupbyAuthor

func (g Groomba) PrintBranchesGroupbyAuthor(branches []*plumbing.Reference) error
Example
InitTest()

cfg, _ := GetConfig(".")
repo, _ := git.PlainOpen("testdata/dst")
g := Groomba{cfg: cfg, repo: repo, auth: &MockAuthenticator{}}

fb, _ := g.FilterBranches(time.Now())
_ = g.PrintBranchesGroupbyAuthor(fb)
Output:

Test:
    - name: refs/remotes/origin/IsStale
      age: 19d
    - name: refs/remotes/origin/IsStale2
      age: 19d

type MoveBranchError added in v0.3.3

type MoveBranchError struct {
	// contains filtered or unexported fields
}

MoveBranchError defines the errors during the MoveBranch step

func (*MoveBranchError) Error added in v0.3.3

func (e *MoveBranchError) Error() string

Error so MoveBranchError satisfies the error interface

func (*MoveBranchError) Unwrap added in v0.3.3

func (e *MoveBranchError) Unwrap() error

Unwrap for MoveBranchError

type MoveBranchOperation added in v0.3.3

type MoveBranchOperation int

MoveBranchOperation defines the various operatons during MoveBranch

const (
	CopyBranch MoveBranchOperation = iota
	DeleteBranch
)

type MoveStaleBranchesError added in v0.3.3

type MoveStaleBranchesError struct {
	// contains filtered or unexported fields
}

MoveStaleBranchesError stores all errors from MoveBranches

func (*MoveStaleBranchesError) Error added in v0.3.3

func (m *MoveStaleBranchesError) Error() string

Error so MoveStaleBranchesError satisfies the error interface

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL