0
0
mirror of https://github.com/thegeeklab/git-sv.git synced 2024-06-02 17:39:39 +02:00

Compare commits

...

72 Commits
v0.1.1 ... main

Author SHA1 Message Date
renovate[bot]
1c480502a3
chore(deps): update docker.io/library/alpine docker tag to v3.20 (#72)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-06-01 13:22:00 +02:00
renovate[bot]
e8103191c2 chore(deps): update dependency golangci/golangci-lint to v1.59.0 2024-05-27 04:13:44 +00:00
renovate[bot]
834a228d7d
fix(deps): update module github.com/rs/zerolog to v1.33.0 (#73)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-05-24 09:38:11 +02:00
renovate[bot]
41672b77ba chore(deps): update dependency golangci/golangci-lint to v1.58.2 2024-05-20 08:23:28 +00:00
renovate[bot]
fe8df439ce
chore(docker): update docker.io/library/golang:1.22 docker digest to f43c6f0 (#70)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-05-17 09:36:56 +02:00
renovate[bot]
91531a7ea7 chore(deps): update dependency golangci/golangci-lint to v1.58.1 2024-05-13 03:43:43 +00:00
9bdc5e1dd9
ci: fix golangci-lint deprecations 2024-05-12 11:08:29 +02:00
renovate[bot]
c4d961209a chore(docker): update docker.io/library/golang:1.22 docker digest to b1e05e2 2024-05-08 03:51:32 +00:00
renovate[bot]
dfcf3d0fd4 chore(deps): update dependency golangci/golangci-lint to v1.58.0 2024-05-06 04:35:13 +00:00
renovate[bot]
fc863b54c3
fix(deps): update module github.com/urfave/cli/v2 to v2.27.2 (#66)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-29 10:27:24 +02:00
renovate[bot]
b55f129e52 chore(docker): update docker.io/library/golang:1.22 docker digest to d5302d4 2024-04-25 04:15:17 +00:00
renovate[bot]
451e70beac chore(docker): update docker.io/library/golang:1.22 docker digest to 450e382 2024-04-11 08:51:04 +00:00
renovate[bot]
0ce0f59b9a chore(docker): update docker.io/library/golang:1.22 docker digest to c4fb952 2024-04-04 04:36:20 +00:00
renovate[bot]
937c6ed547
chore(deps): update dependency golangci/golangci-lint to v1.57.2 (#62)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-02 09:08:31 +02:00
renovate[bot]
234b3934f8
chore(deps): update quay.io/thegeeklab/wp-docker-buildx docker tag to v4 (#61)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-03-27 08:55:26 +01:00
renovate[bot]
9aded778f5 chore(deps): update dependency golangci/golangci-lint to v1.57.1 2024-03-25 03:43:45 +00:00
renovate[bot]
c4d561bc0a chore(docker): update docker.io/library/golang:1.22 docker digest to 0b55ab8 2024-03-13 07:25:11 +00:00
renovate[bot]
aa1aef7b4f chore(docker): update docker.io/library/golang:1.22 docker digest to 34ce21a 2024-03-06 05:05:13 +00:00
renovate[bot]
cf15d6d1d3 chore(deps): update dependency golangci/golangci-lint to v1.56.2 2024-02-19 03:39:20 +00:00
renovate[bot]
acedfe66e1 chore(docker): update docker.io/library/golang:1.22 docker digest to 7b297d9 2024-02-16 03:55:11 +00:00
94e81118e6
[skip ci] revert renovate automerge config 2024-02-15 12:19:30 +01:00
renovate[bot]
2d2de1a5e0
chore(deps): update golang devdeps non-major (#55)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Robert Kaussow <mail@thegeeklab.de>
2024-02-12 09:09:42 +01:00
renovate[bot]
689ceb2b16
chore(deps): update docker.io/library/golang docker tag to v1.22 (#53)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Robert Kaussow <mail@thegeeklab.de>
2024-02-07 22:32:36 +01:00
bfe498ad0e
harmonize container image refs and use fqin 2024-02-07 09:40:51 +01:00
b49a0da75c
run ci on renovate auto branches 2024-02-07 09:10:12 +01:00
03c3a72d50
ci: enable ci run on renovate branches 2024-02-05 08:58:30 +01:00
renovate[bot]
d018cccc70
fix(deps): update module github.com/rs/zerolog to v1.32.0 (#52)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-02-05 08:45:37 +01:00
renovate[bot]
fc4c4779c1 chore(docker): update golang:1.21 docker digest to 7b575fe 2024-02-03 06:14:07 +00:00
renovate[bot]
bda10c1383 chore(docker): update alpine:3.19 docker digest to c5b1261 2024-01-28 15:57:51 +00:00
renovate[bot]
095dfef577 chore(docker): update golang:1.21 docker digest to 76aadd9 2024-01-25 10:27:20 +00:00
renovate[bot]
6098f3305f
chore(deps): update quay.io/thegeeklab/wp-docker-buildx docker tag to v3 (#48)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-01-22 11:28:47 +01:00
renovate[bot]
656110b555 chore(docker): update golang:1.21 docker digest to 5f5d61d 2024-01-17 12:12:00 +00:00
renovate[bot]
79e4eded25 chore(docker): update golang:1.21 docker digest to 6fbd2d3 2024-01-12 00:35:00 +00:00
renovate[bot]
ac6282868d chore(docker): update golang:1.21 docker digest to 21260a4 2024-01-11 15:24:12 +00:00
renovate[bot]
ed3f5c25c2 chore(docker): update golang:1.21 docker digest to ffbb0b8 2024-01-11 03:46:23 +00:00
renovate[bot]
5521c99d9f chore(docker): update golang:1.21 docker digest to 7026fb7 2024-01-10 03:38:46 +00:00
renovate[bot]
503327cbcc
fix(deps): update module github.com/urfave/cli/v2 to v2.27.1 (#42)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-01-01 16:21:56 +01:00
837ad200fb
use list style synatx and cleanup (#41) 2023-12-23 23:45:17 +01:00
dependabot[bot]
815bca2e1c
chore(deps): bump golang.org/x/crypto from 0.14.0 to 0.17.0 (#40)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-21 11:55:16 +01:00
renovate[bot]
e04f6654c2 chore(docker): update golang:1.21 docker digest to 672a228 2023-12-21 06:54:46 +00:00
renovate[bot]
6dae5b8ce9 chore(docker): update golang:1.21 docker digest to fb02af5 2023-12-20 19:57:00 +00:00
renovate[bot]
0b780a91aa chore(docker): update golang:1.21 docker digest to 1a9d253 2023-12-20 07:41:04 +00:00
renovate[bot]
186d3646e3 chore(docker): update golang:1.21 docker digest to b172263 2023-12-19 16:58:54 +00:00
d6a4e34bdb
ci: add missing test group 2023-12-15 22:34:49 +01:00
renovate[bot]
54fb966339 chore(docker): update golang:1.21 docker digest to 2ff79bc 2023-12-13 03:59:22 +00:00
renovate[bot]
bc3ec2bfe9 chore(docker): update golang:1.21 docker digest to ae34fbf 2023-12-09 09:31:53 +00:00
renovate[bot]
3750e21bb2
chore(deps): update alpine docker tag to v3.19 (#33)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-08 08:39:59 +01:00
renovate[bot]
37775efb47
chore(deps): update quay.io/thegeeklab/wp-docker-buildx docker tag to v2 (#32)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-07 08:40:04 +01:00
e268cd6e07
fix: replace logrus by zerolog (#31) 2023-12-06 09:29:44 +01:00
renovate[bot]
859e9a6b4c chore(docker): update golang:1.21 docker digest to 58e14a9 2023-12-06 01:40:02 +00:00
efe73d7bcc
ci: exclude dockerhub from linkcheck due to rate limiting 2023-12-05 11:24:35 +01:00
renovate[bot]
f4777100e8
fix(deps): update module github.com/urfave/cli/v2 to v2.26.0 (#29)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-04 09:00:27 +01:00
renovate[bot]
982c849297 chore(docker): update alpine:3.18 docker digest to 34871e7 2023-12-01 07:20:48 +00:00
renovate[bot]
d27fac0770 chore(docker): update golang:1.21 docker digest to 9baee0e 2023-11-22 21:42:25 +00:00
renovate[bot]
1d173506de chore(docker): update golang:1.21 docker digest to daa9d10 2023-11-22 13:33:31 +00:00
renovate[bot]
843002e96e chore(docker): update golang:1.21 docker digest to 4521f9d 2023-11-22 06:13:44 +00:00
renovate[bot]
b33c37bc77 chore(docker): update golang:1.21 docker digest to 57bf74a 2023-11-16 09:47:42 +00:00
a747bdbf8c
remove deprecated go version from golangci config 2023-11-08 09:25:31 +01:00
renovate[bot]
7266817b9b chore(docker): update golang:1.21 docker digest to 81cd210 2023-11-08 00:38:12 +00:00
renovate[bot]
f059134af5 chore(deps): update dependency golangci/golangci-lint to v1.55.2 2023-11-06 03:57:24 +00:00
renovate[bot]
d22e7f056c
chore(docker): update golang:1.21 docker digest to b113af1 (#21)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-11-04 22:38:30 +01:00
renovate[bot]
b0338bd725 chore(docker): update golang:1.21 docker digest to 5206873 2023-11-02 07:01:49 +00:00
renovate[bot]
05f448f9d3 chore(docker): update golang:1.21 docker digest to 84e41b3 2023-11-02 00:50:50 +00:00
renovate[bot]
0fba70f052 chore(deps): update dependency golangci/golangci-lint to v1.55.1 2023-10-30 04:48:02 +00:00
24ca46653d
fix: use description for breaking changes if no message in footer (#16) 2023-10-28 22:25:07 +02:00
42297c3db4
ci: use gotestsum for better test output (#17) 2023-10-28 22:01:18 +02:00
renovate[bot]
d64335e73a chore(deps): update dependency golangci/golangci-lint to v1.55.0 2023-10-23 03:02:08 +00:00
a2f25f042e
feat: add flag to create local tag only (#14) 2023-10-18 16:09:13 +02:00
aafeb36d4a
feat: add flag to control tag annotation (#13) 2023-10-18 15:51:05 +02:00
53af856cc5
fix: ensure logger is configured before first usage (#12) 2023-10-17 15:23:29 +02:00
66b6f803b8
fix: skip tag and next-version if unchanged (#11) 2023-10-17 15:23:00 +02:00
b9493c1610
chore: cleanup docs and remove unused config deprecation (#10) 2023-10-17 14:40:46 +02:00
31 changed files with 198 additions and 235 deletions

View File

@ -13,3 +13,5 @@ ReleaseNoteSection
Beatriz
Vieira
sv4git
multiarch
(P|p)rebuilt

View File

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

View File

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

@ -0,0 +1 @@
https://hub.docker.com/r/thegeeklab/*

View File

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

View File

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

View File

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

View File

@ -8,7 +8,7 @@ when:
runs_on: [success, failure]
steps:
matrix:
- name: matrix
image: quay.io/thegeeklab/wp-matrix
settings:
homeserver:

View File

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

View File

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

View File

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

View File

@ -7,42 +7,33 @@ Semantic versioning tool for git based on conventional commits.
[![GitHub contributors](https://img.shields.io/github/contributors/thegeeklab/git-sv)](https://github.com/thegeeklab/git-sv/graphs/contributors)
[![License: MIT](https://img.shields.io/github/license/thegeeklab/git-sv)](https://github.com/thegeeklab/git-sv/blob/main/LICENSE)
## Getting Started
### Requirements
## Requirements
- Git 2.17+
### Installing
## Installation
- Download the latest release and add the binary to your path.
- Optional: Set `GITSV_HOME` to define user configurations. Check the [Configuration](#configuration) topic for more information.
If you want to install from source using `go install`, just run:
Prebuilt multiarch binaries are available for Linux only.
```Shell
# keep in mind that with this, it will compile from source and won't show the version on cli -h.
go install github.com/thegeeklab/git-sv/cmd/git-sv@latest
# if you want to add the version on the binary, run this command instead.
GITSV_VERSION=$(go list -f '{{ .Version }}' -m github.com/thegeeklab/git-sv@latest | sed 's/v//') && go install --ldflags "-X main.Version=$SGITSV_VERSION" github.com/thegeeklab/git-sv/cmd/git-sv@v$GITSV_VERSION
curl -SsfL https://github.com/thegeeklab/git-sv/releases/latest/download/git-sv-linux-amd64 -o /usr/local/bin/git-sv
chmod +x /usr/local/bin/git-sv
```
### Configuration
## Build
#### YAML
There are 3 configuration levels when using git-sv: [default](#default), [repository](#repository). All of them are merged considering the follow priority: **repository > user > default**.
To see the current configuration, run:
Build the binary from source with the following command:
```Shell
git sv cfg show
make build
```
##### Configuration Types
## Configuration
###### Default
The configuration is loaded from a YAML file in the following order (last wins):
- built-in default
- `.gitsv/config.yml` in repository root
To check the default configuration, run:
@ -50,37 +41,22 @@ To check the default configuration, run:
git sv cfg default
```
###### Repository
Create a `.gitsv/config.yml` file on the root of your repository, e.g. [.gitsv/config.yml](.gitsv/config.yml).
##### Configuration format
```Yaml
version: "1.1" #configuration version
version: "1.1" # Configuration version.
versioning: # versioning bump
versioning:
update-major: [] # Commit types used to bump major.
update-minor: [feat] # Commit types used to bump minor.
update-patch: [build, ci, chore, fix, perf, refactor, test] # Commit types used to bump patch.
# When type is not present on update rules and is unknown (not mapped on commit message types);
# if ignore-unknown=false bump patch, if ignore-unknown=true do not bump version
# if ignore-unknown=false bump patch, if ignore-unknown=true do not bump version.
ignore-unknown: false
tag:
pattern: "%d.%d.%d" # Pattern used to create git tag.
filter: "" # Enables you to filter for considerable tags using git pattern syntax
filter: "" # Enables you to filter for considerable tags using git pattern syntax.
release-notes:
# Deprecated!!! please use 'sections' instead!
# Headers names for release notes markdown. To disable a section just remove the header
# line. It's possible to add other commit types, the release note will be created
# respecting the following order: feat, fix, refactor, perf, test, build, ci, chore, docs, style, breaking-change.
headers:
breaking-change: Breaking Changes
feat: Features
fix: Bug Fixes
sections: # Array with each section of release note. Check template section for more information.
- name: Features # Name used on section.
section-type: commits # Type of the section, supported types: commits, breaking-changes.
@ -99,6 +75,7 @@ branches: # Git branches config.
skip-detached: false # Set true if a detached branch should be ignored on commit message validation.
commit-message:
# Supported commit types.
types: [
build,
ci,
@ -111,7 +88,7 @@ commit-message:
revert,
style,
test,
] # Supported commit types.
]
header-selector: "" # You can put in a regex here to select only a certain part of the commit message. Please define a regex group 'header'.
scope:
# Define supported scopes, if blank, scope will not be validated, if not, only scope listed will be valid.
@ -127,7 +104,7 @@ commit-message:
regex: "[A-Z]+-[0-9]+" # Regex for issue id.
```
#### Templates
### Templates
**git-sv** uses _go templates_ to format the output for `release-notes` and `changelog`, to see how the default template is configured check [template directory](https://github.com/thegeeklab/git-sv/tree/main/templates/assets). It's possible to overwrite the default configuration by adding `.gitsv/templates` on your repository.
@ -140,7 +117,7 @@ commit-message:
Everything inside `.gitsv/templates` will be loaded, so it's possible to add more files to be used as needed.
##### Variables
#### Variables
To execute the template the `releasenotes-md.tpl` will receive a single `ReleaseNote` and `changelog-md.tpl` will receive a list of `ReleaseNote` as variables.
@ -153,25 +130,7 @@ Each `ReleaseNoteSection` will be configured according with `release-notes.secti
> :warning: currently only `commits` and `breaking-changes` are supported as `section-types`, using a different value for this field will make the section to be removed from the template variables.
### Running
Run `git-sv` to get the list of available parameters:
```Shell
git-sv
```
#### Run as git command
If `git-sv` is configured on your path, you can use it like a git command:
```Shell
git sv
git sv current-version
git sv next-version
```
#### Usage
## Usage
Use `--help` or `-h` to get usage information, don't forget that some commands have unique options too:
@ -204,7 +163,15 @@ GLOBAL OPTIONS:
--version, -v print the version
```
##### Use range
If `git-sv` is configured on your path, you can also use it like a git command.
```Shell
git sv
git sv current-version
git sv next-version
```
### Ranges
Commands like `commit-log` and `commit-notes` has a range option. Supported range types are: `tag`, `date` and `hash`.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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"`
@ -74,10 +80,6 @@ func NewConfig(configDir, configFilename string) *Config {
if merr := merge(cfg, migrate(repoCfg, repoCfgFilepath)); merr != nil {
log.Fatal().Err(merr).Msg("failed to merge repo config")
}
if len(repoCfg.ReleaseNotes.Headers) > 0 { // mergo is merging maps, headers will be overwritten
cfg.ReleaseNotes.Headers = repoCfg.ReleaseNotes.Headers
}
}
return cfg
@ -143,14 +145,7 @@ func GetDefault() *Config {
}
func merge(dst *Config, src Config) error {
err := mergo.Merge(dst, src, mergo.WithOverride, mergo.WithTransformers(&mergeTransformer{}))
if err == nil {
if len(src.ReleaseNotes.Headers) > 0 { // mergo is merging maps, ReleaseNotes.Headers should be overwritten
dst.ReleaseNotes.Headers = src.ReleaseNotes.Headers
}
}
return err
return mergo.Merge(dst, src, mergo.WithOverride, mergo.WithTransformers(&mergeTransformer{}))
}
type mergeTransformer struct{}
@ -179,50 +174,7 @@ func (t *mergeTransformer) Transformer(typ reflect.Type) func(dst, src reflect.V
return nil
}
//nolint:revive
func migrate(cfg Config, filename string) Config {
if cfg.ReleaseNotes.Headers == nil {
return cfg
}
log.Warn().Msgf("config 'release-notes.headers' on %s is deprecated, please use 'sections' instead!", filename)
return Config{
Version: cfg.Version,
Versioning: cfg.Versioning,
Tag: cfg.Tag,
ReleaseNotes: sv.ReleaseNotesConfig{
Sections: migrateReleaseNotes(cfg.ReleaseNotes.Headers),
},
Branches: cfg.Branches,
CommitMessage: cfg.CommitMessage,
}
}
func migrateReleaseNotes(headers map[string]string) []sv.ReleaseNotesSectionConfig {
order := []string{"feat", "fix", "refactor", "perf", "test", "build", "ci", "chore", "docs", "style"}
var sections []sv.ReleaseNotesSectionConfig
for _, key := range order {
if name, exists := headers[key]; exists {
sections = append(
sections,
sv.ReleaseNotesSectionConfig{
Name: name,
SectionType: sv.ReleaseNotesSectionTypeCommits,
CommitTypes: []string{key},
})
}
}
if name, exists := headers["breaking-change"]; exists {
sections = append(
sections,
sv.ReleaseNotesSectionConfig{
Name: name,
SectionType: sv.ReleaseNotesSectionTypeBreakingChanges,
})
}
return sections
return cfg
}

View File

@ -117,13 +117,6 @@ func Test_merge(t *testing.T) {
}},
false,
},
{
"overwrite release notes header",
Config{ReleaseNotes: sv.ReleaseNotesConfig{Headers: map[string]string{"a": "aa"}}},
Config{ReleaseNotes: sv.ReleaseNotesConfig{Headers: map[string]string{"b": "bb"}}},
Config{ReleaseNotes: sv.ReleaseNotesConfig{Headers: map[string]string{"b": "bb"}}},
false,
},
{
"overwrite tag config",
Config{
@ -155,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)
}

View File

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

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

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,7 +8,6 @@ import (
// ReleaseNotesConfig release notes preferences.
type ReleaseNotesConfig struct {
Headers map[string]string `yaml:"headers,omitempty"`
Sections []ReleaseNotesSectionConfig `yaml:"sections"`
}
@ -78,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())
}
}