mirror of
https://github.com/thegeeklab/git-sv.git
synced 2024-06-03 03:49:39 +02:00
Compare commits
71 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1c480502a3 | ||
|
e8103191c2 | ||
|
834a228d7d | ||
|
41672b77ba | ||
|
fe8df439ce | ||
|
91531a7ea7 | ||
9bdc5e1dd9 | |||
|
c4d961209a | ||
|
dfcf3d0fd4 | ||
|
fc863b54c3 | ||
|
b55f129e52 | ||
|
451e70beac | ||
|
0ce0f59b9a | ||
|
937c6ed547 | ||
|
234b3934f8 | ||
|
9aded778f5 | ||
|
c4d561bc0a | ||
|
aa1aef7b4f | ||
|
cf15d6d1d3 | ||
|
acedfe66e1 | ||
94e81118e6 | |||
|
2d2de1a5e0 | ||
|
689ceb2b16 | ||
bfe498ad0e | |||
b49a0da75c | |||
03c3a72d50 | |||
|
d018cccc70 | ||
|
fc4c4779c1 | ||
|
bda10c1383 | ||
|
095dfef577 | ||
|
6098f3305f | ||
|
656110b555 | ||
|
79e4eded25 | ||
|
ac6282868d | ||
|
ed3f5c25c2 | ||
|
5521c99d9f | ||
|
503327cbcc | ||
837ad200fb | |||
|
815bca2e1c | ||
|
e04f6654c2 | ||
|
6dae5b8ce9 | ||
|
0b780a91aa | ||
|
186d3646e3 | ||
d6a4e34bdb | |||
|
54fb966339 | ||
|
bc3ec2bfe9 | ||
|
3750e21bb2 | ||
|
37775efb47 | ||
e268cd6e07 | |||
|
859e9a6b4c | ||
efe73d7bcc | |||
|
f4777100e8 | ||
|
982c849297 | ||
|
d27fac0770 | ||
|
1d173506de | ||
|
843002e96e | ||
|
b33c37bc77 | ||
a747bdbf8c | |||
|
7266817b9b | ||
|
f059134af5 | ||
|
d22e7f056c | ||
|
b0338bd725 | ||
|
05f448f9d3 | ||
|
0fba70f052 | ||
24ca46653d | |||
42297c3db4 | |||
|
d64335e73a | ||
a2f25f042e | |||
aafeb36d4a | |||
53af856cc5 | |||
66b6f803b8 |
|
@ -35,7 +35,7 @@ release-notes:
|
|||
- name: Documentation
|
||||
commit-types: [docs]
|
||||
section-type: commits
|
||||
- name: Breaking Changes
|
||||
- name: BREAKING CHANGES
|
||||
section-type: breaking-changes
|
||||
|
||||
commit-message:
|
||||
|
|
|
@ -23,7 +23,6 @@ linters:
|
|||
- errchkjson
|
||||
- errname
|
||||
- errorlint
|
||||
- execinquery
|
||||
# - exhaustive
|
||||
- exportloopref
|
||||
- forcetypeassert
|
||||
|
@ -37,12 +36,12 @@ linters:
|
|||
- gocyclo
|
||||
- godot
|
||||
# - godox
|
||||
- goerr113
|
||||
- err113
|
||||
- gofmt
|
||||
- gofumpt
|
||||
- goheader
|
||||
- goimports
|
||||
- gomnd
|
||||
- mnd
|
||||
- gomoddirectives
|
||||
- gomodguard
|
||||
- goprintffuncname
|
||||
|
@ -86,6 +85,7 @@ linters:
|
|||
# - wastedassign
|
||||
- whitespace
|
||||
- wsl
|
||||
- zerologlint
|
||||
fast: false
|
||||
|
||||
run:
|
||||
|
@ -98,7 +98,6 @@ linters-settings:
|
|||
yaml: kebab
|
||||
gofumpt:
|
||||
extra-rules: true
|
||||
lang-version: "1.21"
|
||||
|
||||
issues:
|
||||
exclude-rules:
|
||||
|
|
1
.lycheeignore
Normal file
1
.lycheeignore
Normal file
|
@ -0,0 +1 @@
|
|||
https://hub.docker.com/r/thegeeklab/*
|
|
@ -6,8 +6,8 @@ when:
|
|||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
steps:
|
||||
dryrun:
|
||||
image: quay.io/thegeeklab/wp-docker-buildx:1
|
||||
- name: dryrun
|
||||
image: quay.io/thegeeklab/wp-docker-buildx:4
|
||||
settings:
|
||||
containerfile: Containerfile.multiarch
|
||||
dry_run: true
|
||||
|
@ -19,9 +19,9 @@ steps:
|
|||
when:
|
||||
- event: [pull_request]
|
||||
|
||||
publish-dockerhub:
|
||||
- name: publish-dockerhub
|
||||
image: quay.io/thegeeklab/wp-docker-buildx:4
|
||||
group: container
|
||||
image: quay.io/thegeeklab/wp-docker-buildx:1
|
||||
settings:
|
||||
auto_tag: true
|
||||
containerfile: Containerfile.multiarch
|
||||
|
@ -40,9 +40,9 @@ steps:
|
|||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
publish-quay:
|
||||
- name: publish-quay
|
||||
image: quay.io/thegeeklab/wp-docker-buildx:4
|
||||
group: container
|
||||
image: quay.io/thegeeklab/wp-docker-buildx:1
|
||||
settings:
|
||||
auto_tag: true
|
||||
containerfile: Containerfile.multiarch
|
||||
|
|
|
@ -6,26 +6,25 @@ when:
|
|||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
steps:
|
||||
build:
|
||||
image: docker.io/techknowlogick/xgo:go-1.21.x
|
||||
- name: build
|
||||
image: docker.io/techknowlogick/xgo:go-1.22.x
|
||||
commands:
|
||||
- ln -s $(pwd) /source
|
||||
- make release
|
||||
|
||||
executable:
|
||||
- name: executable
|
||||
image: quay.io/thegeeklab/alpine-tools
|
||||
commands:
|
||||
- $(find dist/ -executable -type f -iname ${CI_REPO_NAME}-linux-amd64) --help
|
||||
|
||||
changelog:
|
||||
- name: changelog
|
||||
image: quay.io/thegeeklab/git-sv
|
||||
commands:
|
||||
- git fetch --depth=2147483647
|
||||
- git sv current-version
|
||||
- git sv release-notes -t ${CI_COMMIT_TAG:-next} -o CHANGELOG.md
|
||||
- cat CHANGELOG.md
|
||||
|
||||
publish-github:
|
||||
- name: publish-github
|
||||
image: docker.io/plugins/github-release
|
||||
settings:
|
||||
api_key:
|
||||
|
@ -36,7 +35,7 @@ steps:
|
|||
overwrite: true
|
||||
title: ${CI_COMMIT_TAG}
|
||||
when:
|
||||
- event: [tag]
|
||||
- event: [tag]
|
||||
|
||||
depends_on:
|
||||
- test
|
||||
|
|
|
@ -6,26 +6,27 @@ when:
|
|||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
steps:
|
||||
markdownlint:
|
||||
- name: markdownlint
|
||||
image: quay.io/thegeeklab/markdownlint-cli
|
||||
group: test
|
||||
commands:
|
||||
- markdownlint 'README.md' 'CONTRIBUTING.md'
|
||||
|
||||
spellcheck:
|
||||
- name: spellcheck
|
||||
image: quay.io/thegeeklab/alpine-tools
|
||||
group: test
|
||||
commands:
|
||||
- spellchecker --files '_docs/**/*.md' 'README.md' 'CONTRIBUTING.md' -d .dictionary -p spell indefinite-article syntax-urls
|
||||
- spellchecker --files 'docs/**/*.md' 'README.md' 'CONTRIBUTING.md' -d .dictionary -p spell indefinite-article syntax-urls
|
||||
environment:
|
||||
FORCE_COLOR: "true"
|
||||
NPM_CONFIG_LOGLEVEL: "error"
|
||||
|
||||
link-validation:
|
||||
- name: link-validation
|
||||
image: docker.io/lycheeverse/lychee
|
||||
group: test
|
||||
commands:
|
||||
- lychee --no-progress --format detailed README.md
|
||||
|
||||
pushrm-dockerhub:
|
||||
- name: pushrm-dockerhub
|
||||
image: docker.io/chko/docker-pushrm:1
|
||||
secrets:
|
||||
- source: docker_password
|
||||
|
@ -42,7 +43,7 @@ steps:
|
|||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
status: [success]
|
||||
|
||||
pushrm-quay:
|
||||
- name: pushrm-quay
|
||||
image: docker.io/chko/docker-pushrm:1
|
||||
secrets:
|
||||
- source: quay_token
|
||||
|
|
|
@ -8,7 +8,7 @@ when:
|
|||
runs_on: [success, failure]
|
||||
|
||||
steps:
|
||||
matrix:
|
||||
- name: matrix
|
||||
image: quay.io/thegeeklab/wp-matrix
|
||||
settings:
|
||||
homeserver:
|
||||
|
|
|
@ -6,12 +6,12 @@ when:
|
|||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
steps:
|
||||
lint:
|
||||
image: docker.io/library/golang:1.21
|
||||
- name: lint
|
||||
image: docker.io/library/golang:1.22
|
||||
commands:
|
||||
- make lint
|
||||
|
||||
test:
|
||||
image: docker.io/library/golang:1.21
|
||||
- name: test
|
||||
image: docker.io/library/golang:1.22
|
||||
commands:
|
||||
- make test
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
FROM --platform=$BUILDPLATFORM golang:1.21@sha256:24a09375a6216764a3eda6a25490a88ac178b5fcb9511d59d0da5ebf9e496474 as build
|
||||
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.22@sha256:f43c6f049f04cbbaeb28f0aad3eea15274a7d0a7899a617d0037aec48d7ab010 as build
|
||||
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
|
@ -8,7 +8,7 @@ WORKDIR /src
|
|||
|
||||
RUN make build
|
||||
|
||||
FROM alpine:3.18@sha256:eece025e432126ce23f223450a0326fbebde39cdf496a85d8c016293fc851978
|
||||
FROM docker.io/library/alpine:3.20@sha256:77726ef6b57ddf65bb551896826ec38bc3e53f75cdde31354fbffb4f25238ebd
|
||||
|
||||
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>"
|
||||
LABEL org.opencontainers.image.authors="Robert Kaussow <mail@thegeeklab.de>"
|
||||
|
|
10
Makefile
10
Makefile
|
@ -1,7 +1,7 @@
|
|||
# renovate: datasource=github-releases depName=mvdan/gofumpt
|
||||
GOFUMPT_PACKAGE_VERSION := v0.5.0
|
||||
GOFUMPT_PACKAGE_VERSION := v0.6.0
|
||||
# renovate: datasource=github-releases depName=golangci/golangci-lint
|
||||
GOLANGCI_LINT_PACKAGE_VERSION := v1.54.2
|
||||
GOLANGCI_LINT_PACKAGE_VERSION := v1.59.0
|
||||
|
||||
EXECUTABLE := git-sv
|
||||
|
||||
|
@ -17,9 +17,10 @@ SOURCES ?= $(shell find . -name "*.go" -type f)
|
|||
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@$(GOFUMPT_PACKAGE_VERSION)
|
||||
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_PACKAGE_VERSION)
|
||||
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
||||
GOTESTSUM_PACKAGE ?= gotest.tools/gotestsum@latest
|
||||
|
||||
GENERATE ?=
|
||||
XGO_VERSION := go-1.21.x
|
||||
XGO_VERSION := go-1.22.x
|
||||
XGO_TARGETS ?= linux/amd64,linux/arm-6,linux/arm-7,linux/arm64
|
||||
|
||||
TARGETOS ?= linux
|
||||
|
@ -68,7 +69,7 @@ generate:
|
|||
|
||||
.PHONY: test
|
||||
test:
|
||||
$(GO) test -v -coverprofile coverage.out $(PACKAGES)
|
||||
$(GO) run $(GOTESTSUM_PACKAGE) --no-color=false -- -coverprofile=coverage.out $(PACKAGES)
|
||||
|
||||
.PHONY: build
|
||||
build: $(DIST)/$(EXECUTABLE)
|
||||
|
@ -99,3 +100,4 @@ deps:
|
|||
$(GO) install $(GOFUMPT_PACKAGE)
|
||||
$(GO) install $(GOLANGCI_LINT_PACKAGE)
|
||||
$(GO) install $(XGO_PACKAGE)
|
||||
$(GO) install $(GOTESTSUM_PACKAGE)
|
||||
|
|
12
app/app.go
12
app/app.go
|
@ -152,15 +152,23 @@ func (g GitSV) Commit(header, body, footer string) error {
|
|||
}
|
||||
|
||||
// Tag create a git tag.
|
||||
func (g GitSV) Tag(version semver.Version) (string, error) {
|
||||
func (g GitSV) Tag(version semver.Version, annotate, local bool) (string, error) {
|
||||
tag := fmt.Sprintf(*g.Config.Tag.Pattern, version.Major(), version.Minor(), version.Patch())
|
||||
tagMsg := fmt.Sprintf("Version %d.%d.%d", version.Major(), version.Minor(), version.Patch())
|
||||
|
||||
tagCommand := exec.Command("git", "tag", "-a", tag, "-m", tagMsg)
|
||||
tagCommand := exec.Command("git", "tag", tag)
|
||||
if annotate {
|
||||
tagCommand.Args = append(tagCommand.Args, "-a", "-m", tagMsg)
|
||||
}
|
||||
|
||||
if out, err := tagCommand.CombinedOutput(); err != nil {
|
||||
return tag, combinedOutputErr(err, out)
|
||||
}
|
||||
|
||||
if local {
|
||||
return tag, nil
|
||||
}
|
||||
|
||||
pushCommand := exec.Command("git", "push", "origin", tag)
|
||||
if out, err := pushCommand.CombinedOutput(); err != nil {
|
||||
return tag, combinedOutputErr(err, out)
|
||||
|
|
|
@ -14,7 +14,7 @@ func ChangelogFlags(settings *app.ChangelogSettings) []cli.Flag {
|
|||
return []cli.Flag{
|
||||
&cli.IntFlag{
|
||||
Name: "size",
|
||||
Value: 10, //nolint:gomnd
|
||||
Value: 10, //nolint:mnd
|
||||
Aliases: []string{"n"},
|
||||
Destination: &settings.Size,
|
||||
Usage: "get changelog from last 'n' tags",
|
||||
|
@ -31,7 +31,7 @@ func ChangelogFlags(settings *app.ChangelogSettings) []cli.Flag {
|
|||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "strict",
|
||||
Usage: "only show tags 'SemVer-ish'",
|
||||
Usage: "only include semver comliant tags",
|
||||
Destination: &settings.Strict,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
|
@ -45,7 +45,7 @@ func ChangelogFlags(settings *app.ChangelogSettings) []cli.Flag {
|
|||
|
||||
//nolint:gocognit
|
||||
func ChangelogHandler(g app.GitSV, settings *app.ChangelogSettings) cli.ActionFunc {
|
||||
return func(c *cli.Context) error {
|
||||
return func(_ *cli.Context) error {
|
||||
tags, err := g.Tags()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -49,7 +49,7 @@ func CommitLogFlags(settings *app.CommitLogSettings) []cli.Flag {
|
|||
}
|
||||
|
||||
func CommitLogHandler(g app.GitSV, settings *app.CommitLogSettings) cli.ActionFunc {
|
||||
return func(c *cli.Context) error {
|
||||
return func(_ *cli.Context) error {
|
||||
var (
|
||||
commits []sv.CommitLog
|
||||
err error
|
||||
|
|
|
@ -39,7 +39,7 @@ func CommitNotesFlags(settings *app.CommitNotesSettings) []cli.Flag {
|
|||
}
|
||||
|
||||
func CommitNotesHandler(g app.GitSV, settings *app.CommitNotesSettings) cli.ActionFunc {
|
||||
return func(c *cli.Context) error {
|
||||
return func(_ *cli.Context) error {
|
||||
var date time.Time
|
||||
|
||||
lr, err := logRange(g, settings.Range, settings.Start, settings.End)
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
func ConfigDefaultHandler() cli.ActionFunc {
|
||||
return func(c *cli.Context) error {
|
||||
return func(_ *cli.Context) error {
|
||||
cfg := app.GetDefault()
|
||||
|
||||
content, err := yaml.Marshal(&cfg)
|
||||
|
@ -24,7 +24,7 @@ func ConfigDefaultHandler() cli.ActionFunc {
|
|||
}
|
||||
|
||||
func ConfigShowHandler(cfg *app.Config) cli.ActionFunc {
|
||||
return func(c *cli.Context) error {
|
||||
return func(_ *cli.Context) error {
|
||||
content, err := yaml.Marshal(cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
func CurrentVersionHandler(gsv app.GitSV) cli.ActionFunc {
|
||||
return func(c *cli.Context) error {
|
||||
return func(_ *cli.Context) error {
|
||||
lastTag := gsv.LastTag()
|
||||
|
||||
currentVer, err := sv.ToVersion(lastTag)
|
||||
|
|
|
@ -3,13 +3,14 @@ package commands
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/thegeeklab/git-sv/app"
|
||||
"github.com/thegeeklab/git-sv/sv"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func NextVersionHandler(g app.GitSV) cli.ActionFunc {
|
||||
return func(c *cli.Context) error {
|
||||
return func(_ *cli.Context) error {
|
||||
lastTag := g.LastTag()
|
||||
|
||||
currentVer, err := sv.ToVersion(lastTag)
|
||||
|
@ -22,7 +23,12 @@ func NextVersionHandler(g app.GitSV) cli.ActionFunc {
|
|||
return fmt.Errorf("error getting git log: %w", err)
|
||||
}
|
||||
|
||||
nextVer, _ := g.CommitProcessor.NextVersion(currentVer, commits)
|
||||
nextVer, updated := g.CommitProcessor.NextVersion(currentVer, commits)
|
||||
if !updated {
|
||||
log.Info().Msgf("nothing to do: current version %s unchanged", currentVer)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("%d.%d.%d\n", nextVer.Major(), nextVer.Minor(), nextVer.Patch())
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ func ReleaseNotesFlags(settings *app.ReleaseNotesSettings) []cli.Flag {
|
|||
}
|
||||
|
||||
func ReleaseNotesHandler(g app.GitSV, settings *app.ReleaseNotesSettings) cli.ActionFunc {
|
||||
return func(c *cli.Context) error {
|
||||
return func(_ *cli.Context) error {
|
||||
var (
|
||||
commits []sv.CommitLog
|
||||
rnVersion *semver.Version
|
||||
|
|
|
@ -3,13 +3,30 @@ package commands
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/thegeeklab/git-sv/app"
|
||||
"github.com/thegeeklab/git-sv/sv"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func TagHandler(g app.GitSV) cli.ActionFunc {
|
||||
return func(c *cli.Context) error {
|
||||
func TagFlags(settings *app.TagSettings) []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "annotate",
|
||||
Aliases: []string{"a"},
|
||||
Usage: "make an annotated tag object",
|
||||
Destination: &settings.Annotate,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "local",
|
||||
Usage: "create local tag only",
|
||||
Destination: &settings.Local,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TagHandler(g app.GitSV, settings *app.TagSettings) cli.ActionFunc {
|
||||
return func(_ *cli.Context) error {
|
||||
lastTag := g.LastTag()
|
||||
|
||||
currentVer, err := sv.ToVersion(lastTag)
|
||||
|
@ -22,15 +39,20 @@ func TagHandler(g app.GitSV) cli.ActionFunc {
|
|||
return fmt.Errorf("error getting git log: %w", err)
|
||||
}
|
||||
|
||||
nextVer, _ := g.CommitProcessor.NextVersion(currentVer, commits)
|
||||
tagname, err := g.Tag(*nextVer)
|
||||
nextVer, updated := g.CommitProcessor.NextVersion(currentVer, commits)
|
||||
if !updated {
|
||||
log.Info().Msgf("nothing to do: current version %s unchanged", currentVer)
|
||||
|
||||
fmt.Println(tagname)
|
||||
return nil
|
||||
}
|
||||
|
||||
tagname, err := g.Tag(*nextVer, settings.Annotate, settings.Local)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error generating tag version: %s: %w", nextVer.String(), err)
|
||||
}
|
||||
|
||||
fmt.Println(tagname)
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ type Settings struct {
|
|||
ReleaseNotesSettings ReleaseNotesSettings
|
||||
CommitNotesSettings CommitNotesSettings
|
||||
CommitLogSettings CommitLogSettings
|
||||
TagSettings TagSettings
|
||||
}
|
||||
|
||||
type ChangelogSettings struct {
|
||||
|
@ -48,6 +49,11 @@ type CommitLogSettings struct {
|
|||
End string
|
||||
}
|
||||
|
||||
type TagSettings struct {
|
||||
Annotate bool
|
||||
Local bool
|
||||
}
|
||||
|
||||
// Config cli yaml config.
|
||||
type Config struct {
|
||||
Version string `yaml:"version"`
|
||||
|
|
|
@ -148,6 +148,7 @@ func Test_merge(t *testing.T) {
|
|||
if err := merge(&tt.dst, tt.src); (err != nil) != tt.wantErr {
|
||||
t.Errorf("merge() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(tt.dst, tt.want) {
|
||||
t.Errorf("merge() = %v, want %v", tt.dst, tt.want)
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ var (
|
|||
func main() {
|
||||
gsv := app.New()
|
||||
|
||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||
cli.VersionPrinter = func(c *cli.Context) {
|
||||
fmt.Printf("%s version=%s date=%s\n", c.App.Name, c.App.Version, BuildDate)
|
||||
}
|
||||
|
@ -37,9 +38,7 @@ func main() {
|
|||
Destination: &gsv.Settings.LogLevel,
|
||||
},
|
||||
},
|
||||
Before: func(ctx *cli.Context) error {
|
||||
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
|
||||
|
||||
Before: func(_ *cli.Context) error {
|
||||
lvl, err := zerolog.ParseLevel(gsv.Settings.LogLevel)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -117,7 +116,8 @@ When flag range is "date", if "end" is YYYY-MM-DD the range will be inclusive.`,
|
|||
Name: "tag",
|
||||
Aliases: []string{"tg"},
|
||||
Usage: "generate tag with version based on git commit messages",
|
||||
Action: commands.TagHandler(gsv),
|
||||
Action: commands.TagHandler(gsv, &gsv.Settings.TagSettings),
|
||||
Flags: commands.TagFlags(&gsv.Settings.TagSettings),
|
||||
},
|
||||
{
|
||||
Name: "commit",
|
||||
|
|
14
go.mod
14
go.mod
|
@ -1,21 +1,21 @@
|
|||
module github.com/thegeeklab/git-sv
|
||||
|
||||
go 1.21
|
||||
go 1.22
|
||||
|
||||
require (
|
||||
dario.cat/mergo v1.0.0
|
||||
github.com/Masterminds/semver/v3 v3.2.1
|
||||
github.com/Masterminds/sprig/v3 v3.2.3
|
||||
github.com/manifoldco/promptui v0.9.0
|
||||
github.com/rs/zerolog v1.31.0
|
||||
github.com/urfave/cli/v2 v2.25.7
|
||||
github.com/rs/zerolog v1.33.0
|
||||
github.com/urfave/cli/v2 v2.27.2
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Masterminds/goutils v1.1.1 // indirect
|
||||
github.com/chzyer/readline v1.5.1 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
|
||||
github.com/google/uuid v1.3.1 // indirect
|
||||
github.com/huandu/xstrings v1.4.0 // indirect
|
||||
github.com/imdario/mergo v0.3.16 // indirect
|
||||
|
@ -27,8 +27,8 @@ require (
|
|||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/shopspring/decimal v1.3.1 // indirect
|
||||
github.com/spf13/cast v1.5.1 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||
golang.org/x/crypto v0.14.0 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
|
||||
golang.org/x/crypto v0.17.0 // indirect
|
||||
golang.org/x/sys v0.15.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
)
|
||||
|
|
24
go.sum
24
go.sum
|
@ -17,8 +17,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
|
|||
github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04=
|
||||
github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
|
@ -62,8 +62,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
|
|||
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
|
||||
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
|
||||
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
|
@ -76,16 +76,16 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
|||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
|
||||
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
|
||||
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
|
||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
|
||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
|
||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
||||
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
|
@ -104,8 +104,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
||||
|
|
|
@ -115,9 +115,11 @@ func TestSemVerCommitProcessor_NextVersion(t *testing.T) {
|
|||
},
|
||||
CommitMessageConfig{Types: []string{"major", "minor", "patch", "none"}})
|
||||
got, gotUpdated := p.NextVersion(tt.version, tt.commits)
|
||||
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("SemVerCommitProcessor.NextVersion() Version = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
||||
if tt.wantUpdated != gotUpdated {
|
||||
t.Errorf("SemVerCommitProcessor.NextVersion() Updated = %v, want %v", gotUpdated, tt.wantUpdated)
|
||||
}
|
||||
|
@ -144,6 +146,7 @@ func TestToVersion(t *testing.T) {
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("ToVersion() = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
|
|
@ -114,6 +114,7 @@ func Test_checkTemplatesExecution(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.template, func(t *testing.T) {
|
||||
var b bytes.Buffer
|
||||
|
||||
err := tpls.ExecuteTemplate(&b, tt.template, tt.variables)
|
||||
if err != nil {
|
||||
t.Errorf("invalid template err = %v", err)
|
||||
|
|
|
@ -249,7 +249,7 @@ func (p BaseMessageProcessor) IssueID(branch string) (string, error) {
|
|||
}
|
||||
|
||||
groups := r.FindStringSubmatch(branch)
|
||||
if len(groups) != 4 { //nolint:gomnd
|
||||
if len(groups) != 4 { //nolint:mnd
|
||||
return "", nil
|
||||
}
|
||||
|
||||
|
@ -292,22 +292,22 @@ func removeCarriage(commit string) string {
|
|||
// Parse a commit message.
|
||||
func (p BaseMessageProcessor) Parse(subject, body string) (CommitMessage, error) {
|
||||
preparedSubject, err := p.prepareHeader(subject)
|
||||
commitBody := removeCarriage(body)
|
||||
m := CommitMessage{}
|
||||
|
||||
if err != nil {
|
||||
return CommitMessage{}, err
|
||||
return m, err
|
||||
}
|
||||
|
||||
commitType, scope, description, hasBreakingChange := parseSubjectMessage(preparedSubject)
|
||||
|
||||
metadata := make(map[string]string)
|
||||
m.Metadata = make(map[string]string)
|
||||
m.Body = removeCarriage(body)
|
||||
m.Type, m.Scope, m.Description, m.IsBreakingChange = parseSubjectMessage(preparedSubject)
|
||||
|
||||
for key, mdCfg := range p.messageCfg.Footer {
|
||||
if mdCfg.Key != "" {
|
||||
prefixes := append([]string{mdCfg.Key}, mdCfg.KeySynonyms...)
|
||||
for _, prefix := range prefixes {
|
||||
if tagValue := extractFooterMetadata(prefix, commitBody, mdCfg.UseHash); tagValue != "" {
|
||||
metadata[key] = tagValue
|
||||
if tagValue := extractFooterMetadata(prefix, m.Body, mdCfg.UseHash); tagValue != "" {
|
||||
m.Metadata[key] = tagValue
|
||||
|
||||
break
|
||||
}
|
||||
|
@ -315,19 +315,16 @@ func (p BaseMessageProcessor) Parse(subject, body string) (CommitMessage, error)
|
|||
}
|
||||
}
|
||||
|
||||
if tagValue := extractFooterMetadata(BreakingChangeFooterKey, commitBody, false); tagValue != "" {
|
||||
metadata[BreakingChangeMetadataKey] = tagValue
|
||||
hasBreakingChange = true
|
||||
if m.IsBreakingChange {
|
||||
m.Metadata[BreakingChangeMetadataKey] = m.Description
|
||||
}
|
||||
|
||||
return CommitMessage{
|
||||
Type: commitType,
|
||||
Scope: scope,
|
||||
Description: description,
|
||||
Body: commitBody,
|
||||
IsBreakingChange: hasBreakingChange,
|
||||
Metadata: metadata,
|
||||
}, nil
|
||||
if tagValue := extractFooterMetadata(BreakingChangeFooterKey, m.Body, false); tagValue != "" {
|
||||
m.IsBreakingChange = true
|
||||
m.Metadata[BreakingChangeMetadataKey] = tagValue
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (p BaseMessageProcessor) prepareHeader(header string) (string, error) {
|
||||
|
@ -363,7 +360,7 @@ func parseSubjectMessage(message string) (string, string, string, bool) {
|
|||
regex := regexp.MustCompile(`([a-z]+)(\((.*)\))?(!)?: (.*)`)
|
||||
|
||||
result := regex.FindStringSubmatch(message)
|
||||
if len(result) != 6 { //nolint:gomnd
|
||||
if len(result) != 6 { //nolint:mnd
|
||||
return "", "", message, false
|
||||
}
|
||||
|
||||
|
@ -371,15 +368,14 @@ func parseSubjectMessage(message string) (string, string, string, bool) {
|
|||
}
|
||||
|
||||
func extractFooterMetadata(key, text string, useHash bool) string {
|
||||
var regex *regexp.Regexp
|
||||
regex := regexp.MustCompile(key + ": (.*)")
|
||||
|
||||
if useHash {
|
||||
regex = regexp.MustCompile(key + " (#.*)")
|
||||
} else {
|
||||
regex = regexp.MustCompile(key + ": (.*)")
|
||||
}
|
||||
|
||||
result := regex.FindStringSubmatch(text)
|
||||
if len(result) < 2 { //nolint:gomnd
|
||||
if len(result) < 2 { //nolint:mnd
|
||||
return ""
|
||||
}
|
||||
|
||||
|
@ -396,6 +392,7 @@ func hasFooter(message string) bool {
|
|||
if lines > 0 && r.MatchString(scanner.Text()) {
|
||||
return true
|
||||
}
|
||||
|
||||
lines++
|
||||
}
|
||||
|
||||
|
|
|
@ -385,6 +385,7 @@ func TestBaseMessageProcessor_Enhance(t *testing.T) {
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
if got != tt.want {
|
||||
t.Errorf("BaseMessageProcessor.Enhance() = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
@ -416,6 +417,7 @@ func TestBaseMessageProcessor_IssueID(t *testing.T) {
|
|||
|
||||
return
|
||||
}
|
||||
|
||||
if got != tt.want {
|
||||
t.Errorf("BaseMessageProcessor.IssueID() = %v, want %v", got, tt.want)
|
||||
}
|
||||
|
@ -604,7 +606,7 @@ func TestBaseMessageProcessor_Parse(t *testing.T) {
|
|||
},
|
||||
},
|
||||
{
|
||||
"breaking change with exclamation mark",
|
||||
"breaking change with empty body",
|
||||
ccfg,
|
||||
"feat!: something new", "",
|
||||
CommitMessage{
|
||||
|
@ -613,7 +615,9 @@ func TestBaseMessageProcessor_Parse(t *testing.T) {
|
|||
Description: "something new",
|
||||
Body: "",
|
||||
IsBreakingChange: true,
|
||||
Metadata: map[string]string{},
|
||||
Metadata: map[string]string{
|
||||
BreakingChangeMetadataKey: "something new",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -779,9 +783,11 @@ func TestBaseMessageProcessor_Format(t *testing.T) {
|
|||
if got != tt.wantHeader {
|
||||
t.Errorf("BaseMessageProcessor.Format() header got = %v, want %v", got, tt.wantHeader)
|
||||
}
|
||||
|
||||
if got1 != tt.wantBody {
|
||||
t.Errorf("BaseMessageProcessor.Format() body got = %v, want %v", got1, tt.wantBody)
|
||||
}
|
||||
|
||||
if got2 != tt.wantFooter {
|
||||
t.Errorf("BaseMessageProcessor.Format() footer got = %v, want %v", got2, tt.wantFooter)
|
||||
}
|
||||
|
@ -813,6 +819,7 @@ func Test_splitCommitMessageContent(t *testing.T) {
|
|||
if got != tt.wantSubject {
|
||||
t.Errorf("splitCommitMessageContent() subject got = %v, want %v", got, tt.wantSubject)
|
||||
}
|
||||
|
||||
if got1 != tt.wantBody {
|
||||
t.Errorf("splitCommitMessageContent() body got1 = [%v], want [%v]", got1, tt.wantBody)
|
||||
}
|
||||
|
@ -840,12 +847,15 @@ func Test_parseSubjectMessage(t *testing.T) {
|
|||
if ctype != tt.wantType {
|
||||
t.Errorf("parseSubjectMessage() type got = %v, want %v", ctype, tt.wantType)
|
||||
}
|
||||
|
||||
if scope != tt.wantScope {
|
||||
t.Errorf("parseSubjectMessage() scope got = %v, want %v", scope, tt.wantScope)
|
||||
}
|
||||
|
||||
if description != tt.wantDescription {
|
||||
t.Errorf("parseSubjectMessage() description got = %v, want %v", description, tt.wantDescription)
|
||||
}
|
||||
|
||||
if hasBreakingChange != tt.wantHasBreakingChange {
|
||||
t.Errorf("parseSubjectMessage() hasBreakingChange got = %v, want %v", hasBreakingChange, tt.wantHasBreakingChange)
|
||||
}
|
||||
|
@ -911,7 +921,7 @@ func Test_prepareHeader(t *testing.T) {
|
|||
},
|
||||
{
|
||||
"matching non-conventional with invalid regex",
|
||||
"Merged PR (\\d+): (?<header>.*)",
|
||||
"Merged PR (\\d+): (<header>.*)",
|
||||
"Merged PR 123: something",
|
||||
"",
|
||||
true,
|
||||
|
@ -925,6 +935,7 @@ func Test_prepareHeader(t *testing.T) {
|
|||
if tt.wantError && err == nil {
|
||||
t.Errorf("prepareHeader() err got = %v, want not nil", err)
|
||||
}
|
||||
|
||||
if header != tt.wantHeader {
|
||||
t.Errorf("prepareHeader() header got = %v, want %v", header, tt.wantHeader)
|
||||
}
|
||||
|
|
|
@ -77,8 +77,7 @@ func (p BaseReleaseNoteProcessor) Create(
|
|||
sections[sectionCfg.Name] = section
|
||||
}
|
||||
|
||||
if commit.Message.BreakingMessage() != "" {
|
||||
// TODO: if no message found, should use description instead?
|
||||
if commit.Message.IsBreakingChange {
|
||||
breakingChanges = append(breakingChanges, commit.Message.BreakingMessage())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user