Compare commits

...

82 Commits

Author SHA1 Message Date
dependabot[bot]
3131b8b0ee build(deps): bump github.com/cloudflare/circl from 1.3.2 to 1.3.3
Bumps [github.com/cloudflare/circl](https://github.com/cloudflare/circl) from 1.3.2 to 1.3.3.
- [Release notes](https://github.com/cloudflare/circl/releases)
- [Commits](https://github.com/cloudflare/circl/compare/v1.3.2...v1.3.3)

---
updated-dependencies:
- dependency-name: github.com/cloudflare/circl
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-11 20:45:08 +00:00
Sebastian
ade0e49736 fix(*): update all dependencies to fix security findings 2023-02-20 16:33:55 +01:00
Sebastian Beisch
ca6488ee78 fix(go): update to go 1.19 as default build 2023-02-20 16:28:56 +01:00
Sebastian Beisch
979a378abd fix(*): update all dependencies to fix security findings 2023-02-20 16:07:07 +01:00
Sebastian
2c8d2d9ade style(changelog): simplify string sort 2022-04-11 21:56:56 +02:00
Sebastian
8acb8b74b8 refactor(changelog): sort authors 2022-04-11 21:56:56 +02:00
Sebastian
fd1063132f refactor(changelog): clean up author map 2022-04-11 21:56:56 +02:00
Sebastian Beisch
1d0c93b678 test(analyzer): fix test 2022-04-11 21:56:56 +02:00
Sebastian Beisch
0c7338ab13 feat(changelog): show authors of commits and show body as header
Enable new features in `.release.yml` like

```yml

changelog:
  showAuthors: false  ## Show authors in changelog
  showBodyAsHeader: false  ## Show all bodies of the commits as header of changelog (useful for squash commit flow to show long text in release)

```
2022-04-11 21:56:56 +02:00
Sebastian Beisch
03f2eeadaa fix(analyzer): fix commit message body parser
In special cases the body of a commit was not correctly interpreted and the changelog was displayed wrongly.
2022-04-11 21:56:56 +02:00
Sebastian
bcb21d917d chore(codeql): enable code scan 2022-04-11 13:38:30 +02:00
Sebastian Beisch
ea2fbfba3d chore(ci): add go 1.17 2022-03-04 13:54:47 +01:00
Sebastian Beisch
c5f993e7de fix(#62): show message block with right indent 2022-03-04 13:54:47 +01:00
Ferenc
ec8dc17df2 docs(examples/github-actions.yml): add github actions example 2021-08-20 08:39:19 +02:00
Sebastian
9e40e81fea Merge pull request #75 from Nightapes/doc/gitlab 2021-08-11 19:16:52 +02:00
Felix Wiedmann
2782fb5d03 docs(gitlab): add missing entrypoint overwrite 2021-08-11 19:00:47 +02:00
Felix Wiedmann
0800219d60 Merge branch 'master' of github.com:Nightapes/go-semantic-release 2021-08-11 16:08:57 +02:00
Sebastian
f89150b698 fix(Dockerfile): move binary in /usr/local/bin to call go-semantic-releaser via $PATH in terminal directly and update alpine 2021-08-10 21:05:52 +02:00
Felix Wiedmann
780a6dbc2e docs(gitlab): add example gitlab-ci.yml 2021-08-10 18:34:16 +02:00
Felix Wiedmann
2d7977993b build(Dockerfile): move binary in /usr/local/bin to call go-semantic-releaservia $PATH in terminal directly 2021-08-10 18:34:16 +02:00
Felix Wiedmann
9d7edbf756 docs(gitlab): add example gitlab-ci.yml 2021-08-10 16:28:47 +02:00
Felix Wiedmann
d9e2f36927 build(Dockerfile): move binary in /usr/local/bin to call go-semantic-releaservia $PATH in terminal directly 2021-08-10 16:21:42 +02:00
Sebastian
a6783f23bd Merge pull request #67 from Nightapes/feat/changelog 2021-05-08 23:52:26 +02:00
Felix Wiedmann
fbb3684f68 docs(readme): add Write changelog to file section 2021-05-08 23:39:52 +02:00
Felix Wiedmann
9bc3143f53 ref(changelog): add unit description of max-file-size 2021-05-08 23:23:43 +02:00
Felix Wiedmann
7b93801e88 test(semantic-release): add tests for WriteChangelog 2021-05-08 22:23:03 +02:00
Felix Wiedmann
749bbf720b chore(changelog): fix calculation of file name 2021-05-08 22:23:03 +02:00
Felix Wiedmann
d9e5dc4515 chore(cmd): pass max file size of changelog via options 2021-05-08 22:23:03 +02:00
Felix Wiedmann
d66364e474 ref(changelog): check for max changelog file size, generate new change log file if exceeded.feat/changelog
still in WIO
2021-05-08 22:23:03 +02:00
Felix Wiedmann
2fc6145149 ci(go): remove go 1.15 in matrix build 2021-05-08 22:23:03 +02:00
fwiedmann
a054cf9a60 feat(changelog): prepend a changelog to a file as default, use --overwrite to overwrite the whole file
BREAKING CHANGE: changelog command will now prepend changelogs to the changelog-file
2021-05-08 22:23:03 +02:00
fwiedmann
155a16ddd5 ci(build): set upload artifact go version to 1.16,
remove version 1.13, 1.14
2021-05-08 22:21:43 +02:00
fwiedmann
d7878222bb build(go): set module version to go 1.16 2021-05-08 22:21:43 +02:00
Sebastian Beisch
f79466b238 fix(gitutil): don't crash if no last version was found 2021-05-06 19:07:07 +02:00
Sebastian Beisch
5225b12c00 style(internal) clean up code 2021-04-28 08:43:10 +02:00
Sebastian Beisch
2cd24777b3 fix(internal): improve git log for commits on current branch since last release
At the moment when PRs where done in parallel it could happen that some commits where ignored in the release. This should be fixed now
2021-04-28 08:43:10 +02:00
Naven Gogineni
cb3084d0b7 docs(github): fix typo in comment 2021-03-10 09:09:07 +01:00
Naveen Gogineni
795f5d54ef fix(github): fix baseURL for enterprise and test failures 2021-03-10 09:09:07 +01:00
Naveen Gogineni
382cb54bcb Add correct URLs for base and upload URLs for enterprise 2021-03-08 19:29:13 +01:00
Sebastian Beisch
3bc68d9794 feat(changelog): add npm helper text to changelog 2021-02-25 07:19:04 +01:00
Sebastian Beisch
c7d6c7cc7b feat(integrations): add first simple npm integration
Integrations are simple helpers to make integration with existing tools easier.
At basic npm support, the integration will set the version before release to the `package.json`

```yml
integrations:
  npm:
    enabled: true
```
2021-02-25 07:19:04 +01:00
maulik13
47a54436f5 feat(changelog): add a function in the funcMap to return commit URL 2021-02-23 14:25:09 +01:00
maulik13
deed3a630e docs(README): update available fields/objects for a changelog template 2021-02-23 14:25:09 +01:00
maulik13
df058a927f refactor(changelog): remove unused Version and Now fields, fixed spelling 2021-02-23 14:25:09 +01:00
maulik13
5a58d039fb refactor(angular): update default separator variable in angular 2021-02-23 14:25:09 +01:00
maulik13
08ab3af547 fix(analyzer): remove extra quote in structtag 2021-02-23 14:25:09 +01:00
maulik13
7208daed1f feat(angular): update angular to include new structured fields 2021-02-23 14:25:09 +01:00
maulik13
a20992af14 feat(conventional): parse body and footers according to the rules
Previous assumption about multiple labeled body blocks and footers is
not correct. There is only one body text block with multi-line support.
A footer always starts with a token with a separator.
- A body ends when a footer is found or text ends.
- A footer ends when another footer is found or text ends.
2021-02-23 14:25:09 +01:00
maulik13
dc4d1c581a feat(analyzer): update AnalyzedCommit to add flexibility in parsing a message
This provides flexibility of parsing and rendering structured messages
with more detail in the changelog and helps extract metadata from the 
message. The new structure can be used to split a message in multiple 
blocks (e.g. footer)
2021-02-23 14:25:09 +01:00
Sebastian
81bdb68ee4 Merge pull request #58 from maulik13/changelog-full-template
Changelog full template
2021-02-12 17:23:32 +01:00
maulik13
c485c3ee85 docs(changelog): update changelog template example 2021-02-12 13:55:08 +01:00
Sebastian
86c9512479 Update main.yml 2021-02-11 19:36:20 +01:00
Sebastian
4574d00c28 chore(ci): add pull request 2021-02-11 19:36:20 +01:00
Sebastian
0c4310d60b chore(ci): check if pr is fork 2021-02-11 19:36:20 +01:00
maulik13
3a37a5e1db feat(changelog): add string functions for changelog template 2021-02-08 11:30:06 +01:00
maulik13
9594f39caa feat(changelog): allow using of TemplatePath file for full changelog text 2021-02-08 11:15:27 +01:00
Felix Wiedmann
b9cbbd435f feat(analyzer): add conventional commit format 2021-01-24 00:22:42 +01:00
Felix Wiedmann
564c033cbb Merge pull request #51 from Nightapes/feat/conventional-commits
feat(analyzer): add conventional commit format
2021-01-23 23:17:13 +01:00
Felix Wiedmann
3deead130c Merge pull request #53 from Nightapes/ref/feat-conv-commits
ref(analyzer): simplified analyze method for angular and conventional
2021-01-23 23:11:37 +01:00
Felix Wiedmann
ac1bb779bb lint(semanticrelease): update file permissions 2021-01-23 22:53:55 +01:00
fwiedmann
6cd43d7957 ref(analyzer): simplified analyze method for angular and conventional 2021-01-23 22:49:42 +01:00
Sebastian
450383bdbf Merge branch 'master' into feat/conventional-commits 2021-01-21 22:43:53 +01:00
Sebastian
d6c5e395a8 chore(lint): fix lint version 2021-01-21 22:40:07 +01:00
Felix Wiedmann
3731fa6e55 Merge pull request #50 from maulik13/custom-tag-prefix 2021-01-21 21:54:21 +01:00
Sebastian Beisch
8db8b0d72c feat(analyzer): add conventional commit format
See: [conventional](https://www.conventionalcommits.org/en/v1.0.0/#summaryhttps://www.conventionalcommits.org/en/v1.0.0/#summary)
2021-01-21 21:41:14 +01:00
maulik13
15a17e546b docs: update the readme file to include the tagPrefix parameter 2021-01-21 21:39:52 +01:00
maulik13
037983df1e feat(release): add an option to specify a custom prefix for the version tag 2021-01-21 17:52:08 +01:00
Felix Wiedmann
01af837b40 Merge pull request #46 from Nightapes/fix/commits
refactor(internal/git): revert list commits changes
2020-11-11 16:01:03 +01:00
Sebastian Beisch
0f1275fc30 refactor(internal/git): revert list commits changes 2020-11-11 10:53:10 +01:00
Felix Wiedmann
115bc85d8d Merge pull request #45 from Nightapes/fix/merge-commits
Fix/merge commits
2020-11-10 12:59:36 +01:00
Sebastian Beisch
dee85c6877 fix(internal/git): check merge commits and collect parent commits for changelog 2020-11-09 14:43:01 +01:00
Sebastian Beisch
ccfce5e135 chore(git): update to new git version go-git.v5 2020-11-09 14:40:38 +01:00
Sebastian
8ffc0804ec Merge pull request #44 from Nightapes/fix/hooks
feat(hooks): pass environment variables to hooks
2020-08-18 19:02:16 +02:00
Sebastian Beisch
348ea6607e chore(*): update dependencies 2020-08-18 17:43:39 +02:00
Sebastian Beisch
00cbfd39a2 chore(go): switch to golang 1.15 2020-08-18 17:38:28 +02:00
Sebastian Beisch
0cbc7a7885 feat(hooks): pass environment variables to hooks 2020-08-18 17:33:53 +02:00
Sebastian
1bc0185f70 Merge pull request #43 from zeroshade/breaking
fix(internal/angular): fix angular parsing of breaking change messages that have multiple lines
2020-07-28 21:13:58 +02:00
Matthew Topol
f0ebb03e46 fix(internal/angular): fix angular parsing of breaking change messages that have multiple lines 2020-07-27 16:42:15 -04:00
Sebastian
cc22d5d4db Merge pull request #42 from Nightapes/fix/asset
fix(internal/assets): close zip writer before closing zip file
2020-05-21 11:06:24 +02:00
fwiedmann
c84b51d18c fix(internal/assets): close zip writer before closing zip file 2020-05-21 00:45:59 +02:00
Felix Wiedmann
11acc95a34 Merge pull request #41 from Nightapes/fix.assets
fix(assets): when file is zipped, upload zipped file instead of unzipped file
2020-03-25 09:01:03 +01:00
Sebastian Beisch
be35b743b4 fix(assets): when file is zipped, upload zipped file instead of unzipped file 2020-03-25 08:45:27 +01:00
49 changed files with 2613 additions and 597 deletions

70
.github/workflows/codeql-analysis.yml vendored Normal file
View File

@@ -0,0 +1,70 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"
on:
push:
branches: [ master ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ master ]
schedule:
- cron: '21 16 * * 5'
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'go' ]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Learn more about CodeQL language support at https://git.io/codeql-language-support
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
#- run: |
# make bootstrap
# make release
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2

View File

@@ -1,14 +1,20 @@
name: Go name: Go
on: [push, pull_request] on:
pull_request:
push:
branches:
- master
jobs: jobs:
build: build:
strategy: strategy:
matrix: matrix:
go: ["1.13", "1.14"] go: ["1.18", "1.19"]
env:
DEFAULT_GO: "1.19"
name: Build with go version ${{ matrix.go }} name: Build with go version ${{ matrix.go }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Set up Go 1.14 - name: Set up GoLang ${{ matrix.go }}
uses: actions/setup-go@v1 uses: actions/setup-go@v1
with: with:
go-version: ${{ matrix.go }} go-version: ${{ matrix.go }}
@@ -17,11 +23,10 @@ jobs:
- name: Check out code into the Go module directory - name: Check out code into the Go module directory
uses: actions/checkout@v1 uses: actions/checkout@v1
- name: Lint - name: golangci-lint
run: | uses: golangci/golangci-lint-action@v3
export PATH=$PATH:$(go env GOPATH)/bin with:
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.18.0 version: latest
golangci-lint run ./...
- name: Run tests - name: Run tests
run: go test ./... run: go test ./...
@@ -36,8 +41,12 @@ jobs:
GOOS=windows GOARCH=386 CGO_ENABLED=0 go build -o build/go-semantic-release.windows_i386.exe -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/ GOOS=windows GOARCH=386 CGO_ENABLED=0 go build -o build/go-semantic-release.windows_i386.exe -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o build/go-semantic-release.windows_x86_64.exe -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/ GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o build/go-semantic-release.windows_x86_64.exe -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -o build/go-semantic-release.darwin_x86_64 -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/ GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -o build/go-semantic-release.darwin_x86_64 -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
- name: Build Docker image - name: Build Docker image PR
if: matrix.go == '1.14' if: github.ref != 'refs/heads/master'
run: |
docker build -t nightapes/go-semantic-release:development-${{matrix.go}} .
- name: Build Docker image master
if: github.ref == 'refs/heads/master'
run: | run: |
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }} docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
docker login -u nightapes -p ${{ secrets.GITHUB_TOKEN }} docker.pkg.github.com docker login -u nightapes -p ${{ secrets.GITHUB_TOKEN }} docker.pkg.github.com
@@ -46,7 +55,7 @@ jobs:
docker tag nightapes/go-semantic-release:development-${{matrix.go}} docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:development-${{matrix.go}} docker tag nightapes/go-semantic-release:development-${{matrix.go}} docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:development-${{matrix.go}}
docker push docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:development-${{matrix.go}} docker push docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:development-${{matrix.go}}
- uses: actions/upload-artifact@v1 - uses: actions/upload-artifact@v1
if: matrix.go == '1.14' if: matrix.go == env.DEFAULT_GO
with: with:
name: build name: build
path: build path: build
@@ -62,6 +71,7 @@ jobs:
name: build name: build
path: build path: build
- name: Release - name: Release
if: github.ref == 'refs/heads/master'
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
@@ -69,3 +79,10 @@ jobs:
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }} docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
docker login -u nightapes -p $GITHUB_TOKEN docker.pkg.github.com docker login -u nightapes -p $GITHUB_TOKEN docker.pkg.github.com
./build/go-semantic-release-temp release --loglevel trace ./build/go-semantic-release-temp release --loglevel trace
- name: Release PR
if: github.ref != 'refs/heads/master'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
chmod -R +x build
./build/go-semantic-release-temp release --loglevel trace

View File

@@ -19,6 +19,8 @@ changelog:
docker: docker:
latest: true latest: true
repository: "nightapes/go-semantic-release" repository: "nightapes/go-semantic-release"
showAuthors: true
hooks: hooks:
preRelease: preRelease:
- docker build -t nightapes/go-semantic-release:latest . - docker build -t nightapes/go-semantic-release:latest .

View File

@@ -1,9 +1,9 @@
FROM alpine:3.10.2 FROM alpine:3.14
WORKDIR /code WORKDIR /code
COPY ./build/go-semantic-release.linux_x86_64 . COPY ./build/go-semantic-release.linux_x86_64 /usr/local/bin/go-semantic-release
USER 1000 USER 1000
ENTRYPOINT [ "./go-semantic-release.linux_x86_64" ] ENTRYPOINT [ "go-semantic-release" ]

14
Makefile Normal file
View File

@@ -0,0 +1,14 @@
all: build
.PHONY: build
build:
go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/
lint:
golangci-lint run --print-issued-lines=false --fix ./...
test:
go test --coverprofile coverage.out -v -parallel 20 ./...

147
README.md
View File

@@ -4,7 +4,7 @@
## Release Types ## Release Types
| Type | Implemendet | Git tag | Changelog | Release | Write access git | Api token | | Type | Implemented | Git tag | Changelog | Release | Write access git | Api token |
| ----------- | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | | ----------- | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: |
| `github` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: | | `github` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: |
| `gitlab` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: | | `gitlab` | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | | :white_check_mark: |
@@ -56,15 +56,26 @@ hooks:
- name: echo $RELEASE_VERSION - name: echo $RELEASE_VERSION
postRelease: postRelease:
- name: echo $RELEASE_VERSION - name: echo $RELEASE_VERSION
integrations:
npm:
enabled: true
``` ```
#### CommitFormat #### CommitFormat
Set the commit format, at the moment we support ony [angular](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit-message-format), more coming soon. Supported formats:
```yml * [angular](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit-message-format)
commitFormat: angular
``` ```yml
commitFormat: angular
```
* [conventional](https://www.conventionalcommits.org/en/v1.0.0/#summaryhttps://www.conventionalcommits.org/en/v1.0.0/#summary)
```yml
commitFormat: conventional
```
#### Branch #### Branch
@@ -97,23 +108,28 @@ release: 'github'
github: github:
user: "<user/group" user: "<user/group"
repo: "<repositroyname>" repo: "<repositroyname>"
## Optional, if your not using github.com ## Optional, if you are not using github.com
customUrl: <https://your.github> customUrl: <https://your.github>
## Optional, if you want to change the default tag prefix ("v")
tagPrefix: ""
``` ```
##### Gitlab ##### Gitlab
You need to set the env `GITLAB_ACCESS_TOKEN` with an personal access token. You need to set the env `GITLAB_ACCESS_TOKEN` with an personal access token.
```yml ```yml
release: 'gitlab' release: 'gitlab'
gitlab: gitlab:
repo: "<repositroyname>" ## Example group/project repo: "<repositroyname>" ## Example group/project
## Optional, if your not using gitlab.com ## Optional, if your not using gitlab.com
customUrl: <https://your.gitlab> customUrl: <https://your.gitlab>
## Optional, if you want to change the default tag prefix ("v")
tagPrefix: ""
``` ```
You can find an example `.gitlab-ci.yml` in the [examples](examples/.gitlab-ci.yml) folder.
##### Git only ##### Git only
Only via https at the moment. You need write access to your git repository Only via https at the moment. You need write access to your git repository
@@ -125,6 +141,8 @@ git:
email: "<email>" # Used for creating tag email: "<email>" # Used for creating tag
user: "<user>" : # Used for creating tag and pushing user: "<user>" : # Used for creating tag and pushing
auth: "<token>" # Used for pushing, can be env "$GIT_TOKEN", will be replaced with env auth: "<token>" # Used for pushing, can be env "$GIT_TOKEN", will be replaced with env
## Optional, if you want to change the default tag prefix ("v")
tagPrefix: ""
``` ```
@@ -144,23 +162,90 @@ assets:
#### Hooks #### Hooks
Hooks will run when calling `release`. Hooks run only if a release will be triggered. Hooks will run when calling `release`. Hooks run only if a release will be triggered.
You can define hooks which run before or after the release. The shell commands will run in order, you can access the current release version via
an environment variable `RELEASE_VERSION`
```yml
hooks:
preRelease:
- name: echo $RELEASE_VERSION
postRelease:
- name: echo $RELEASE_VERSION
```
#### Integrations
Integrations are simple helpers to make integration with existing tools easier.
At the moment npm is supported, the integration will set the version before release to the `package.json`
```yml
integrations:
npm:
enabled: true
```
#### Changelog #### Changelog
Following variables can be used for templates: Following variables and objects can be used for templates:
* `Commits` string
* `Version` string __Top level__
* `Now` time.Time
* `Backtick` string | Field | Type | Description |
* `HasDocker` bool | -------- | ------ | ----- |
* `HasDockerLatest` bool | `Commits` | string | Fully rendered commit messages. This is left for backward compatibility. |
* `DockerRepository` string | `CommitsContent` | commitsContent | Raw parsed commit data. Use this if you want to customize the output. |
| `Version` | string | Next release version |
| `Now` | time.Time | Current time of generating changelog |
| `Backtick` | string | Backtick character |
| `HasDocker` | bool | If a docker repository is set in the config. |
| `HasDockerLatest` | bool | If `latest` image was uploaded |
| `DockerRepository` | string | Docker repository |
__commitsContent__
| Field | Type | Description |
| -------- | ------ | ----- |
| `Commits` | map[string][]AnalyzedCommit | Commits grouped by commit type |
| `BreakingChanges` | []AnalyzedCommit | Analyzed commit structure |
| `Order` | []string | Ordered list of types |
| `HasURL` | bool | If a URL is available for commits |
| `URL` | string | URL for to the commit with {{hash}} suffix |
__AnalyzedCommit__
| Field | Type | Description |
| -------- | ------ | ----- |
| `Commit` | Commit | Original GIT commit |
| `Tag` | string | Type of commit (e.g. feat, fix, ...) |
| `TagString` | string | Full name of the type |
| `Scope` | bool | Scope value from the commit |
| `Subject` | string | URL for to the commit with {{hash}} suffix |
| `MessageBlocks` | map[string][]MessageBlock | Different sections of a message (e.g. body, footer etc.) |
| `IsBreaking` | bool | If this commit contains a breaking change |
| `Print` | bool | Should this commit be included in Changelog output |
__Commit__
| Field | Type | Description |
| -------- | ------ | ----- |
| `Message` | string | Original git commit message |
| `Author` | string | Name of the author |
| `Hash` | string | Commit hash value "|
__MessageBlock__
| Field | Type | Description |
| -------- | ------ | ----- |
| `Label` | string | Label for a block (optional). This will usually be a token used in a footer |
| `Content` | string | The parsed content of a block |
```yml ```yml
changelog: changelog:
printAll: false ## Print all valid commits to changelog printAll: false ## Print all valid commits to changelog
title: "v{{.Version}} ({{.Now.Format "2006-01-02"}})" ## Used for releases (go template) title: "v{{.Version}} ({{.Now.Format "2006-01-02"}})" ## Used for releases (go template)
templatePath: "./examples/changelog.tmpl" ## Path to a template file (go template) templatePath: "./examples/changelog.tmpl" ## Path to a template file (go template)
showAuthors: false ## Show authors in changelog
showBodyAsHeader: false ## Show all bodies of the commits as header of changelog (useful for squash commit flow to show long text in release)
``` ```
##### Docker ##### Docker
@@ -174,9 +259,21 @@ changelog:
repository: ## Your docker repository, which is used for docker run repository: ## Your docker repository, which is used for docker run
``` ```
##### NPM
You can print a help text for a npm package
```yml
changelog:
npm:
name: ## Name of the npm package
repository: ## Your docker repository, which is used for docker run
```
### Version ### Version
`go-semantic-release` has two modes for calcualting the version: automatic or manual. `go-semantic-release` has two modes for calculating the version: automatic or manual.
#### Automatic #### Automatic
@@ -211,6 +308,24 @@ go build -ldflags "--X main.version=`./go-semantic-release next`"
./go-semantic-release release ./go-semantic-release release
``` ```
### Write changelog to file
This will write all changes beginning from the last git tag til HEAD to a changelog file.
Default changelog file name if nothing is given via `--file`: `CHANGELOG.md`.
Note that per default the new changelog will be prepended to the existing file.
With `--max-file-size` a maximum sizes of the changelog file in megabytes can be specified.
If the size exceeds the limit, the current changelog file will be moved to a new file called `<filename>-<1-n>.<file extension>`. The new changelog will be written to the `<filename>`.
The default maximum file size limit is `10 megabytes`.
```bash
./go-semantic-release changelog --max-file-size 10
```
This will overwrite the given changelog file if its existing, if not it will be created.
```bash
./go-semantic-release changelog --overwrite
```
## Build from source ## Build from source

View File

@@ -7,7 +7,11 @@ import (
) )
func init() { func init() {
changelogCmd.Flags().Bool("checks", false, "Check for missing values and envs")
changelogCmd.Flags().Bool("overwrite", false, "Overwrite the content of the changelog. Default is to prepend the new changelog to the existing file.")
changelogCmd.Flags().StringP("out", "o", "CHANGELOG.md", "Name of the file") changelogCmd.Flags().StringP("out", "o", "CHANGELOG.md", "Name of the file")
changelogCmd.Flags().String("from", "", "Generate combined changelog from given version until latest version ")
changelogCmd.Flags().Int64("max-file-size", 10, "The max allowed file size in MB for a changelog file. If the file size is larger, the current file will be moved to a new file named <filename>-01.md. The next changelog will be written to de default file.")
rootCmd.AddCommand(changelogCmd) rootCmd.AddCommand(changelogCmd)
} }
@@ -30,17 +34,32 @@ var changelogCmd = &cobra.Command{
return err return err
} }
overwrite, err := cmd.Flags().GetBool("overwrite")
if err != nil {
return err
}
file, err := cmd.Flags().GetString("out") file, err := cmd.Flags().GetString("out")
if err != nil { if err != nil {
return err return err
} }
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks") configChecks, err := cmd.Flags().GetBool("checks")
if err != nil { if err != nil {
return err return err
} }
s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks) fromVersion, err := cmd.Flags().GetString("from")
if err != nil {
return err
}
maxFileSize, err := cmd.Flags().GetInt64("max-file-size")
if err != nil {
return err
}
s, err := semanticrelease.New(readConfig(config), repository, configChecks)
if err != nil { if err != nil {
return err return err
} }
@@ -50,7 +69,7 @@ var changelogCmd = &cobra.Command{
return err return err
} }
releaseVersion, err := s.GetNextVersion(provider, force) releaseVersion, err := s.GetNextVersion(provider, force, fromVersion)
if err != nil { if err != nil {
return err return err
} }
@@ -60,11 +79,6 @@ var changelogCmd = &cobra.Command{
if err != nil { if err != nil {
return err return err
} }
return s.WriteChangeLog(generatedChangelog.Content, file, overwrite, maxFileSize)
if err = s.WriteChangeLog(generatedChangelog.Content, file); err != nil {
log.Fatal(err)
}
return nil
}, },
} }

View File

@@ -7,6 +7,7 @@ import (
) )
func init() { func init() {
hooksCmd.Flags().Bool("checks", false, "Check for missing values and envs")
rootCmd.AddCommand(hooksCmd) rootCmd.AddCommand(hooksCmd)
} }
@@ -29,14 +30,14 @@ var hooksCmd = &cobra.Command{
return err return err
} }
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks") configChecks, err := cmd.Flags().GetBool("checks")
if err != nil { if err != nil {
return err return err
} }
releaseConfig := readConfig(config) releaseConfig := readConfig(config)
s, err := semanticrelease.New(releaseConfig, repository, !ignoreConfigChecks) s, err := semanticrelease.New(releaseConfig, repository, configChecks)
if err != nil { if err != nil {
return err return err
} }
@@ -47,7 +48,7 @@ var hooksCmd = &cobra.Command{
return err return err
} }
releaseVersion, err := s.GetNextVersion(provider, force) releaseVersion, err := s.GetNextVersion(provider, force, "")
if err != nil { if err != nil {
return err return err
} }

View File

@@ -0,0 +1,62 @@
package commands
import (
"github.com/Nightapes/go-semantic-release/internal/integrations"
"github.com/Nightapes/go-semantic-release/pkg/semanticrelease"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func init() {
integrationsCmd.Flags().Bool("checks", false, "Check for missing values and envs")
integrationsCmd.Flags().StringP("out", "o", "CHANGELOG.md", "Name of the file")
rootCmd.AddCommand(integrationsCmd)
}
var integrationsCmd = &cobra.Command{
Use: "integrations",
Short: "Call integrations from config file manual",
RunE: func(cmd *cobra.Command, args []string) error {
config, err := cmd.Flags().GetString("config")
if err != nil {
return err
}
repository, err := cmd.Flags().GetString("repository")
if err != nil {
return err
}
force, err := cmd.Flags().GetBool("no-cache")
if err != nil {
return err
}
configChecks, err := cmd.Flags().GetBool("checks")
if err != nil {
return err
}
releaseConfig := readConfig(config)
s, err := semanticrelease.New(releaseConfig, repository, configChecks)
if err != nil {
return err
}
provider, err := s.GetCIProvider()
if err != nil {
return err
}
releaseVersion, err := s.GetNextVersion(provider, force, "")
if err != nil {
return err
}
log.Debugf("Found %d commits till last release", len(releaseVersion.Commits))
i := integrations.New(&releaseConfig.Integrations, releaseVersion)
return i.Run()
},
}

View File

@@ -8,6 +8,7 @@ import (
) )
func init() { func init() {
lastCmd.Flags().Bool("checks", false, "Check for missing values and envs")
rootCmd.AddCommand(lastCmd) rootCmd.AddCommand(lastCmd)
} }
@@ -30,12 +31,12 @@ var lastCmd = &cobra.Command{
return err return err
} }
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks") configChecks, err := cmd.Flags().GetBool("checks")
if err != nil { if err != nil {
return err return err
} }
s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks) s, err := semanticrelease.New(readConfig(config), repository, configChecks)
if err != nil { if err != nil {
return err return err
} }
@@ -48,7 +49,7 @@ var lastCmd = &cobra.Command{
return nil return nil
} }
releaseVersion, err := s.GetNextVersion(provider, force) releaseVersion, err := s.GetNextVersion(provider, force, "")
if err != nil { if err != nil {
return err return err
} }

View File

@@ -8,6 +8,7 @@ import (
) )
func init() { func init() {
nextCmd.Flags().Bool("checks", false, "Check for missing values and envs")
rootCmd.AddCommand(nextCmd) rootCmd.AddCommand(nextCmd)
} }
@@ -30,12 +31,12 @@ var nextCmd = &cobra.Command{
return err return err
} }
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks") configChecks, err := cmd.Flags().GetBool("checks")
if err != nil { if err != nil {
return err return err
} }
s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks) s, err := semanticrelease.New(readConfig(config), repository, configChecks)
if err != nil { if err != nil {
return err return err
} }
@@ -48,7 +49,7 @@ var nextCmd = &cobra.Command{
return nil return nil
} }
releaseVersion, err := s.GetNextVersion(provider, force) releaseVersion, err := s.GetNextVersion(provider, force, "")
if err != nil { if err != nil {
return err return err
} }

View File

@@ -6,6 +6,7 @@ import (
) )
func init() { func init() {
releaseCmd.Flags().Bool("no-checks", false, "Ignore missing values and envs")
rootCmd.AddCommand(releaseCmd) rootCmd.AddCommand(releaseCmd)
} }

View File

@@ -35,7 +35,6 @@ func init() {
rootCmd.PersistentFlags().StringP("loglevel", "l", "error", "Set loglevel") rootCmd.PersistentFlags().StringP("loglevel", "l", "error", "Set loglevel")
rootCmd.PersistentFlags().StringP("config", "c", ".release.yml", "Path to config file") rootCmd.PersistentFlags().StringP("config", "c", ".release.yml", "Path to config file")
rootCmd.PersistentFlags().Bool("no-cache", false, "Ignore cache, don't use in ci build") rootCmd.PersistentFlags().Bool("no-cache", false, "Ignore cache, don't use in ci build")
rootCmd.PersistentFlags().Bool("no-checks", false, "Ignore missing values and envs")
} }
func readConfig(file string) *config.ReleaseConfig { func readConfig(file string) *config.ReleaseConfig {

View File

@@ -7,6 +7,7 @@ import (
) )
func init() { func init() {
setCmd.Flags().Bool("checks", false, "Check for missing values and envs")
rootCmd.AddCommand(setCmd) rootCmd.AddCommand(setCmd)
} }
@@ -26,12 +27,12 @@ var setCmd = &cobra.Command{
return err return err
} }
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks") configChecks, err := cmd.Flags().GetBool("checks")
if err != nil { if err != nil {
return err return err
} }
s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks) s, err := semanticrelease.New(readConfig(config), repository, configChecks)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -6,6 +6,7 @@ import (
) )
func init() { func init() {
zipCmd.Flags().Bool("checks", false, "Check for missing values and envs")
zipCmd.Flags().StringP("algorithm", "a", "sha256", "Algorithm for checksum (crc32,md5,sha1,sha224,sha384,sha256,sha512)") zipCmd.Flags().StringP("algorithm", "a", "sha256", "Algorithm for checksum (crc32,md5,sha1,sha224,sha384,sha256,sha512)")
rootCmd.AddCommand(zipCmd) rootCmd.AddCommand(zipCmd)
} }
@@ -24,12 +25,12 @@ var zipCmd = &cobra.Command{
return err return err
} }
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks") configChecks, err := cmd.Flags().GetBool("checks")
if err != nil { if err != nil {
return err return err
} }
s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks) s, err := semanticrelease.New(readConfig(config), repository, configChecks)
if err != nil { if err != nil {
return err return err
} }

12
examples/.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,12 @@
stages:
- release
release:
stage: release
image:
name: nightapes/go-semantic-release:latest
entrypoint: [""]
script:
- go-semantic-release next
only:
- master

View File

@@ -1,5 +1,26 @@
{{ define "commitList" }}
{{ range $index,$commit := .BreakingChanges -}}
{{ if eq $index 0 -}}
## BREAKING CHANGES
{{ end -}}
* {{ if $commit.Scope }}**{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}**{{ end }} {{$commit.ParsedBreakingChangeMessage}}
introduced by commit:
{{$commit.ParsedMessage}} {{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})){{end}}
{{ end -}}
{{ range $key := .Order -}}
{{ $commits := index $.Commits $key -}}
{{ if $commits -}}
### {{ $key }}
{{ range $index,$commit := $commits -}}
* {{ if $commit.Scope }}**{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}** {{end}}{{$commit.ParsedMessage}}{{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})){{end}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
# My custom release template v{{$.Version}} ({{.Now.Format "2006-01-02"}}) # My custom release template v{{$.Version}} ({{.Now.Format "2006-01-02"}})
{{ .Commits -}} {{ template "commitList" .CommitsContent -}}
{{ if .HasDocker}} {{ if .HasDocker}}
## Docker image ## Docker image

View File

@@ -0,0 +1,29 @@
name: Go
on: [ push, pull_request ]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v1
- name: Init go-semantic-release
run: |
wget https://github.com/Nightapes/go-semantic-release/releases/download/v2.0.1/go-semantic-release.linux_x86_64.zip
unzip go-semantic-release.linux_x86_64.zip
chmod +x go-semantic-release.linux_x86_64
- name: Build binary
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o <your-build-name>.linux_x86_64
GOOS=windows GOARCH=386 CGO_ENABLED=0 go build -o <your-build-name>.windows_i386.exe
GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o <your-build-name>.windows_x86_64.exe
GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go build -o <your-build-name>.darwin_x86_64
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./go-semantic-release.linux_x86_64 release --loglevel trace

59
go.mod
View File

@@ -1,24 +1,51 @@
module github.com/Nightapes/go-semantic-release module github.com/Nightapes/go-semantic-release
go 1.13 go 1.18
require ( require (
github.com/Masterminds/semver v1.5.0 github.com/Masterminds/semver v1.5.0
github.com/golang/protobuf v1.3.4 // indirect github.com/go-git/go-billy/v5 v5.4.1
github.com/go-git/go-git/v5 v5.5.2
github.com/google/go-github/v25 v25.1.3 github.com/google/go-github/v25 v25.1.3
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/sergi/go-diff v1.1.0 // indirect github.com/sirupsen/logrus v1.9.0
github.com/sirupsen/logrus v1.4.2 github.com/spf13/cobra v1.6.1
github.com/spf13/cobra v0.0.6 github.com/stretchr/testify v1.7.0
github.com/spf13/pflag v1.0.5 // indirect github.com/tidwall/sjson v1.2.5
github.com/stretchr/testify v1.4.0 golang.org/x/oauth2 v0.5.0
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d // indirect gopkg.in/yaml.v2 v2.4.0
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect )
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect require (
google.golang.org/appengine v1.6.5 github.com/Microsoft/go-winio v0.6.0 // indirect
gopkg.in/src-d/go-billy.v4 v4.3.2 github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
gopkg.in/src-d/go-git.v4 v4.13.1 github.com/acomagu/bufpipe v1.0.3 // indirect
gopkg.in/yaml.v2 v2.2.8 github.com/cloudflare/circl v1.3.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/pjbgf/sha1cd v0.2.3 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/skeema/knownhosts v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tidwall/gjson v1.14.4 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/tools v0.6.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
) )

332
go.sum
View File

@@ -1,227 +1,195 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs= github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs= github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/ProtonMail/go-crypto v0.0.0-20221026131551-cf6655e29de4/go.mod h1:UBYPn8k0D56RtnR8RFQMjmh4KrZzWJ5o7Z9SYjossQ8=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f h1:lBNOc5arjvs8E5mO2tbpBpLoyyu8B6e44T7hJy6potg=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/go-git/go-billy/v5 v5.4.0/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg=
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0= github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-git/go-billy/v5 v5.4.1/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-git/go-git-fixtures/v4 v4.3.1 h1:y5z6dd3qi8Hl+stezc8p3JxDkoTRqMAlKnXHuzrfjTQ=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-git/go-git-fixtures/v4 v4.3.1/go.mod h1:8LHG1a3SRW71ettAD/jW13h8c6AqjVSeL11RAdgaqpo=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-git/go-git/v5 v5.5.2 h1:v8lgZa5k9ylUw+OR/roJHTxR4QItsNFI5nKtAXFuynw=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-git/go-git/v5 v5.5.2/go.mod h1:BE5hUJ5yaV2YMxhmaP4l6RBQ08kMxKSPD4BlxtH7OjI=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.4 h1:87PNWwrRvUSnqS4dlcBU/ftvOIBep4sYuBLlh6rX2wk= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v25 v25.1.3 h1:Ht4YIQgUh4l4lc80fvGnw60khXysXvlgPxPP8uJG3EA= github.com/google/go-github/v25 v25.1.3 h1:Ht4YIQgUh4l4lc80fvGnw60khXysXvlgPxPP8uJG3EA=
github.com/google/go-github/v25 v25.1.3/go.mod h1:6z5pC69qHtrPJ0sXPsj4BLnd82b+r6sLB7qcBoRZqpw= github.com/google/go-github/v25 v25.1.3/go.mod h1:6z5pC69qHtrPJ0sXPsj4BLnd82b+r6sLB7qcBoRZqpw=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/pjbgf/sha1cd v0.2.3 h1:uKQP/7QOzNtKYH7UTohZLcjF5/55EnTw0jO/Ru4jZwI=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/pjbgf/sha1cd v0.2.3/go.mod h1:HOK9QrgzdHpbc2Kzip0Q1yi3M2MFGPADtR6HjG65m5M=
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/skeema/knownhosts v1.1.0 h1:Wvr9V0MxhjRbl3f9nMnKnFfiWTJmtECJ9Njkea3ysW0=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/skeema/knownhosts v1.1.0/go.mod h1:sKFq3RD6/TKZkSWn8boUbDC7Qkgcv+8XXijpFO6roag=
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
github.com/spf13/cobra v0.0.6 h1:breEStsVwemnKh2/s6gMvSdMEkwW0sK8vGStnlVBMCs= github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/src-d/gcfg v1.4.0 h1:xXbNR5AlLSA315x2UO+fTSSAXCDf+Ar38/6oyGbDKQ4=
github.com/src-d/gcfg v1.4.0/go.mod h1:p/UMsR43ujA89BJY9duynAwIpvqEujIH/jFlfL7jWoI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70= github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4= github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
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-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d h1:1ZiEyfaQIg3Qh0EoqpwAakHVhecoE5wlSg5GjnafJGw= golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw= golang.org/x/oauth2 v0.5.0 h1:HuArIo48skDwlrvM3sEdHXElYslAMsf3KwRkkW4MC4s=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.5.0/go.mod h1:9/XBHVqLaWO3/BRHs5jbpYCnOZVjj5V0ndyaAM7KB4I=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190221075227-b4e8571b14e0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8= golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI= golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
google.golang.org/appengine v1.6.5 h1:tycE03LOZYQNhDpS27tcQdAzLCVMaj7QT2SXxebnpCM= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/src-d/go-billy.v4 v4.3.2 h1:0SQA1pRztfTFx2miS8sA97XvooFeNOmvUenF4o0EcVg= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/src-d/go-git-fixtures.v3 v3.5.0 h1:ivZFOIltbce2Mo8IjzUHAFoq/IylO9WHhNOAJK+LsJg=
gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g=
gopkg.in/src-d/go-git.v4 v4.13.1 h1:SRtFyV8Kxc0UP7aCHcijOMQGPxHSmMOPrzulQWolkYE=
gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -2,20 +2,30 @@
package analyzer package analyzer
import ( import (
"bufio"
"fmt" "fmt"
"regexp"
"strings"
"github.com/Nightapes/go-semantic-release/internal/shared" "github.com/Nightapes/go-semantic-release/internal/shared"
"github.com/Nightapes/go-semantic-release/pkg/config" "github.com/Nightapes/go-semantic-release/pkg/config"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
//Analyzer struct const breakingChangeKeywords = "BREAKING CHANGE"
const defaultBreakingChangePrefix = breakingChangeKeywords + ":"
const footerTokenRegex = "^(?P<token>[^\\s*-][\\w\\- ]+[^\\s])<SEP>.*"
var defaultTokenSeparators = [2]string{": ", " #"}
// Analyzer struct
type Analyzer struct { type Analyzer struct {
analyzeCommits analyzeCommits analyzeCommits analyzeCommits
Config config.ChangelogConfig ChangelogConfig config.ChangelogConfig
AnalyzerConfig config.AnalyzerConfig
} }
//Rule for commits // Rule for commits
type Rule struct { type Rule struct {
Tag string Tag string
TagString string TagString string
@@ -24,25 +34,28 @@ type Rule struct {
} }
type analyzeCommits interface { type analyzeCommits interface {
analyze(commit shared.Commit, tag Rule) (shared.AnalyzedCommit, bool, error) analyze(commit shared.Commit, tag Rule) *shared.AnalyzedCommit
getRules() []Rule getRules() []Rule
} }
//New Analyzer struct for given commit format // New Analyzer struct for given commit format
func New(format string, config config.ChangelogConfig) (*Analyzer, error) { func New(format string, analyzerConfig config.AnalyzerConfig, chglogConfig config.ChangelogConfig) (*Analyzer, error) {
analyzer := &Analyzer{ analyzer := &Analyzer{
Config: config, AnalyzerConfig: analyzerConfig,
ChangelogConfig: chglogConfig,
} }
switch format { switch format {
case ANGULAR: case ANGULAR:
analyzer.analyzeCommits = newAngular() analyzer.analyzeCommits = newAngular()
log.Debugf("Commit format set to %s", ANGULAR) log.Debugf("Commit format set to %s", ANGULAR)
case CONVENTIONAL:
analyzer.analyzeCommits = newConventional(analyzerConfig)
log.Debugf("Commit format set to %s", CONVENTIONAL)
default: default:
return nil, fmt.Errorf("invalid commit format: %s", format) return nil, fmt.Errorf("invalid commit format: %s", format)
} }
return analyzer, nil return analyzer, nil
} }
// GetRules from current mode // GetRules from current mode
@@ -50,9 +63,8 @@ func (a *Analyzer) GetRules() []Rule {
return a.analyzeCommits.getRules() return a.analyzeCommits.getRules()
} }
// Analyze commits and return commits splitted by major,minor,patch // Analyze commits and return commits split by major,minor,patch
func (a *Analyzer) Analyze(commits []shared.Commit) map[shared.Release][]shared.AnalyzedCommit { func (a *Analyzer) Analyze(commits []shared.Commit) map[shared.Release][]shared.AnalyzedCommit {
analyzedCommits := make(map[shared.Release][]shared.AnalyzedCommit) analyzedCommits := make(map[shared.Release][]shared.AnalyzedCommit)
analyzedCommits["major"] = make([]shared.AnalyzedCommit, 0) analyzedCommits["major"] = make([]shared.AnalyzedCommit, 0)
analyzedCommits["minor"] = make([]shared.AnalyzedCommit, 0) analyzedCommits["minor"] = make([]shared.AnalyzedCommit, 0)
@@ -61,25 +73,132 @@ func (a *Analyzer) Analyze(commits []shared.Commit) map[shared.Release][]shared.
for _, commit := range commits { for _, commit := range commits {
for _, rule := range a.analyzeCommits.getRules() { for _, rule := range a.analyzeCommits.getRules() {
analyzedCommit, hasBreakingChange, err := a.analyzeCommits.analyze(commit, rule) analyzedCommit := a.analyzeCommits.analyze(commit, rule)
if err == nil { if analyzedCommit == nil {
if a.Config.PrintAll { continue
analyzedCommit.Print = true }
} else { if a.ChangelogConfig.PrintAll || rule.Changelog {
analyzedCommit.Print = rule.Changelog analyzedCommit.Print = true
} }
if hasBreakingChange { if analyzedCommit.IsBreaking {
analyzedCommits["major"] = append(analyzedCommits["major"], analyzedCommit) analyzedCommits["major"] = append(analyzedCommits["major"], *analyzedCommit)
} else {
analyzedCommits[rule.Release] = append(analyzedCommits[rule.Release], analyzedCommit)
}
break break
} }
analyzedCommits[rule.Release] = append(analyzedCommits[rule.Release], *analyzedCommit)
break
} }
} }
log.Debugf("Analyzed commits: major=%d minor=%d patch=%d none=%d", len(analyzedCommits["major"]), len(analyzedCommits["minor"]), len(analyzedCommits["patch"]), len(analyzedCommits["none"])) log.Debugf("Analyzed commits: major=%d minor=%d patch=%d none=%d", len(analyzedCommits["major"]), len(analyzedCommits["minor"]), len(analyzedCommits["patch"]), len(analyzedCommits["none"]))
return analyzedCommits return analyzedCommits
} }
//
// getRegexMatchedMap will match a regex with named groups and map the matching
// results to corresponding group names
//
func getRegexMatchedMap(regEx, url string) (paramsMap map[string]string) {
var compRegEx = regexp.MustCompile(regEx)
match := compRegEx.FindStringSubmatch(url)
paramsMap = make(map[string]string)
for i, name := range compRegEx.SubexpNames() {
if i > 0 && i <= len(match) {
paramsMap[name] = match[i]
}
}
return paramsMap
}
//
// getMessageBlocksFromTexts converts strings to an array of MessageBlock
//
func getMessageBlocksFromTexts(txtArray, separators []string) []shared.MessageBlock {
blocks := make([]shared.MessageBlock, len(txtArray))
for i, line := range txtArray {
blocks[i] = parseMessageBlock(line, separators)
}
return blocks
}
//
// parseMessageBlock parses a text in to MessageBlock
//
func parseMessageBlock(msg string, separators []string) shared.MessageBlock {
msgBlock := shared.MessageBlock{
Label: "",
Content: msg,
}
if token, sep := findFooterToken(msg, separators); len(token) > 0 {
msgBlock.Label = token
content := strings.Replace(msg, token+sep, "", 1)
msgBlock.Content = strings.TrimSpace(content)
}
return msgBlock
}
//
// findFooterToken checks if given text has a token with one of the separators and returns a token
//
func findFooterToken(text string, separators []string) (token string, sep string) {
for _, sep := range separators {
regex := strings.Replace(footerTokenRegex, "<SEP>", sep, 1)
matches := getRegexMatchedMap(regex, text)
if token, ok := matches["token"]; ok {
return token, sep
}
}
return "", ""
}
//
// getDefaultMessageBlockMap parses a text block and splits in to different sections.
// default logic to distinguish different parts is:
// - Body starts right after the header (without beginning with a token)
// - Body ends when a footer is discovered or text ends
// - A footer is detected when it starts with a token ending with a separator
// - A footer ends when another footer is found or text ends
//
func getDefaultMessageBlockMap(txtBlock string, tokenSep []string) map[string][]shared.MessageBlock {
msgBlockMap := make(map[string][]shared.MessageBlock)
footers := make([]string, 0)
body, footerBlock, line := "", "", ""
footerFound := false
// Look through each line
scanner := bufio.NewScanner(strings.NewReader(txtBlock))
for scanner.Scan() {
line = scanner.Text()
if token, _ := findFooterToken(line, tokenSep); len(token) > 0 {
// if footer was already found from before
if len(footerBlock) > 0 {
footers = append(footers, strings.TrimSpace(footerBlock))
}
footerFound = true
footerBlock = ""
}
//'\n' is removed when reading from scanner
if !footerFound {
body += line + "\n"
} else {
footerBlock += line + "\n"
}
}
if len(footerBlock) > 0 {
footers = append(footers, strings.TrimSpace(footerBlock))
}
body = strings.TrimSpace(body)
if len(body) > 0 {
msgBlockMap["body"] = []shared.MessageBlock{{
Label: "",
Content: body,
}}
}
footerBlocks := getMessageBlocksFromTexts(footers, tokenSep)
if len(footerBlocks) > 0 {
msgBlockMap["footer"] = footerBlocks
}
return msgBlockMap
}

View File

@@ -10,7 +10,7 @@ import (
func TestAnalyzer(t *testing.T) { func TestAnalyzer(t *testing.T) {
_, err := analyzer.New("unknown", config.ChangelogConfig{}) _, err := analyzer.New("unknown", config.AnalyzerConfig{}, config.ChangelogConfig{})
assert.Error(t, err) assert.Error(t, err)
} }

View File

@@ -2,8 +2,7 @@
package analyzer package analyzer
import ( import (
"fmt" "github.com/Nightapes/go-semantic-release/pkg/config"
"regexp"
"strings" "strings"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
@@ -12,17 +11,20 @@ import (
) )
type angular struct { type angular struct {
rules []Rule rules []Rule
regex string regex string
log *log.Entry log *log.Entry
config config.AnalyzerConfig
} }
// ANGULAR identifer // ANGULAR identifier
const ANGULAR = "angular" const ANGULAR = "angular"
var angularFooterTokenSep = defaultTokenSeparators
func newAngular() *angular { func newAngular() *angular {
return &angular{ return &angular{
regex: `^(TAG)(?:\((.*)\))?: (.*)`, regex: `^(?P<type>\w*)(?:\((?P<scope>.*)\))?: (?P<subject>.*)`,
log: log.WithField("analyzer", ANGULAR), log: log.WithField("analyzer", ANGULAR),
rules: []Rule{ rules: []Rule{
{ {
@@ -36,12 +38,14 @@ func newAngular() *angular {
TagString: "Bug fixes", TagString: "Bug fixes",
Release: "patch", Release: "patch",
Changelog: true, Changelog: true,
}, { },
{
Tag: "perf", Tag: "perf",
TagString: "Performance improvments", TagString: "Performance improvements",
Release: "patch", Release: "patch",
Changelog: true, Changelog: true,
}, { },
{
Tag: "docs", Tag: "docs",
TagString: "Documentation changes", TagString: "Documentation changes",
Release: "none", Release: "none",
@@ -52,22 +56,26 @@ func newAngular() *angular {
TagString: "Style", TagString: "Style",
Release: "none", Release: "none",
Changelog: false, Changelog: false,
}, { },
{
Tag: "refactor", Tag: "refactor",
TagString: "Code refactor", TagString: "Code refactor",
Release: "none", Release: "none",
Changelog: false, Changelog: false,
}, { },
{
Tag: "test", Tag: "test",
TagString: "Testing", TagString: "Testing",
Release: "none", Release: "none",
Changelog: false, Changelog: false,
}, { },
{
Tag: "chore", Tag: "chore",
TagString: "Changes to the build process or auxiliary tools and libraries such as documentation generation", TagString: "Changes to the build process or auxiliary tools and libraries such as documentation generation",
Release: "none", Release: "none",
Changelog: false, Changelog: false,
}, { },
{
Tag: "build", Tag: "build",
TagString: "Changes to CI/CD", TagString: "Changes to CI/CD",
Release: "none", Release: "none",
@@ -81,38 +89,54 @@ func (a *angular) getRules() []Rule {
return a.rules return a.rules
} }
func (a *angular) analyze(commit shared.Commit, rule Rule) (shared.AnalyzedCommit, bool, error) { func (a *angular) analyze(commit shared.Commit, rule Rule) *shared.AnalyzedCommit {
tokenSep := append(a.config.TokenSeparators, angularFooterTokenSep[:]...)
analyzed := shared.AnalyzedCommit{ firstSplit := strings.SplitN(commit.Message, "\n", 2)
Commit: commit, header := firstSplit[0]
Tag: rule.Tag, body := ""
TagString: rule.TagString, if len(firstSplit) > 1 {
body = firstSplit[1]
}
matches := getRegexMatchedMap(a.regex, header)
if len(matches) == 0 || matches["type"] != rule.Tag {
a.log.Tracef("%s does not match %s, skip", commit.Message, rule.Tag)
return nil
} }
re := regexp.MustCompile(strings.Replace(a.regex, "TAG", rule.Tag, -1)) msgBlockMap := getDefaultMessageBlockMap(body, tokenSep)
matches := re.FindAllStringSubmatch(commit.Message, -1)
if len(matches) >= 1 {
if len(matches[0]) >= 3 {
analyzed.Scope = shared.Scope(matches[0][2]) log.Debugf("Found commit from Author %s", commit.Author)
message := strings.Join(matches[0][3:], "") analyzed := &shared.AnalyzedCommit{
if !strings.Contains(message, "BREAKING CHANGE:") { Commit: commit,
analyzed.ParsedMessage = strings.Trim(message, " ") Tag: rule.Tag,
TagString: rule.TagString,
a.log.Tracef("%s: found %s", commit.Message, rule.Tag) Scope: shared.Scope(matches["scope"]),
return analyzed, false, nil Subject: strings.TrimSpace(matches["subject"]),
} MessageBlocks: msgBlockMap,
breakingChange := strings.SplitN(message, "BREAKING CHANGE:", 2)
analyzed.ParsedMessage = strings.Trim(breakingChange[0], " ")
analyzed.ParsedBreakingChangeMessage = strings.Trim(breakingChange[1], " ")
a.log.Tracef(" %s, BREAKING CHANGE found", commit.Message)
return analyzed, true, nil
}
} }
a.log.Tracef("%s does not match %s, skip", commit.Message, rule.Tag)
return analyzed, false, fmt.Errorf("not found")
isBreaking := strings.Contains(commit.Message, defaultBreakingChangePrefix)
analyzed.IsBreaking = isBreaking
oldFormatMessage := strings.TrimSpace(matches["subject"] + "\n" + body)
if !isBreaking {
analyzed.ParsedMessage = strings.Trim(oldFormatMessage, " ")
a.log.Tracef("%s: found %s", commit.Message, rule.Tag)
return analyzed
}
a.log.Tracef(" %s, BREAKING CHANGE found", commit.Message)
breakingChange := strings.SplitN(oldFormatMessage, defaultBreakingChangePrefix, 2)
if len(breakingChange) > 1 {
analyzed.ParsedMessage = strings.TrimSpace(breakingChange[0])
analyzed.ParsedBreakingChangeMessage = strings.TrimSpace(breakingChange[1])
} else {
analyzed.ParsedBreakingChangeMessage = breakingChange[0]
}
return analyzed
} }

View File

@@ -10,7 +10,7 @@ import (
) )
func TestAngular(t *testing.T) { func TestAngular(t *testing.T) {
t.Parallel()
testConfigs := []struct { testConfigs := []struct {
testCase string testCase string
commits []shared.Commit commits []shared.Commit
@@ -19,8 +19,8 @@ func TestAngular(t *testing.T) {
{ {
testCase: "feat", testCase: "feat",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": []shared.AnalyzedCommit{ "minor": {
shared.AnalyzedCommit{ {
Commit: shared.Commit{ Commit: shared.Commit{
Message: "feat(internal/changelog): my first commit", Message: "feat(internal/changelog): my first commit",
Author: "me", Author: "me",
@@ -31,14 +31,16 @@ func TestAngular(t *testing.T) {
Tag: "feat", Tag: "feat",
TagString: "Features", TagString: "Features",
Print: true, Print: true,
Subject: "my first commit",
MessageBlocks: map[string][]shared.MessageBlock{},
}, },
}, },
"major": []shared.AnalyzedCommit{}, "major": {},
"patch": []shared.AnalyzedCommit{}, "patch": {},
"none": []shared.AnalyzedCommit{}, "none": {},
}, },
commits: []shared.Commit{ commits: []shared.Commit{
shared.Commit{ {
Message: "feat(internal/changelog): my first commit", Message: "feat(internal/changelog): my first commit",
Author: "me", Author: "me",
Hash: "12345667", Hash: "12345667",
@@ -48,8 +50,8 @@ func TestAngular(t *testing.T) {
{ {
testCase: "feat breaking change", testCase: "feat breaking change",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": []shared.AnalyzedCommit{ "minor": {
shared.AnalyzedCommit{ {
Commit: shared.Commit{ Commit: shared.Commit{
Message: "feat(internal/changelog): my first commit", Message: "feat(internal/changelog): my first commit",
Author: "me", Author: "me",
@@ -60,10 +62,12 @@ func TestAngular(t *testing.T) {
Tag: "feat", Tag: "feat",
TagString: "Features", TagString: "Features",
Print: true, Print: true,
Subject: "my first commit",
MessageBlocks: map[string][]shared.MessageBlock{},
}, },
}, },
"major": []shared.AnalyzedCommit{ "major": {
shared.AnalyzedCommit{ {
Commit: shared.Commit{ Commit: shared.Commit{
Message: "feat(internal/changelog): my first break BREAKING CHANGE: change api to v2", Message: "feat(internal/changelog): my first break BREAKING CHANGE: change api to v2",
Author: "me", Author: "me",
@@ -75,18 +79,21 @@ func TestAngular(t *testing.T) {
TagString: "Features", TagString: "Features",
Print: true, Print: true,
ParsedBreakingChangeMessage: "change api to v2", ParsedBreakingChangeMessage: "change api to v2",
IsBreaking: true,
Subject: "my first break BREAKING CHANGE: change api to v2",
MessageBlocks: map[string][]shared.MessageBlock{},
}, },
}, },
"patch": []shared.AnalyzedCommit{}, "patch": {},
"none": []shared.AnalyzedCommit{}, "none": {},
}, },
commits: []shared.Commit{ commits: []shared.Commit{
shared.Commit{ {
Message: "feat(internal/changelog): my first commit", Message: "feat(internal/changelog): my first commit",
Author: "me", Author: "me",
Hash: "12345667", Hash: "12345667",
}, },
shared.Commit{ {
Message: "feat(internal/changelog): my first break BREAKING CHANGE: change api to v2", Message: "feat(internal/changelog): my first break BREAKING CHANGE: change api to v2",
Author: "me", Author: "me",
Hash: "12345668", Hash: "12345668",
@@ -94,31 +101,22 @@ func TestAngular(t *testing.T) {
}, },
}, },
{ {
testCase: "invalid", testCase: "feat breaking change footer",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": []shared.AnalyzedCommit{},
"major": []shared.AnalyzedCommit{},
"patch": []shared.AnalyzedCommit{},
"none": []shared.AnalyzedCommit{},
},
commits: []shared.Commit{ commits: []shared.Commit{
shared.Commit{ {
Message: "internal/changelog: my first commit", Message: "feat(internal/changelog): my first commit",
Author: "me", Author: "me",
Hash: "12345667", Hash: "12345667",
}, },
shared.Commit{ {
Message: "Merge feat(internal/changelog): my first commit", Message: "feat(internal/changelog): my first break \n\nBREAKING CHANGE: change api to v2\n",
Author: "me", Author: "me",
Hash: "12345667", Hash: "12345668",
}, },
}, },
},
{
testCase: "feat and build",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": []shared.AnalyzedCommit{ "minor": {
shared.AnalyzedCommit{ {
Commit: shared.Commit{ Commit: shared.Commit{
Message: "feat(internal/changelog): my first commit", Message: "feat(internal/changelog): my first commit",
Author: "me", Author: "me",
@@ -129,10 +127,81 @@ func TestAngular(t *testing.T) {
Tag: "feat", Tag: "feat",
TagString: "Features", TagString: "Features",
Print: true, Print: true,
Subject: "my first commit",
MessageBlocks: map[string][]shared.MessageBlock{},
}, },
}, },
"none": []shared.AnalyzedCommit{ "major": {
shared.AnalyzedCommit{ {
Commit: shared.Commit{
Message: "feat(internal/changelog): my first break \n\nBREAKING CHANGE: change api to v2\n",
Author: "me",
Hash: "12345668",
},
Scope: "internal/changelog",
ParsedMessage: "my first break",
Tag: "feat",
TagString: "Features",
Print: true,
ParsedBreakingChangeMessage: "change api to v2",
IsBreaking: true,
Subject: "my first break",
MessageBlocks: map[string][]shared.MessageBlock{
"footer": {
shared.MessageBlock{
Label: "BREAKING CHANGE",
Content: "change api to v2",
},
},
},
},
},
"patch": {},
"none": {},
},
},
{
testCase: "invalid",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": {},
"major": {},
"patch": {},
"none": {},
},
commits: []shared.Commit{
{
Message: "internal/changelog: my first commit",
Author: "me",
Hash: "12345667",
},
{
Message: "Merge feat(internal/changelog): my first commit",
Author: "me",
Hash: "12345667",
},
},
},
{
testCase: "feat and build",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": {
{
Commit: shared.Commit{
Message: "feat(internal/changelog): my first commit",
Author: "me",
Hash: "12345667",
},
Scope: "internal/changelog",
ParsedMessage: "my first commit",
Tag: "feat",
TagString: "Features",
Print: true,
Subject: "my first commit",
MessageBlocks: map[string][]shared.MessageBlock{},
},
},
"none": {
{
Commit: shared.Commit{ Commit: shared.Commit{
Message: "build(internal/changelog): my first build", Message: "build(internal/changelog): my first build",
Author: "me", Author: "me",
@@ -144,18 +213,20 @@ func TestAngular(t *testing.T) {
TagString: "Changes to CI/CD", TagString: "Changes to CI/CD",
Print: false, Print: false,
ParsedBreakingChangeMessage: "", ParsedBreakingChangeMessage: "",
Subject: "my first build",
MessageBlocks: map[string][]shared.MessageBlock{},
}, },
}, },
"patch": []shared.AnalyzedCommit{}, "patch": {},
"major": []shared.AnalyzedCommit{}, "major": {},
}, },
commits: []shared.Commit{ commits: []shared.Commit{
shared.Commit{ {
Message: "feat(internal/changelog): my first commit", Message: "feat(internal/changelog): my first commit",
Author: "me", Author: "me",
Hash: "12345667", Hash: "12345667",
}, },
shared.Commit{ {
Message: "build(internal/changelog): my first build", Message: "build(internal/changelog): my first build",
Author: "me", Author: "me",
Hash: "12345668", Hash: "12345668",
@@ -164,7 +235,7 @@ func TestAngular(t *testing.T) {
}, },
} }
angular, err := analyzer.New("angular", config.ChangelogConfig{}) angular, err := analyzer.New("angular", config.AnalyzerConfig{}, config.ChangelogConfig{})
assert.NoError(t, err) assert.NoError(t, err)
for _, test := range testConfigs { for _, test := range testConfigs {
@@ -174,5 +245,4 @@ func TestAngular(t *testing.T) {
assert.Equalf(t, test.analyzedCommits["patch"], analyzedCommits["patch"], "Testcase %s should have patch commits", test.testCase) assert.Equalf(t, test.analyzedCommits["patch"], analyzedCommits["patch"], "Testcase %s should have patch commits", test.testCase)
assert.Equalf(t, test.analyzedCommits["none"], analyzedCommits["none"], "Testcase %s should have none commits", test.testCase) assert.Equalf(t, test.analyzedCommits["none"], analyzedCommits["none"], "Testcase %s should have none commits", test.testCase)
} }
} }

View File

@@ -0,0 +1,143 @@
// Package analyzer provides different commit analyzer
package analyzer
import (
"github.com/Nightapes/go-semantic-release/pkg/config"
"strings"
log "github.com/sirupsen/logrus"
"github.com/Nightapes/go-semantic-release/internal/shared"
)
type conventional struct {
rules []Rule
regex string
log *log.Entry
config config.AnalyzerConfig
}
// CONVENTIONAL identifier
const CONVENTIONAL = "conventional"
var conventionalFooterTokenSep = defaultTokenSeparators
func newConventional(config config.AnalyzerConfig) *conventional {
return &conventional{
config: config,
regex: `^(?P<type>\w*)(?:\((?P<scope>.*)\))?(?P<breaking>\!)?: (?P<subject>.*)`,
log: log.WithField("analyzer", CONVENTIONAL),
rules: []Rule{
{
Tag: "feat",
TagString: "Features",
Release: "minor",
Changelog: true,
},
{
Tag: "fix",
TagString: "Bug fixes",
Release: "patch",
Changelog: true,
},
{
Tag: "perf",
TagString: "Performance improvements",
Release: "patch",
Changelog: true,
},
{
Tag: "docs",
TagString: "Documentation changes",
Release: "none",
Changelog: false,
},
{
Tag: "style",
TagString: "Style",
Release: "none",
Changelog: false,
},
{
Tag: "refactor",
TagString: "Code refactor",
Release: "none",
Changelog: false,
},
{
Tag: "test",
TagString: "Testing",
Release: "none",
Changelog: false,
},
{
Tag: "chore",
TagString: "Changes to the build process or auxiliary tools and libraries such as documentation generation",
Release: "none",
Changelog: false,
},
{
Tag: "build",
TagString: "Changes to CI/CD",
Release: "none",
Changelog: false,
},
},
}
}
func (a *conventional) getRules() []Rule {
return a.rules
}
func (a *conventional) analyze(commit shared.Commit, rule Rule) *shared.AnalyzedCommit {
tokenSep := append(a.config.TokenSeparators, conventionalFooterTokenSep[:]...)
firstSplit := strings.SplitN(commit.Message, "\n", 2)
header := firstSplit[0]
body := ""
if len(firstSplit) > 1 {
body = firstSplit[1]
}
matches := getRegexMatchedMap(a.regex, header)
if len(matches) == 0 || matches["type"] != rule.Tag {
a.log.Tracef("%s does not match %s, skip", commit.Message, rule.Tag)
return nil
}
msgBlockMap := getDefaultMessageBlockMap(body, tokenSep)
analyzed := &shared.AnalyzedCommit{
Commit: commit,
Tag: rule.Tag,
TagString: rule.TagString,
Scope: shared.Scope(matches["scope"]),
Subject: strings.TrimSpace(matches["subject"]),
MessageBlocks: msgBlockMap,
}
isBreaking := matches["breaking"] == "!" || strings.Contains(commit.Message, defaultBreakingChangePrefix)
analyzed.IsBreaking = isBreaking
oldFormatMessage := strings.TrimSpace(matches["subject"] + "\n" + body)
if !isBreaking {
analyzed.ParsedMessage = strings.Trim(oldFormatMessage, " ")
a.log.Tracef("%s: found %s", commit.Message, rule.Tag)
return analyzed
}
a.log.Infof(" %s, BREAKING CHANGE found", commit.Message)
breakingChange := strings.SplitN(oldFormatMessage, defaultBreakingChangePrefix, 2)
if len(breakingChange) > 1 {
analyzed.ParsedMessage = strings.TrimSpace(breakingChange[0])
analyzed.ParsedBreakingChangeMessage = strings.TrimSpace(breakingChange[1])
} else {
analyzed.ParsedBreakingChangeMessage = breakingChange[0]
}
return analyzed
}

View File

@@ -0,0 +1,496 @@
package analyzer_test
import (
"testing"
"github.com/Nightapes/go-semantic-release/internal/analyzer"
"github.com/Nightapes/go-semantic-release/internal/shared"
"github.com/Nightapes/go-semantic-release/pkg/config"
"github.com/stretchr/testify/assert"
)
func TestConventional(t *testing.T) {
t.Parallel()
testConfigs := []struct {
testCase string
commits []shared.Commit
wantAnalyzedCommits map[shared.Release][]shared.AnalyzedCommit
}{
{
testCase: "feat",
wantAnalyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": {
{
Commit: shared.Commit{
Message: "feat(internal/changelog): my first commit",
Author: "me",
Hash: "12345667",
},
Scope: "internal/changelog",
ParsedMessage: "my first commit",
Tag: "feat",
TagString: "Features",
Subject: "my first commit",
MessageBlocks: map[string][]shared.MessageBlock{},
Print: true,
},
{
Commit: shared.Commit{
Message: "feat: no scope",
Author: "me",
Hash: "12345667",
},
Scope: "",
ParsedMessage: "no scope",
Tag: "feat",
TagString: "Features",
Subject: "no scope",
MessageBlocks: map[string][]shared.MessageBlock{},
Print: true,
},
},
"major": {},
"patch": {},
"none": {},
},
commits: []shared.Commit{
{
Message: "feat(internal/changelog): my first commit",
Author: "me",
Hash: "12345667",
},
{
Message: "feat: no scope",
Author: "me",
Hash: "12345667",
},
},
},
{
testCase: "feat breaking change",
wantAnalyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": {
{
Commit: shared.Commit{
Message: "feat: my first commit",
Author: "me",
Hash: "12345667",
},
Scope: "",
ParsedMessage: "my first commit",
Tag: "feat",
TagString: "Features",
Print: true,
Subject: "my first commit",
MessageBlocks: map[string][]shared.MessageBlock{},
},
},
"major": {
{
Commit: shared.Commit{
Message: "feat!: my first break",
Author: "me",
Hash: "12345668",
},
Scope: "",
ParsedMessage: "",
Tag: "feat",
TagString: "Features",
Print: true,
ParsedBreakingChangeMessage: "my first break",
IsBreaking: true,
Subject: "my first break",
MessageBlocks: map[string][]shared.MessageBlock{},
},
},
"patch": {},
"none": {},
},
commits: []shared.Commit{
{
Message: "feat: my first commit",
Author: "me",
Hash: "12345667",
},
{
Message: "feat!: my first break",
Author: "me",
Hash: "12345668",
},
},
},
{
testCase: "feat breaking change footer",
wantAnalyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": {
{
Commit: shared.Commit{
Message: "feat: my first commit",
Author: "me",
Hash: "12345667",
},
Scope: "",
ParsedMessage: "my first commit",
Tag: "feat",
TagString: "Features",
Print: true,
Subject: "my first commit",
MessageBlocks: map[string][]shared.MessageBlock{},
},
},
"major": {
{
Commit: shared.Commit{
Message: "feat: my first break \n\nBREAKING CHANGE: change api to v2\n",
Author: "me",
Hash: "12345668",
},
Scope: "",
ParsedMessage: "my first break",
Tag: "feat",
TagString: "Features",
Print: true,
ParsedBreakingChangeMessage: "change api to v2",
IsBreaking: true,
Subject: "my first break",
MessageBlocks: map[string][]shared.MessageBlock{
"footer" : { shared.MessageBlock{
Label: "BREAKING CHANGE",
Content: "change api to v2",
},
},
},
},
{
Commit: shared.Commit{
Message: "feat!: my first break \n\nBREAKING CHANGE: hey from the change",
Author: "me",
Hash: "12345669",
},
Scope: "",
ParsedMessage: "my first break",
Tag: "feat",
TagString: "Features",
Print: true,
ParsedBreakingChangeMessage: "hey from the change",
IsBreaking: true,
Subject: "my first break",
MessageBlocks: map[string][]shared.MessageBlock{
"footer" : {shared.MessageBlock{
Label: "BREAKING CHANGE",
Content: "hey from the change",
},
},
},
},
},
"patch": {},
"none": {},
},
commits: []shared.Commit{
{
Message: "feat: my first commit",
Author: "me",
Hash: "12345667",
},
{
Message: "feat: my first break \n\nBREAKING CHANGE: change api to v2\n",
Author: "me",
Hash: "12345668",
},
{
Message: "feat!: my first break \n\nBREAKING CHANGE: hey from the change",
Author: "me",
Hash: "12345669",
},
},
},
{
testCase: "invalid",
wantAnalyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": {},
"major": {},
"patch": {},
"none": {},
},
commits: []shared.Commit{
{
Message: "internal/changelog: my first commit",
Author: "me",
Hash: "12345667",
},
{
Message: "Merge feat: my first commit",
Author: "me",
Hash: "12345667",
},
},
},
{
testCase: "feat and build",
wantAnalyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": {
{
Commit: shared.Commit{
Message: "feat: my first commit",
Author: "me",
Hash: "12345667",
},
Scope: "",
ParsedMessage: "my first commit",
Tag: "feat",
TagString: "Features",
Print: true,
Subject: "my first commit",
MessageBlocks: map[string][]shared.MessageBlock{},
},
},
"none": {
{
Commit: shared.Commit{
Message: "build: my first build",
Author: "me",
Hash: "12345668",
},
Scope: "",
ParsedMessage: "my first build",
Tag: "build",
TagString: "Changes to CI/CD",
Print: false,
ParsedBreakingChangeMessage: "",
Subject: "my first build",
MessageBlocks: map[string][]shared.MessageBlock{},
},
},
"patch": {},
"major": {},
},
commits: []shared.Commit{
{
Message: "feat: my first commit",
Author: "me",
Hash: "12345667",
},
{
Message: "build: my first build",
Author: "me",
Hash: "12345668",
},
},
},
{
testCase: "fix and build",
wantAnalyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": {},
"none": {
{
Commit: shared.Commit{
Message: "build: my first build",
Author: "me",
Hash: "12345668",
},
Scope: "",
ParsedMessage: "my first build",
Tag: "build",
TagString: "Changes to CI/CD",
Print: false,
ParsedBreakingChangeMessage: "",
Subject: "my first build",
MessageBlocks: map[string][]shared.MessageBlock{},
},
},
"patch": {{
Commit: shared.Commit{
Message: "fix: my first commit",
Author: "me",
Hash: "12345667",
},
Scope: "",
ParsedMessage: "my first commit",
Tag: "fix",
TagString: "Bug fixes",
Print: true,
Subject: "my first commit",
MessageBlocks: map[string][]shared.MessageBlock{},
}},
"major": {},
},
commits: []shared.Commit{
{
Message: "fix: my first commit",
Author: "me",
Hash: "12345667",
},
{
Message: "build: my first build",
Author: "me",
Hash: "12345668",
},
},
},
}
conventional, err := analyzer.New("conventional", config.AnalyzerConfig{}, config.ChangelogConfig{})
assert.NoError(t, err)
for _, test := range testConfigs {
analyzedCommits := conventional.Analyze(test.commits)
assert.Equalf(t, test.wantAnalyzedCommits["major"], analyzedCommits["major"], "Testcase %s should have major commits", test.testCase)
assert.Equalf(t, test.wantAnalyzedCommits["minor"], analyzedCommits["minor"], "Testcase %s should have minor commits", test.testCase)
assert.Equalf(t, test.wantAnalyzedCommits["patch"], analyzedCommits["patch"], "Testcase %s should have patch commits", test.testCase)
assert.Equalf(t, test.wantAnalyzedCommits["none"], analyzedCommits["none"], "Testcase %s should have none commits", test.testCase)
}
}
func TestConventional_BodyAndFooters(t *testing.T) {
t.Parallel()
testConfigs := []struct {
testCase string
commits []shared.Commit
expectedAnalyzedCommits map[shared.Release][]shared.AnalyzedCommit
}{
{
testCase: "Only body, no footer",
commits: []shared.Commit{
{
Message: "fix: squash bug for logging\n\nNow the logs will not print lines twice. The following changed:\n\n-Buffer -Stdout",
Author: "me",
Hash: "12345667",
},
},
expectedAnalyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"patch": {
{
Commit: shared.Commit{
Message: "fix: squash bug for logging\n\nNow the logs will not print lines twice. The following changed:\n\n-Buffer -Stdout",
Author: "me",
Hash: "12345667",
},
Scope: "",
ParsedMessage: "squash bug for logging\n\nNow the logs will not print lines twice. The following changed:\n\n-Buffer -Stdout",
Tag: "fix",
TagString: "Bug fixes",
Print: true,
Subject: "squash bug for logging",
MessageBlocks: map[string][]shared.MessageBlock{
"body": {
shared.MessageBlock{
Label: "",
Content: "Now the logs will not print lines twice. The following changed:\n\n-Buffer -Stdout",
},
},
},
},
},
"major": {},
"minor": {},
"none": {},
},
},
{
testCase: "Only footers, no body",
commits: []shared.Commit{
{
Message: "fix: squash bug for logging\n\nNote: now the logs will not print lines twice.\n\nIssue: #123\nSeverity: medium",
Author: "me",
Hash: "12345667",
},
},
expectedAnalyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"patch": {
{
Commit: shared.Commit{
Message: "fix: squash bug for logging\n\nNote: now the logs will not print lines twice.\n\nIssue: #123\nSeverity: medium",
Author: "me",
Hash: "12345667",
},
Scope: "",
ParsedMessage: "squash bug for logging\n\nNote: now the logs will not print lines twice.\n\nIssue: #123\nSeverity: medium",
Tag: "fix",
TagString: "Bug fixes",
Print: true,
Subject: "squash bug for logging",
MessageBlocks: map[string][]shared.MessageBlock{
"footer": {
shared.MessageBlock{
Label: "Note",
Content: "now the logs will not print lines twice.",
},
shared.MessageBlock{
Label: "Issue",
Content: "#123",
},
shared.MessageBlock{
Label: "Severity",
Content: "medium",
},
},
},
},
},
"major": {},
"minor": {},
"none": {},
},
},
{
testCase: "Body and footers",
commits: []shared.Commit{
{
Message: "fix: squash bug for logging\n\nNow the logs will not print lines twice. The following changed:\n\n-Buffer -Stdout\n\nIssue: #123\nSeverity: medium",
Author: "me",
Hash: "12345667",
},
},
expectedAnalyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"patch": {
{
Commit: shared.Commit{
Message: "fix: squash bug for logging\n\nNow the logs will not print lines twice. The following changed:\n\n-Buffer -Stdout\n\nIssue: #123\nSeverity: medium",
Author: "me",
Hash: "12345667",
},
Scope: "",
ParsedMessage: "squash bug for logging\n\nNow the logs will not print lines twice. The following changed:\n\n-Buffer -Stdout\n\nIssue: #123\nSeverity: medium",
Tag: "fix",
TagString: "Bug fixes",
Print: true,
Subject: "squash bug for logging",
MessageBlocks: map[string][]shared.MessageBlock{
"body": {
shared.MessageBlock{
Label: "",
Content: "Now the logs will not print lines twice. The following changed:\n\n-Buffer -Stdout",
},
},
"footer": {
shared.MessageBlock{
Label: "Issue",
Content: "#123",
},
shared.MessageBlock{
Label: "Severity",
Content: "medium",
},
},
},
},
},
"major": {},
"minor": {},
"none": {},
},
},
}
conventional, err := analyzer.New("conventional", config.AnalyzerConfig{}, config.ChangelogConfig{})
assert.NoError(t, err)
for _, test := range testConfigs {
analyzedCommits := conventional.Analyze(test.commits)
assert.Equalf(t, test.expectedAnalyzedCommits["major"], analyzedCommits["major"], "Testcase %s should have major commits", test.testCase)
assert.Equalf(t, test.expectedAnalyzedCommits["minor"], analyzedCommits["minor"], "Testcase %s should have minor commits", test.testCase)
assert.Equalf(t, test.expectedAnalyzedCommits["patch"], analyzedCommits["patch"], "Testcase %s should have patch commits", test.testCase)
assert.Equalf(t, test.expectedAnalyzedCommits["none"], analyzedCommits["none"], "Testcase %s should have none commits", test.testCase)
}
}

View File

@@ -7,6 +7,7 @@ import (
"crypto/sha256" "crypto/sha256"
"crypto/sha512" "crypto/sha512"
"encoding/hex" "encoding/hex"
"fmt"
"hash" "hash"
"hash/crc32" "hash/crc32"
"io" "io"
@@ -24,6 +25,7 @@ import (
type Asset struct { type Asset struct {
name string name string
path string path string
zippedPath string
algorithm string algorithm string
isCompressed bool isCompressed bool
} }
@@ -63,8 +65,12 @@ func NewAsset(repository string, assetConfig config.Asset, algorithm string) (*A
} }
func (a *Asset) getChecksum() (string, error) { func (a *Asset) getChecksum() (string, error) {
log.Debugf("Calculating checksum for %s", a.path) path, err := a.GetPath()
file, err := os.Open(a.path) if err != nil {
return "", nil
}
log.Debugf("Calculating checksum for %s", path)
file, err := os.Open(path)
if err != nil { if err != nil {
return "", errors.Wrapf(err, "Failed to open file %s to calculate checksum", a.name) return "", errors.Wrapf(err, "Failed to open file %s to calculate checksum", a.name)
} }
@@ -98,13 +104,16 @@ func (a *Asset) getChecksum() (string, error) {
// GetPath where the file is located, if zipped true, it will compress it and give you the new location // GetPath where the file is located, if zipped true, it will compress it and give you the new location
func (a *Asset) GetPath() (string, error) { func (a *Asset) GetPath() (string, error) {
if a.isCompressed { if a.isCompressed {
return a.zipFile() return a.ZipFile()
} }
return a.path, nil return a.path, nil
} }
// GetName of asset // GetName of asset
func (a *Asset) GetName() string { func (a *Asset) GetName() string {
if a.isCompressed {
return fmt.Sprintf("%s.zip", a.name)
}
return a.name return a.name
} }
@@ -114,7 +123,11 @@ func (a *Asset) IsCompressed() bool {
} }
// ZipFile compress given file in zip format // ZipFile compress given file in zip format
func (a *Asset) zipFile() (string, error) { func (a *Asset) ZipFile() (string, error) {
if a.zippedPath != "" {
return a.zippedPath, nil
}
path := a.path path := a.path
fileToZip, err := os.Open(path) fileToZip, err := os.Open(path)
@@ -136,7 +149,6 @@ func (a *Asset) zipFile() (string, error) {
} }
zipWriter := zip.NewWriter(zipFile) zipWriter := zip.NewWriter(zipFile)
defer zipWriter.Close()
fileToZipHeader, err := zip.FileInfoHeader(fileToZipInfo) fileToZipHeader, err := zip.FileInfoHeader(fileToZipInfo)
if err != nil { if err != nil {
@@ -153,8 +165,15 @@ func (a *Asset) zipFile() (string, error) {
if _, err = io.Copy(fileToZipWriter, fileToZip); err != nil { if _, err = io.Copy(fileToZipWriter, fileToZip); err != nil {
return "", errors.Wrap(err, "Could not zip file") return "", errors.Wrap(err, "Could not zip file")
} }
if err := zipWriter.Close(); err != nil {
return "", errors.Wrap(err, fmt.Sprintf("Could not close zipwriter for zip %s", a.path))
}
if err := zipFile.Close(); err != nil { if err := zipFile.Close(); err != nil {
return "", errors.Wrap(err, "Could not close file") return "", errors.Wrap(err, "Could not close file")
} }
return filepath.Abs(fileToZipInfo.Name()) a.zippedPath, err = filepath.Abs(zipFile.Name())
return a.zippedPath, err
} }

View File

@@ -13,7 +13,7 @@ import (
// Set struct // Set struct
type Set struct { type Set struct {
Assets []*Asset assets []*Asset
repository string repository string
algorithm string algorithm string
} }
@@ -21,7 +21,7 @@ type Set struct {
//New container for assets //New container for assets
func New(repository, algorithm string) *Set { func New(repository, algorithm string) *Set {
return &Set{ return &Set{
Assets: []*Asset{}, assets: []*Asset{},
repository: repository, repository: repository,
algorithm: algorithm, algorithm: algorithm,
} }
@@ -34,13 +34,13 @@ func (s *Set) Add(assetConfigs ...config.Asset) error {
if err != nil { if err != nil {
return err return err
} }
s.Assets = append(s.Assets, asset) s.assets = append(s.assets, asset)
} }
return nil return nil
} }
func (s *Set) All() []*Asset { func (s *Set) All() []*Asset {
return s.Assets return s.assets
} }
func (s *Set) GenerateChecksum() error { func (s *Set) GenerateChecksum() error {
@@ -50,7 +50,7 @@ func (s *Set) GenerateChecksum() error {
} }
defer checksumFile.Close() defer checksumFile.Close()
lines := []string{} lines := []string{}
for _, asset := range s.Assets { for _, asset := range s.assets {
checksum, err := asset.getChecksum() checksum, err := asset.getChecksum()
if err != nil { if err != nil {
return err return err
@@ -68,7 +68,7 @@ func (s *Set) GenerateChecksum() error {
return err return err
} }
s.Assets = append(s.Assets, &Asset{ s.assets = append(s.assets, &Asset{
path: filePath, path: filePath,
name: "checksum.txt", name: "checksum.txt",
isCompressed: false, isCompressed: false,

View File

@@ -56,8 +56,8 @@ func TestWriteAndReadCache(t *testing.T) {
}, },
Branch: "master", Branch: "master",
Commits: map[shared.Release][]shared.AnalyzedCommit{ Commits: map[shared.Release][]shared.AnalyzedCommit{
"major": []shared.AnalyzedCommit{ "major": {
shared.AnalyzedCommit{ {
Commit: shared.Commit{ Commit: shared.Commit{
Message: "Message", Message: "Message",
Author: "Author", Author: "Author",
@@ -69,6 +69,8 @@ func TestWriteAndReadCache(t *testing.T) {
Tag: "feat", Tag: "feat",
TagString: "Features", TagString: "Features",
Print: true, Print: true,
Subject: "add gitlab as release option",
MessageBlocks: map[string][]shared.MessageBlock{},
}, },
}, },
}, },

View File

@@ -83,12 +83,12 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "1.1.0-alpha.0", nextVersion: "1.1.0-alpha.0",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []shared.AnalyzedCommit{}, "major": {},
"minor": []shared.AnalyzedCommit{ "minor": {
shared.AnalyzedCommit{}, {},
}, },
"patch": []shared.AnalyzedCommit{}, "patch": {},
"none": []shared.AnalyzedCommit{}, "none": {},
}, },
isFirst: false, isFirst: false,
}, },
@@ -98,12 +98,12 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "1.1.0-beta.0", nextVersion: "1.1.0-beta.0",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []shared.AnalyzedCommit{}, "major": {},
"minor": []shared.AnalyzedCommit{ "minor": {
shared.AnalyzedCommit{}, {},
}, },
"patch": []shared.AnalyzedCommit{}, "patch": {},
"none": []shared.AnalyzedCommit{}, "none": {},
}, },
isFirst: false, isFirst: false,
}, },
@@ -113,10 +113,10 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "1.0.0", nextVersion: "1.0.0",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []shared.AnalyzedCommit{}, "major": {},
"minor": []shared.AnalyzedCommit{}, "minor": {},
"patch": []shared.AnalyzedCommit{}, "patch": {},
"none": []shared.AnalyzedCommit{}, "none": {},
}, },
isFirst: false, isFirst: false,
}, },
@@ -126,10 +126,10 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "1.0.0", nextVersion: "1.0.0",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []shared.AnalyzedCommit{shared.AnalyzedCommit{}}, "major": {{}},
"minor": []shared.AnalyzedCommit{}, "minor": {},
"patch": []shared.AnalyzedCommit{}, "patch": {},
"none": []shared.AnalyzedCommit{}, "none": {},
}, },
isFirst: true, isFirst: true,
}, },
@@ -139,10 +139,10 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "2.0.0-rc.0", nextVersion: "2.0.0-rc.0",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []shared.AnalyzedCommit{shared.AnalyzedCommit{}}, "major": {{}},
"minor": []shared.AnalyzedCommit{shared.AnalyzedCommit{}}, "minor": {{}},
"patch": []shared.AnalyzedCommit{shared.AnalyzedCommit{}}, "patch": {{}},
"none": []shared.AnalyzedCommit{}, "none": {},
}, },
isFirst: false, isFirst: false,
}, },
@@ -152,10 +152,10 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
lastVersion: createVersion("1.0.0-rc.0"), lastVersion: createVersion("1.0.0-rc.0"),
nextVersion: "1.0.0-rc.1", nextVersion: "1.0.0-rc.1",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []shared.AnalyzedCommit{}, "major": {},
"minor": []shared.AnalyzedCommit{shared.AnalyzedCommit{}}, "minor": {{}},
"patch": []shared.AnalyzedCommit{shared.AnalyzedCommit{}}, "patch": {{}},
"none": []shared.AnalyzedCommit{}, "none": {},
}, },
isFirst: false, isFirst: false,
}, },
@@ -165,10 +165,10 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "2.0.0", nextVersion: "2.0.0",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []shared.AnalyzedCommit{shared.AnalyzedCommit{}}, "major": {{}},
"minor": []shared.AnalyzedCommit{shared.AnalyzedCommit{}}, "minor": {{}},
"patch": []shared.AnalyzedCommit{shared.AnalyzedCommit{}}, "patch": {{}},
"none": []shared.AnalyzedCommit{}, "none": {},
}, },
isFirst: false, isFirst: false,
}, },
@@ -178,10 +178,10 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "1.1.0", nextVersion: "1.1.0",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []shared.AnalyzedCommit{}, "major": {},
"minor": []shared.AnalyzedCommit{shared.AnalyzedCommit{}}, "minor": {{}},
"patch": []shared.AnalyzedCommit{shared.AnalyzedCommit{}}, "patch": {{}},
"none": []shared.AnalyzedCommit{}, "none": {},
}, },
isFirst: false, isFirst: false,
}, },
@@ -191,10 +191,10 @@ func TestCalculator_CalculateNewVersion(t *testing.T) {
lastVersion: createVersion("1.0.0"), lastVersion: createVersion("1.0.0"),
nextVersion: "1.0.1", nextVersion: "1.0.1",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"major": []shared.AnalyzedCommit{}, "major": {},
"minor": []shared.AnalyzedCommit{}, "minor": {},
"patch": []shared.AnalyzedCommit{shared.AnalyzedCommit{}}, "patch": {{}},
"none": []shared.AnalyzedCommit{}, "none": {},
}, },
isFirst: false, isFirst: false,
}, },

View File

@@ -1,8 +1,10 @@
package changelog package changelog
import ( import (
"bufio"
"bytes" "bytes"
"io/ioutil" "io/ioutil"
"sort"
"strings" "strings"
"text/template" "text/template"
"time" "time"
@@ -20,20 +22,45 @@ const defaultCommitList string = `{{ range $index,$commit := .BreakingChanges -}
{{ end -}} {{ end -}}
* {{ if $commit.Scope }}**{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}**{{ end }} {{$commit.ParsedBreakingChangeMessage}} * {{ if $commit.Scope }}**{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}**{{ end }} {{$commit.ParsedBreakingChangeMessage}}
introduced by commit: introduced by commit:
{{$commit.ParsedMessage}} {{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})){{end}} {{$commit.Subject}} {{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})){{end}}
{{ end -}} {{ end -}}
{{ range $key := .Order -}} {{ range $key := .Order -}}
{{ $commits := index $.Commits $key -}} {{ $commits := index $.Commits $key -}}
{{ if $commits -}} {{ if $commits -}}
### {{ $key }} ### {{ $key }}
{{ range $index,$commit := $commits -}} {{ range $index,$commit := $commits -}}
* {{ if $commit.Scope }}**{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}** {{end}}{{$commit.ParsedMessage}}{{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})){{end}} * {{ if $commit.Scope }}**{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}** {{end}}{{$commit.Subject}}{{if $.HasURL}} ([{{ printf "%.7s" $commit.Commit.Hash}}]({{ replace $.URL "{{hash}}" $commit.Commit.Hash}})){{end}}
{{ if not $.ShowBodyAsHeader -}}
{{ if $commit.MessageBlocks.body -}}
{{ range $indexBlock,$bodyBlock := $commit.MessageBlocks.body -}}
{{ addPrefixToLines $bodyBlock.Content " > "}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}} {{ end -}}
{{ end -}} {{ end -}}
{{ end -}}` {{ end -}}`
const defaultChangelogTitle string = `v{{.Version}} ({{.Now.Format "2006-01-02"}})` const defaultCommitListSubTemplate = `{{ define "commitList" }}` + defaultCommitList + "{{ end }}"
const defaultChangelog string = `# v{{$.Version}} ({{.Now.Format "2006-01-02"}}) const defaultChangelogTitle = `v{{.Version}} ({{.Now.Format "2006-01-02"}})`
{{ .Commits -}} const defaultChangelog = `# v{{$.Version}} ({{.Now.Format "2006-01-02"}})
{{ if .ShowBodyAsHeader -}}
{{ range $key := .CommitsContent.Order -}}
{{ $commits := index $.CommitsContent.Commits $key -}}
{{ if $commits -}}
{{ range $index,$commit := $commits -}}
{{ if $commit.MessageBlocks.body -}}
{{ range $indexBlock,$bodyBlock := $commit.MessageBlocks.body -}}
{{ $bodyBlock.Content }}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ end -}}
{{ template "commitList" .CommitsContent -}}
{{ if .HasDocker}} {{ if .HasDocker}}
## Docker image ## Docker image
@@ -48,27 +75,55 @@ or
{{$.Backtick}}docker run {{.DockerRepository}}:latest{{$.Backtick}} {{$.Backtick}}docker run {{.DockerRepository}}:latest{{$.Backtick}}
{{ end -}} {{ end -}}
{{ end -}} {{ end -}}
{{ if .HasNPM}}
## NodeJS Package
New NodeJS package is released under [{{.NPMPackageName}}]({{.NPMRepository}})
### Usage
{{$.Backtick}}yarn add {{.NPMPackageName}}@{{.Version}}{{$.Backtick}}
or
{{$.Backtick}}npm install -save {{.NPMPackageName}}@{{.Version}}{{$.Backtick}}
{{ end -}}
{{ if .ShowAuthors -}}
# Special Thanks
{{range $i,$a := .Authors}}{{if gt $i 0 }}, {{end}}{{$a}}{{end}}
{{ end -}}
` `
type changelogContent struct { type changelogContent struct {
Commits string Commits string
CommitsContent commitsContent
Version string Version string
Now time.Time Now time.Time
Backtick string Backtick string
ShowBodyAsHeader bool
HasDocker bool HasDocker bool
HasDockerLatest bool HasDockerLatest bool
DockerRepository string DockerRepository string
HasNPM bool
IsYarn bool
NPMRepository string
NPMPackageName string
Authors []string
ShowAuthors bool
} }
type commitsContent struct { type commitsContent struct {
Commits map[string][]shared.AnalyzedCommit Commits map[string][]shared.AnalyzedCommit
BreakingChanges []shared.AnalyzedCommit BreakingChanges []shared.AnalyzedCommit
Order []string Order []string
Version string ShowBodyAsHeader bool
Now time.Time Backtick string
Backtick string HasURL bool
HasURL bool URL string
URL string
} }
//Changelog struct //Changelog struct
@@ -89,11 +144,11 @@ func New(config *config.ReleaseConfig, rules []analyzer.Rule, releaseTime time.T
} }
} }
// GenerateChanglog from given commits // GenerateChangelog from given commits
func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConfig, analyzedCommits map[shared.Release][]shared.AnalyzedCommit) (*shared.GeneratedChangelog, error) { func (c *Changelog) GenerateChangelog(templateConfig shared.ChangelogTemplateConfig, analyzedCommits map[shared.Release][]shared.AnalyzedCommit) (*shared.GeneratedChangelog, error) {
commitsPerScope := map[string][]shared.AnalyzedCommit{} commitsPerScope := map[string][]shared.AnalyzedCommit{}
commitsBreakingChange := []shared.AnalyzedCommit{} var commitsBreakingChange []shared.AnalyzedCommit
order := make([]string, 0) order := make([]string, 0)
for _, rule := range c.rules { for _, rule := range c.rules {
@@ -103,10 +158,13 @@ func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConf
} }
} }
authors := map[string]bool{}
for _, commits := range analyzedCommits { for _, commits := range analyzedCommits {
for _, commit := range commits { for _, commit := range commits {
authors[commit.Commit.Author] = true
if commit.Print { if commit.Print {
if commit.ParsedBreakingChangeMessage != "" { if commit.IsBreaking {
commitsBreakingChange = append(commitsBreakingChange, commit) commitsBreakingChange = append(commitsBreakingChange, commit)
continue continue
} }
@@ -119,31 +177,47 @@ func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConf
} }
commitsContent := commitsContent{ commitsContent := commitsContent{
Version: templateConfig.Version, Commits: commitsPerScope,
Commits: commitsPerScope, BreakingChanges: commitsBreakingChange,
Now: c.releaseTime, Backtick: "`",
BreakingChanges: commitsBreakingChange, Order: order,
Backtick: "`", ShowBodyAsHeader: c.config.Changelog.ShowBodyAsHeader,
Order: order, HasURL: templateConfig.CommitURL != "",
HasURL: templateConfig.CommitURL != "", URL: templateConfig.CommitURL,
URL: templateConfig.CommitURL,
} }
authorsNames := make([]string, len(authors))
i := 0
for k := range authors {
authorsNames[i] = k
i++
}
sort.Strings(authorsNames)
changelogContent := changelogContent{ changelogContent := changelogContent{
CommitsContent: commitsContent,
Version: templateConfig.Version, Version: templateConfig.Version,
Now: c.releaseTime, Now: c.releaseTime,
Backtick: "`", Backtick: "`",
HasDocker: c.config.Changelog.Docker.Repository != "", HasDocker: c.config.Changelog.Docker.Repository != "",
HasDockerLatest: c.config.Changelog.Docker.Latest, HasDockerLatest: c.config.Changelog.Docker.Latest,
DockerRepository: c.config.Changelog.Docker.Repository, DockerRepository: c.config.Changelog.Docker.Repository,
HasNPM: c.config.Changelog.NPM.PackageName != "",
NPMPackageName: c.config.Changelog.NPM.PackageName,
NPMRepository: c.config.Changelog.NPM.Repository,
ShowBodyAsHeader: c.config.Changelog.ShowBodyAsHeader,
ShowAuthors: c.config.Changelog.ShowAuthors && len(authors) > 0,
Authors: authorsNames,
} }
template := defaultChangelog
chglogTemplate := defaultCommitListSubTemplate + defaultChangelog
if c.config.Changelog.TemplatePath != "" { if c.config.Changelog.TemplatePath != "" {
content, err := ioutil.ReadFile(c.config.Changelog.TemplatePath) content, err := ioutil.ReadFile(c.config.Changelog.TemplatePath)
if err != nil { if err != nil {
return nil, err return nil, err
} }
template = string(content) chglogTemplate = string(content)
} }
templateTitle := defaultChangelogTitle templateTitle := defaultChangelogTitle
@@ -152,30 +226,41 @@ func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConf
} }
log.Debugf("Render title") log.Debugf("Render title")
renderedTitle, err := generateTemplate(templateTitle, changelogContent) renderedTitle, err := generateTemplate(templateTitle, changelogContent, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.Debugf("Render commits") log.Debugf("Render commits")
renderedCommitList, err := generateTemplate(defaultCommitList, commitsContent) renderedCommitList, err := generateTemplate(defaultCommitList, commitsContent, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.Tracef("Commits %s", renderedCommitList) log.Tracef("Commits %s", renderedCommitList)
changelogContent.Commits = renderedCommitList changelogContent.Commits = renderedCommitList
extraFuncMap := template.FuncMap{
"commitUrl": func() string { return templateConfig.CommitURL },
}
log.Debugf("Render changelog") log.Debugf("Render changelog")
renderedContent, err := generateTemplate(template, changelogContent) renderedContent, err := generateTemplate(chglogTemplate, changelogContent, extraFuncMap)
return &shared.GeneratedChangelog{Title: renderedTitle, Content: renderedContent}, err return &shared.GeneratedChangelog{Title: renderedTitle, Content: renderedContent}, err
} }
func generateTemplate(text string, values interface{}) (string, error) { func generateTemplate(text string, values interface{}, extraFuncMap template.FuncMap) (string, error) {
funcMap := template.FuncMap{ funcMap := template.FuncMap{
"replace": replace, "replace": replace,
"lower": lower,
"upper": upper,
"capitalize": capitalize,
"addPrefixToLines": addPrefixToLines,
}
for k, v := range extraFuncMap {
funcMap[k] = v
} }
var tpl bytes.Buffer var tpl bytes.Buffer
@@ -193,3 +278,30 @@ func generateTemplate(text string, values interface{}) (string, error) {
func replace(input, from, to string) string { func replace(input, from, to string) string {
return strings.Replace(input, from, to, -1) return strings.Replace(input, from, to, -1)
} }
func lower(input string) string {
return strings.ToLower(input)
}
func upper(input string) string {
return strings.ToUpper(input)
}
func capitalize(input string) string {
if len(input) > 0 {
return strings.ToUpper(string(input[0])) + input[1:]
}
return ""
}
// Adds a prefix to each line of the given text block
// this can be helpful in rendering correct indentation or bullets for multi-line texts
func addPrefixToLines(input, prefix string) string {
output := ""
scanner := bufio.NewScanner(strings.NewReader(input))
for scanner.Scan() {
output += prefix + scanner.Text() + "\n"
}
output = strings.TrimRight(output, "\n")
return output
}

View File

@@ -25,12 +25,13 @@ func TestChangelog(t *testing.T) {
analyzedCommits map[shared.Release][]shared.AnalyzedCommit analyzedCommits map[shared.Release][]shared.AnalyzedCommit
result *shared.GeneratedChangelog result *shared.GeneratedChangelog
hasError bool hasError bool
showAuthors bool
}{ }{
{ {
testCase: "feat", testCase: "feat",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": []shared.AnalyzedCommit{ "minor": {
shared.AnalyzedCommit{ {
Commit: shared.Commit{ Commit: shared.Commit{
Message: "feat(internal/changelog): my first commit", Message: "feat(internal/changelog): my first commit",
Author: "me", Author: "me",
@@ -41,6 +42,8 @@ func TestChangelog(t *testing.T) {
Tag: "feat", Tag: "feat",
TagString: "Features", TagString: "Features",
Print: true, Print: true,
Subject: "my first commit",
MessageBlocks: map[string][]shared.MessageBlock{},
}, },
}, },
}, },
@@ -50,11 +53,51 @@ func TestChangelog(t *testing.T) {
}, },
hasError: false, hasError: false,
}, },
{
testCase: "feat with authors",
showAuthors: true,
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": {
{
Commit: shared.Commit{
Message: "feat(internal/changelog): my first commit",
Author: "me",
Hash: "12345667",
},
Scope: "internal/changelog",
ParsedMessage: "my first commit",
Tag: "feat",
TagString: "Features",
Print: true,
Subject: "my first commit",
MessageBlocks: map[string][]shared.MessageBlock{},
},
{
Commit: shared.Commit{
Message: "feat(internal/changelog): my second commit",
Author: "secondAuthor",
Hash: "12345667",
},
Scope: "internal/changelog",
ParsedMessage: "my second commit",
Tag: "feat",
TagString: "Features",
Print: true,
Subject: "my second commit",
MessageBlocks: map[string][]shared.MessageBlock{},
},
},
},
result: &shared.GeneratedChangelog{
Title: "v1.0.0 (2019-07-19)",
Content: "# v1.0.0 (2019-07-19)\n### Features\n* **`internal/changelog`** my first commit ([1234566](https://commit.url))\n* **`internal/changelog`** my second commit ([1234566](https://commit.url))\n# Special Thanks\n\nme, secondAuthor\n"},
hasError: false,
},
{ {
testCase: "feat no scope", testCase: "feat no scope",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": []shared.AnalyzedCommit{ "minor": {
shared.AnalyzedCommit{ {
Commit: shared.Commit{ Commit: shared.Commit{
Message: "feat: my first commit", Message: "feat: my first commit",
Author: "me", Author: "me",
@@ -64,6 +107,8 @@ func TestChangelog(t *testing.T) {
Tag: "feat", Tag: "feat",
TagString: "Features", TagString: "Features",
Print: true, Print: true,
Subject: "my first commit",
MessageBlocks: map[string][]shared.MessageBlock{},
}, },
}, },
}, },
@@ -76,8 +121,8 @@ func TestChangelog(t *testing.T) {
{ {
testCase: "feat breaking change", testCase: "feat breaking change",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{ analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": []shared.AnalyzedCommit{ "minor": {
shared.AnalyzedCommit{ {
Commit: shared.Commit{ Commit: shared.Commit{
Message: "feat(internal/changelog): my first commit", Message: "feat(internal/changelog): my first commit",
Author: "me", Author: "me",
@@ -88,8 +133,10 @@ func TestChangelog(t *testing.T) {
Tag: "feat", Tag: "feat",
TagString: "Features", TagString: "Features",
Print: true, Print: true,
Subject: "my first commit",
MessageBlocks: map[string][]shared.MessageBlock{},
}, },
shared.AnalyzedCommit{ {
Commit: shared.Commit{ Commit: shared.Commit{
Message: "feat(internal/changelog): my first break: BREAKING CHANGE: change api to v2", Message: "feat(internal/changelog): my first break: BREAKING CHANGE: change api to v2",
Author: "me", Author: "me",
@@ -101,6 +148,15 @@ func TestChangelog(t *testing.T) {
TagString: "Features", TagString: "Features",
Print: true, Print: true,
ParsedBreakingChangeMessage: "change api to v2", ParsedBreakingChangeMessage: "change api to v2",
IsBreaking: true,
Subject: "my first break",
MessageBlocks: map[string][]shared.MessageBlock{
"body": {shared.MessageBlock{
Label: "BREAKING CHANGE",
Content: "change api to v2",
},
},
},
}, },
}, },
}, },
@@ -110,33 +166,247 @@ func TestChangelog(t *testing.T) {
}, },
hasError: false, hasError: false,
}, },
{
testCase: "conventional commits",
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
"minor": {
{
Commit: shared.Commit{
Message: "feat!: my first break \n\nBREAKING CHANGE: hey from the change",
Author: "me",
Hash: "12345669",
},
Scope: "",
ParsedMessage: "my first break",
Tag: "feat",
TagString: "Features",
Print: true,
ParsedBreakingChangeMessage: "hey from the change",
IsBreaking: true,
Subject: "my first break",
MessageBlocks: map[string][]shared.MessageBlock{
"body": {shared.MessageBlock{
Label: "BREAKING CHANGE",
Content: "hey from the change",
},
},
},
},
{
Commit: shared.Commit{
Message: "feat(internal/changelog): my first commit",
Author: "me",
Hash: "12345667",
},
Scope: "internal/changelog",
ParsedMessage: "my first commit",
Tag: "feat",
TagString: "Features",
Print: true,
Subject: "my first commit",
MessageBlocks: map[string][]shared.MessageBlock{},
},
{
Commit: shared.Commit{
Message: "feat: my second commit",
Author: "me",
Hash: "12345667",
},
Scope: "",
ParsedMessage: "my first commit",
Tag: "feat",
TagString: "Features",
Print: true,
Subject: "my second commit",
MessageBlocks: map[string][]shared.MessageBlock{},
},
{
Commit: shared.Commit{
Message: "feat: my first break \n\nBREAKING CHANGE: change api to v2",
Author: "me",
Hash: "12345668",
},
Scope: "",
ParsedMessage: "my first break",
Tag: "feat",
TagString: "Features",
Print: true,
ParsedBreakingChangeMessage: "change api to v2",
IsBreaking: true,
Subject: "my first break",
MessageBlocks: map[string][]shared.MessageBlock{
"body": {shared.MessageBlock{
Label: "BREAKING CHANGE",
Content: "change api to v2",
}},
},
},
{
Commit: shared.Commit{
Message: "feat: my awesome features \n\n * Feature1: Lists in changelog \n* Feature2: Lists in changelog2",
Author: "me",
Hash: "12345668",
},
Scope: "",
ParsedMessage: "my awesome features",
Tag: "feat",
TagString: "Features",
Print: true,
ParsedBreakingChangeMessage: "",
IsBreaking: false,
Subject: "my awesome features",
MessageBlocks: map[string][]shared.MessageBlock{
"body": {shared.MessageBlock{
Label: "",
Content: "* Feature1: Lists in changelog \n* Feature2: Lists in changelog2",
}},
},
},
{
Commit: shared.Commit{
Message: "feat!: my next commit",
Author: "me",
Hash: "12345668",
},
Scope: "",
ParsedMessage: "",
Tag: "feat",
TagString: "Features",
Print: true,
ParsedBreakingChangeMessage: "my next commit",
IsBreaking: true,
Subject: "my next commit",
MessageBlocks: map[string][]shared.MessageBlock{},
},
},
},
result: &shared.GeneratedChangelog{
Title: "v1.0.0 (2019-07-19)",
Content: "# v1.0.0 (2019-07-19)\n## BREAKING CHANGES\n* hey from the change \nintroduced by commit: \nmy first break ([1234566](https://commit.url))\n* change api to v2 \nintroduced by commit: \nmy first break ([1234566](https://commit.url))\n* my next commit \nintroduced by commit: \nmy next commit ([1234566](https://commit.url))\n### Features\n* **`internal/changelog`** my first commit ([1234566](https://commit.url))\n* my second commit ([1234566](https://commit.url))\n* my awesome features ([1234566](https://commit.url))\n > * Feature1: Lists in changelog \n > * Feature2: Lists in changelog2\n"},
hasError: false,
},
} }
cl := changelog.New(&config.ReleaseConfig{}, []analyzer.Rule{ for _, testConfig := range testConfigs {
t.Run(testConfig.testCase, func(t *testing.T) {
cl := changelog.New(&config.ReleaseConfig{
Changelog: config.ChangelogConfig{
ShowBodyAsHeader: false,
ShowAuthors: testConfig.showAuthors,
},
}, []analyzer.Rule{
{
Tag: "feat",
TagString: "Features",
Release: "minor",
Changelog: true,
},
{
Tag: "fix",
TagString: "Bug fixes",
Release: "patch",
Changelog: true,
},
{
Tag: "build",
TagString: "Build",
Release: "none",
Changelog: false,
},
}, time.Date(2019, 7, 19, 0, 0, 0, 0, time.UTC))
generatedChangelog, err := cl.GenerateChangelog(templateConfig, testConfig.analyzedCommits)
assert.Equalf(t, testConfig.hasError, err != nil, "Testcase %s should have error: %t -> %s", testConfig.testCase, testConfig.hasError, err)
assert.Equalf(t, testConfig.result, generatedChangelog, "Testcase %s should have generated changelog", testConfig.testCase)
})
}
}
func TestChangelogExtensions(t *testing.T) {
testConfigs := []struct {
testCase string
result *shared.GeneratedChangelog
releaseConfig *config.ReleaseConfig
}{
{ {
Tag: "feat", testCase: "docker",
TagString: "Features", releaseConfig: &config.ReleaseConfig{
Release: "minor", Changelog: config.ChangelogConfig{
Changelog: true, Docker: config.ChangelogDocker{
Latest: true,
Repository: "mydocker.de",
},
NPM: config.ChangelogNPM{},
},
},
result: &shared.GeneratedChangelog{Title: "v1.0.0 (2019-07-19)", Content: "# v1.0.0 (2019-07-19)\n### Features\n* **`internal/changelog`** my first commit ([1234566](https://commit.url))\n\n## Docker image\n\nNew docker image is released under `mydocker.de:1.0.0`\n\n### Usage\n\n`docker run mydocker.de:1.0.0`\n\nor\n\n`docker run mydocker.de:latest`\n"},
}, },
{ {
Tag: "fix", testCase: "npm",
TagString: "Bug fixes", releaseConfig: &config.ReleaseConfig{
Release: "patch", Changelog: config.ChangelogConfig{
Changelog: true, Docker: config.ChangelogDocker{},
NPM: config.ChangelogNPM{
Repository: "https://github.com/Nightapes/ngx-validators/packages/102720",
PackageName: "ngx-validators",
},
},
},
result: &shared.GeneratedChangelog{Title: "v1.0.0 (2019-07-19)", Content: "# v1.0.0 (2019-07-19)\n### Features\n* **`internal/changelog`** my first commit ([1234566](https://commit.url))\n\n## NodeJS Package\n\nNew NodeJS package is released under [ngx-validators](https://github.com/Nightapes/ngx-validators/packages/102720)\n\n### Usage\n\n`yarn add ngx-validators@1.0.0`\n\nor\n\n`npm install -save ngx-validators@1.0.0`\n\n"},
}, },
{ }
Tag: "build",
TagString: "Build", analyzedCommits := map[shared.Release][]shared.AnalyzedCommit{
Release: "none", "minor": {
Changelog: false, {
Commit: shared.Commit{
Message: "feat(internal/changelog): my first commit",
Author: "me",
Hash: "12345667",
},
Scope: "internal/changelog",
ParsedMessage: "my first commit",
Tag: "feat",
TagString: "Features",
Print: true,
Subject: "my first commit",
MessageBlocks: map[string][]shared.MessageBlock{},
},
}, },
}, time.Date(2019, 7, 19, 0, 0, 0, 0, time.UTC)) }
for _, config := range testConfigs { for _, config := range testConfigs {
t.Run(config.testCase, func(t *testing.T) { t.Run(config.testCase, func(t *testing.T) {
generatedChangelog, err := cl.GenerateChanglog(templateConfig, config.analyzedCommits) templateConfig := shared.ChangelogTemplateConfig{
assert.Equalf(t, config.hasError, err != nil, "Testcase %s should have error: %t -> %s", config.testCase, config.hasError, err) CommitURL: "https://commit.url",
CompareURL: "https://compare.url",
Hash: "hash",
Version: "1.0.0",
}
cl := changelog.New(config.releaseConfig, []analyzer.Rule{
{
Tag: "feat",
TagString: "Features",
Release: "minor",
Changelog: true,
},
{
Tag: "fix",
TagString: "Bug fixes",
Release: "patch",
Changelog: true,
},
{
Tag: "build",
TagString: "Build",
Release: "none",
Changelog: false,
},
}, time.Date(2019, 7, 19, 0, 0, 0, 0, time.UTC))
generatedChangelog, err := cl.GenerateChangelog(templateConfig, analyzedCommits)
assert.NoError(t, err)
assert.Equalf(t, config.result, generatedChangelog, "Testcase %s should have generated changelog", config.testCase) assert.Equalf(t, config.result, generatedChangelog, "Testcase %s should have generated changelog", config.testCase)
}) })
} }

View File

@@ -6,11 +6,11 @@ import (
"github.com/Nightapes/go-semantic-release/internal/ci" "github.com/Nightapes/go-semantic-release/internal/ci"
"github.com/Nightapes/go-semantic-release/internal/gitutil" "github.com/Nightapes/go-semantic-release/internal/gitutil"
"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/go-git/go-git/v5/storage/memory"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"gopkg.in/src-d/go-billy.v4/memfs"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"gopkg.in/src-d/go-git.v4/storage/memory"
) )
func TestCi(t *testing.T) { func TestCi(t *testing.T) {

View File

@@ -9,11 +9,10 @@ import (
"github.com/Masterminds/semver" "github.com/Masterminds/semver"
"github.com/Nightapes/go-semantic-release/internal/shared" "github.com/Nightapes/go-semantic-release/internal/shared"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/object"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
) )
// GitUtil struct // GitUtil struct
@@ -78,14 +77,30 @@ func (g *GitUtil) GetBranch() (string, error) {
} }
// GetLastVersion from git tags // GetLastVersion from git tags
func (g *GitUtil) GetLastVersion() (*semver.Version, string, error) { func (g *GitUtil) GetVersion(version string) (*semver.Version, *plumbing.Reference, error) {
v, err := semver.NewVersion(version)
if err != nil {
return nil, nil, err
}
tag, err := g.Repository.Tag(version)
if err != nil {
return nil, nil, err
}
log.Debugf("Found old hash %s", tag.Hash().String())
return v, tag, nil
}
// GetLastVersion from git tags
func (g *GitUtil) GetLastVersion() (*semver.Version, *plumbing.Reference, error) {
var tags []*semver.Version var tags []*semver.Version
gitTags, err := g.Repository.Tags() gitTags, err := g.Repository.Tags()
if err != nil { if err != nil {
return nil, "", err return nil, nil, err
} }
err = gitTags.ForEach(func(p *plumbing.Reference) error { err = gitTags.ForEach(func(p *plumbing.Reference) error {
@@ -101,64 +116,84 @@ func (g *GitUtil) GetLastVersion() (*semver.Version, string, error) {
}) })
if err != nil { if err != nil {
return nil, "", err return nil, nil, err
} }
sort.Sort(sort.Reverse(semver.Collection(tags))) sort.Sort(sort.Reverse(semver.Collection(tags)))
if len(tags) == 0 { if len(tags) == 0 {
log.Debugf("Found no tags") log.Debugf("Found no tags")
return nil, "", nil return nil, nil, nil
} }
log.Debugf("Found old version %s", tags[0].String()) log.Debugf("Found old version %s", tags[0].String())
tag, err := g.Repository.Tag(tags[0].Original()) tag, err := g.Repository.Tag(tags[0].Original())
if err != nil { if err != nil {
return nil, "", err return nil, nil, err
} }
log.Debugf("Found old hash %s", tag.Hash().String()) log.Debugf("Found old hash %s", tag.Hash().String())
return tags[0], tag.Hash().String(), nil return tags[0], tag, nil
} }
// GetCommits from git hash to HEAD // GetCommits from git hash to HEAD
func (g *GitUtil) GetCommits(lastTagHash string) ([]shared.Commit, error) { func (g *GitUtil) GetCommits(lastTagHash *plumbing.Reference) ([]shared.Commit, error) {
ref, err := g.Repository.Head() ref, err := g.Repository.Head()
if err != nil { if err != nil {
return nil, err return nil, err
} }
logOptions := &git.LogOptions{From: ref.Hash()}
cIter, err := g.Repository.Log(&git.LogOptions{From: ref.Hash(), Order: git.LogOrderCommitterTime}) if lastTagHash != nil {
logOptions = &git.LogOptions{From: lastTagHash.Hash()}
}
excludeIter, err := g.Repository.Log(logOptions)
if err != nil {
return nil, fmt.Errorf("could not get git log %w", err)
}
seen := map[plumbing.Hash]struct{}{}
err = excludeIter.ForEach(func(c *object.Commit) error {
seen[c.Hash] = struct{}{}
return nil
})
if err != nil { if err != nil {
return nil, err return nil, err
} }
var commits []shared.Commit var isValid object.CommitFilter = func(commit *object.Commit) bool {
var foundEnd bool _, ok := seen[commit.Hash]
return !ok && len(commit.ParentHashes) < 2
}
startCommit, err := g.Repository.CommitObject(ref.Hash())
if err != nil {
return nil, err
}
cIter := object.NewFilterCommitIter(startCommit, &isValid, nil)
commits := make(map[string]shared.Commit)
err = cIter.ForEach(func(c *object.Commit) error { err = cIter.ForEach(func(c *object.Commit) error {
if c.Hash.String() == lastTagHash { log.Debugf("Found commit with hash %s from %s", c.Hash.String(), c.Author.Name)
log.Debugf("Found commit with hash %s, will stop here", c.Hash.String()) commits[c.Hash.String()] = shared.Commit{
foundEnd = true Message: c.Message,
return storer.ErrStop Author: c.Author.Name,
} Hash: c.Hash.String(),
if !foundEnd {
log.Tracef("Found commit with hash %s", c.Hash.String())
commit := shared.Commit{
Message: c.Message,
Author: c.Committer.Name,
Hash: c.Hash.String(),
}
commits = append(commits, commit)
} }
return nil return nil
}) })
if err != nil { if err != nil {
return commits, errors.Wrap(err, "Could not read commits, check git clone depth in your ci") return nil, errors.Wrap(err, "Could not read commits, check git clone depth in your ci")
} }
return commits, nil l := make([]shared.Commit, 0)
for _, value := range commits {
l = append(l, value)
}
return l, nil
} }

View File

@@ -2,13 +2,16 @@ package hooks
import ( import (
"bufio" "bufio"
"io"
"os"
"os/exec" "os/exec"
"runtime" "runtime"
"strings" "strings"
log "github.com/sirupsen/logrus"
"github.com/Nightapes/go-semantic-release/internal/shared" "github.com/Nightapes/go-semantic-release/internal/shared"
"github.com/Nightapes/go-semantic-release/pkg/config" "github.com/Nightapes/go-semantic-release/pkg/config"
log "github.com/sirupsen/logrus"
) )
//Hooks struct //Hooks struct
@@ -61,17 +64,28 @@ func (h *Hooks) runCommand(command string) error {
cmd = exec.Command("sh", "-c", cmdReplaced) cmd = exec.Command("sh", "-c", cmdReplaced)
} }
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "RELEASE_VERSION="+h.version.Next.Version.String())
cmdReader, err := cmd.StdoutPipe() cmdReader, err := cmd.StdoutPipe()
if err != nil { if err != nil {
return err return err
} }
h.printOutput(cmdReader, strings.Fields(cmdReplaced)[0])
scanner := bufio.NewScanner(cmdReader) cmdErrReader, err := cmd.StderrPipe()
go func() { if err != nil {
for scanner.Scan() { return err
log.WithField("cmd", strings.Fields(cmdReplaced)[0]).Infof("%s\n", scanner.Text()) }
} h.printOutput(cmdErrReader, strings.Fields(cmdReplaced)[0])
}()
return cmd.Run() return cmd.Run()
} }
func (h *Hooks) printOutput(read io.ReadCloser, cmd string) {
scanner := bufio.NewScanner(read)
go func() {
for scanner.Scan() {
log.WithField("cmd", cmd).Infof("%s\n", scanner.Text())
}
}()
}

View File

@@ -0,0 +1,26 @@
package integrations
import (
"github.com/Nightapes/go-semantic-release/internal/shared"
"github.com/Nightapes/go-semantic-release/pkg/config"
)
// Integrations struct
type Integrations struct {
version *shared.ReleaseVersion
config *config.Integrations
}
func New(config *config.Integrations, version *shared.ReleaseVersion) *Integrations {
return &Integrations{
config: config,
version: version,
}
}
func (i Integrations) Run() error {
if i.config.NPM.Enabled {
return i.updateNPM()
}
return nil
}

View File

@@ -0,0 +1,28 @@
package integrations
import (
log "github.com/sirupsen/logrus"
"github.com/tidwall/sjson"
"io/ioutil"
)
func (i *Integrations) updateNPM() error {
npmConfig := i.config.NPM
if npmConfig.Path == "" {
npmConfig.Path = "./package.json"
}
log.Debugf("Set version %s to %s", i.version.Next.Version, npmConfig.Path)
data, err := ioutil.ReadFile(npmConfig.Path)
if err != nil {
return err
}
newData, err := sjson.Set(string(data), "version", i.version.Next.Version)
if err != nil {
return err
}
return ioutil.WriteFile(npmConfig.Path, []byte(newData), 0777)
}

View File

@@ -0,0 +1,62 @@
package integrations
import (
"github.com/Masterminds/semver"
"github.com/Nightapes/go-semantic-release/internal/shared"
"github.com/Nightapes/go-semantic-release/pkg/config"
"github.com/stretchr/testify/assert"
"io/ioutil"
"os"
"testing"
)
func TestIntegrations_updateNPM(t *testing.T) {
file, err := ioutil.TempFile("", "package")
if err != nil {
t.Fatal(err)
}
defer os.Remove(file.Name())
err = ioutil.WriteFile(file.Name(), []byte(`{
"name": "test",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"nx": "nx"
}
}`), 0777)
if err != nil {
t.Fatal(err)
}
testVersion, err := semver.NewVersion("1.2.0")
if err != nil {
t.Fatal(err)
}
i := New(&config.Integrations{NPM: config.IntegrationNPM{
Enabled: true,
Path: file.Name(),
}}, &shared.ReleaseVersion{
Next: shared.ReleaseVersionEntry{
Version: testVersion,
},
})
assert.NoError(t, i.updateNPM())
updatedFile, err := ioutil.ReadFile(file.Name())
if err != nil {
t.Fatal(err)
}
assert.Equal(t, `{
"name": "test",
"version": "1.2.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"nx": "nx"
}
}`, string(updatedFile))
}

View File

@@ -8,10 +8,10 @@ import (
"github.com/Nightapes/go-semantic-release/internal/gitutil" "github.com/Nightapes/go-semantic-release/internal/gitutil"
"github.com/Nightapes/go-semantic-release/internal/shared" "github.com/Nightapes/go-semantic-release/internal/shared"
"github.com/Nightapes/go-semantic-release/pkg/config" "github.com/Nightapes/go-semantic-release/pkg/config"
"gopkg.in/src-d/go-git.v4" "github.com/go-git/go-git/v5"
gitConfig "gopkg.in/src-d/go-git.v4/config" gitConfig "github.com/go-git/go-git/v5/config"
"gopkg.in/src-d/go-git.v4/plumbing/object" "github.com/go-git/go-git/v5/plumbing/object"
"gopkg.in/src-d/go-git.v4/plumbing/transport/http" "github.com/go-git/go-git/v5/plumbing/transport/http"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
@@ -67,7 +67,12 @@ func (g *Client) GetCompareURL(oldVersion, newVersion string) string {
// CreateRelease creates release on remote // CreateRelease creates release on remote
func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog, _ *assets.Set) error { func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog, _ *assets.Set) error {
tag := "v" + releaseVersion.Next.Version.String() tagPrefix := config.DefaultTagPrefix
if g.config.TagPrefix != nil{
tagPrefix = *g.config.TagPrefix
}
tag := tagPrefix + releaseVersion.Next.Version.String()
g.log.Infof("create release with version %s", tag) g.log.Infof("create release with version %s", tag)
head, err := g.git.Repository.Head() head, err := g.git.Repository.Head()

View File

@@ -54,10 +54,13 @@ func New(c *config.GitHubProvider, checkConfig bool) (*Client, error) {
if c.CustomURL == "" { if c.CustomURL == "" {
client = github.NewClient(httpClient) client = github.NewClient(httpClient)
} else { } else {
if client, err = github.NewEnterpriseClient(c.CustomURL, c.CustomURL+"/api/v3/", httpClient); err != nil { // v25.0 of google github does not append prefixes for base and upload URLs
if client, err = github.NewEnterpriseClient(c.CustomURL+"/api/v3/", c.CustomURL+"/api/uploads/", httpClient); err != nil {
return &Client{}, err return &Client{}, err
} }
baseURL = c.CustomURL // note: do not append / to end of the url since all the url constructions using this
// assume no trailing /
baseURL = c.CustomURL + "/api/v3"
} }
return &Client{ return &Client{
config: c, config: c,
@@ -90,7 +93,11 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
// CreateRelease creates release on remote // CreateRelease creates release on remote
func (g *Client) makeRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error { func (g *Client) makeRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error {
tag := "v" + releaseVersion.Next.Version.String() tagPrefix := config.DefaultTagPrefix
if g.config.TagPrefix != nil {
tagPrefix = *g.config.TagPrefix
}
tag := tagPrefix + releaseVersion.Next.Version.String()
g.log.Debugf("create release with version %s", tag) g.log.Debugf("create release with version %s", tag)
prerelease := releaseVersion.Next.Version.Prerelease() != "" prerelease := releaseVersion.Next.Version.Prerelease() != ""
@@ -110,8 +117,8 @@ func (g *Client) makeRelease(releaseVersion *shared.ReleaseVersion, generatedCha
return fmt.Errorf("could not create release: %s", err.Error()) return fmt.Errorf("could not create release: %s", err.Error())
} }
g.release = release g.release = release
g.log.Debugf("Release repsone: %+v", *release) g.log.Debugf("Release response: %+v", *release)
g.log.Infof("Crated release") g.log.Infof("Created release")
return nil return nil
} }
@@ -128,15 +135,14 @@ func (g *Client) uploadAssets(assets *assets.Set) error {
if err != nil { if err != nil {
return err return err
} }
fileInfo, _ := file.Stat()
_, resp, err := g.client.Repositories.UploadReleaseAsset(g.context, g.config.User, g.config.Repo, g.release.GetID(), &github.UploadOptions{Name: fileInfo.Name()}, file) _, resp, err := g.client.Repositories.UploadReleaseAsset(g.context, g.config.User, g.config.Repo, g.release.GetID(), &github.UploadOptions{Name: asset.GetName()}, file)
if err != nil { if err != nil {
return err return err
} }
if resp.StatusCode >= http.StatusBadRequest { if resp.StatusCode >= http.StatusBadRequest {
return fmt.Errorf("could not upload asset %s: %s", file.Name(), resp.Status) return fmt.Errorf("could not upload asset %s: %s", asset.GetName(), resp.Status)
} }
} }
} }

View File

@@ -31,14 +31,14 @@ type testReleaseStruct struct {
} }
var testNewClient = []testHelperMethodStruct{ var testNewClient = []testHelperMethodStruct{
testHelperMethodStruct{config: config.GitHubProvider{ {config: config.GitHubProvider{
Repo: "foo", Repo: "foo",
User: "bar", User: "bar",
}, },
valid: true, valid: true,
}, },
testHelperMethodStruct{config: config.GitHubProvider{ {config: config.GitHubProvider{
Repo: "foo", Repo: "foo",
User: "bar", User: "bar",
CustomURL: "https://test.com", CustomURL: "https://test.com",
@@ -51,7 +51,7 @@ var lastVersion, _ = semver.NewVersion("1.0.0")
var newVersion, _ = semver.NewVersion("2.0.0") var newVersion, _ = semver.NewVersion("2.0.0")
var testReleases = []testReleaseStruct{ var testReleases = []testReleaseStruct{
testReleaseStruct{ {
config: config.GitHubProvider{ config: config.GitHubProvider{
Repo: "foo", Repo: "foo",
User: "bar", User: "bar",
@@ -75,7 +75,7 @@ var testReleases = []testReleaseStruct{
requestResponseCode: 200, requestResponseCode: 200,
valid: true, valid: true,
}, },
testReleaseStruct{ {
config: config.GitHubProvider{ config: config.GitHubProvider{
Repo: "foo", Repo: "foo",
User: "bar", User: "bar",
@@ -136,7 +136,7 @@ func TestGetCommitURL(t *testing.T) {
client, _ := New(&testOject.config, false) client, _ := New(&testOject.config, false)
actualURL := client.GetCommitURL() actualURL := client.GetCommitURL()
if testOject.config.CustomURL != "" { if testOject.config.CustomURL != "" {
expectedURL := fmt.Sprintf("%s/%s/%s/commit/{{hash}}", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo) expectedURL := fmt.Sprintf("%s/api/v3/%s/%s/commit/{{hash}}", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo)
assert.EqualValues(t, expectedURL, actualURL) assert.EqualValues(t, expectedURL, actualURL)
} else { } else {
@@ -154,7 +154,7 @@ func TestGetCompareURL(t *testing.T) {
client, _ := New(&testOject.config, false) client, _ := New(&testOject.config, false)
actualURL := client.GetCompareURL("1", "2") actualURL := client.GetCompareURL("1", "2")
if testOject.config.CustomURL != "" { if testOject.config.CustomURL != "" {
expectedURL := fmt.Sprintf("%s/%s/%s/compare/%s...%s", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo, "1", "2") expectedURL := fmt.Sprintf("%s/api/v3/%s/%s/compare/%s...%s", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo, "1", "2")
assert.EqualValues(t, expectedURL, actualURL) assert.EqualValues(t, expectedURL, actualURL)
} else { } else {

View File

@@ -98,7 +98,11 @@ func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedC
// CreateRelease creates release on remote // CreateRelease creates release on remote
func (g *Client) makeRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error { func (g *Client) makeRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error {
tag := "v" + releaseVersion.Next.Version.String() tagPrefix := config.DefaultTagPrefix
if g.config.TagPrefix != nil{
tagPrefix = *g.config.TagPrefix
}
tag := tagPrefix + releaseVersion.Next.Version.String()
g.Release = tag g.Release = tag
g.log.Infof("create release with version %s", tag) g.log.Infof("create release with version %s", tag)
url := fmt.Sprintf("%s/projects/%s/releases", g.apiURL, util.PathEscape(g.config.Repo)) url := fmt.Sprintf("%s/projects/%s/releases", g.apiURL, util.PathEscape(g.config.Repo))
@@ -148,9 +152,7 @@ func (g *Client) uploadAssets(assets *assets.Set) error {
} }
defer file.Close() defer file.Close()
fileInfo, _ := file.Stat() result, err := g.uploadFile(asset.GetName(), file)
result, err := g.uploadFile(fileInfo.Name(), file)
if err != nil { if err != nil {
return fmt.Errorf("could not upload asset %s: %s", file.Name(), err.Error()) return fmt.Errorf("could not upload asset %s: %s", file.Name(), err.Error())
} }
@@ -159,7 +161,7 @@ func (g *Client) uploadAssets(assets *assets.Set) error {
g.log.Infof("Uploaded file %s to gitlab can be downloaded under %s", file.Name(), downloadURL) g.log.Infof("Uploaded file %s to gitlab can be downloaded under %s", file.Name(), downloadURL)
uploadURL := fmt.Sprintf("%s/projects/%s/releases/%s/assets/links?name=%s&url=%s", g.apiURL, util.PathEscape(g.config.Repo), g.Release, util.PathEscape(fileInfo.Name()), downloadURL) uploadURL := fmt.Sprintf("%s/projects/%s/releases/%s/assets/links?name=%s&url=%s", g.apiURL, util.PathEscape(g.config.Repo), g.Release, util.PathEscape(asset.GetName()), downloadURL)
req, err := http.NewRequest("POST", uploadURL, nil) req, err := http.NewRequest("POST", uploadURL, nil)
if err != nil { if err != nil {

View File

@@ -22,29 +22,29 @@ func TestGetCommitURL(t *testing.T) {
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX") os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
defer os.Unsetenv("GITLAB_ACCESS_TOKEN") defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
client, err := New(&config.GitLabProvider{ client, err := New(&config.GitLabProvider{
CustomURL: "https://localhost/", CustomURL: "https://127.0.0.1/",
Repo: "test/test", Repo: "test/test",
}, true) }, true)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "https://localhost/test/test/commit/{{hash}}", client.GetCommitURL()) assert.Equal(t, "https://127.0.0.1/test/test/commit/{{hash}}", client.GetCommitURL())
} }
func TestGetCompareURL(t *testing.T) { func TestGetCompareURL(t *testing.T) {
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX") os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
defer os.Unsetenv("GITLAB_ACCESS_TOKEN") defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
client, err := New(&config.GitLabProvider{ client, err := New(&config.GitLabProvider{
CustomURL: "https://localhost/", CustomURL: "https://127.0.0.1/",
Repo: "test/test", Repo: "test/test",
}, true) }, true)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "https://localhost/test/test/compare/1.0.0...1.0.1", client.GetCompareURL("1.0.0", "1.0.1")) assert.Equal(t, "https://127.0.0.1/test/test/compare/1.0.0...1.0.1", client.GetCompareURL("1.0.0", "1.0.1"))
} }
func TestValidateConfig_EmptyRepro(t *testing.T) { func TestValidateConfig_EmptyRepro(t *testing.T) {
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX") os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
defer os.Unsetenv("GITLAB_ACCESS_TOKEN") defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
_, err := New(&config.GitLabProvider{ _, err := New(&config.GitLabProvider{
CustomURL: "https://localhost/", CustomURL: "https://127.0.0.1/",
}, true) }, true)
assert.Error(t, err) assert.Error(t, err)
} }
@@ -53,7 +53,7 @@ func TestValidateConfig_DefaultURL(t *testing.T) {
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX") os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
defer os.Unsetenv("GITLAB_ACCESS_TOKEN") defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
config := &config.GitLabProvider{ config := &config.GitLabProvider{
Repo: "localhost/test", Repo: "127.0.0.1/test",
} }
_, err := New(config, true) _, err := New(config, true)
assert.NoError(t, err) assert.NoError(t, err)
@@ -64,13 +64,13 @@ func TestValidateConfig_CustomURL(t *testing.T) {
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX") os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
defer os.Unsetenv("GITLAB_ACCESS_TOKEN") defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
config := &config.GitLabProvider{ config := &config.GitLabProvider{
Repo: "/localhost/test/", Repo: "/127.0.0.1/test/",
CustomURL: "https://localhost/", CustomURL: "https://127.0.0.1/",
} }
_, err := New(config, true) _, err := New(config, true)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "https://localhost", config.CustomURL) assert.Equal(t, "https://127.0.0.1", config.CustomURL)
assert.Equal(t, "localhost/test", config.Repo) assert.Equal(t, "127.0.0.1/test", config.Repo)
} }
func TestCreateRelease(t *testing.T) { func TestCreateRelease(t *testing.T) {
@@ -239,7 +239,7 @@ func TestUploadAssets(t *testing.T) {
valid: true, valid: true,
testDir: os.TempDir(), testDir: os.TempDir(),
assets: []config.Asset{ assets: []config.Asset{
config.Asset{ {
Name: filepath.Base(file.Name()), Name: filepath.Base(file.Name()),
Compress: false, Compress: false,
}, },
@@ -258,7 +258,7 @@ func TestUploadAssets(t *testing.T) {
valid: false, valid: false,
testDir: os.TempDir(), testDir: os.TempDir(),
assets: []config.Asset{ assets: []config.Asset{
config.Asset{ {
Name: filepath.Base(file.Name()), Name: filepath.Base(file.Name()),
Compress: false, Compress: false,
}, },
@@ -277,7 +277,7 @@ func TestUploadAssets(t *testing.T) {
valid: false, valid: false,
testDir: os.TempDir(), testDir: os.TempDir(),
assets: []config.Asset{ assets: []config.Asset{
config.Asset{ {
Name: filepath.Base(file.Name()), Name: filepath.Base(file.Name()),
Compress: false, Compress: false,
}, },

View File

@@ -30,8 +30,8 @@ type testDoubleToken struct {
} }
var testDoubles = []testDoubleToken{ var testDoubles = []testDoubleToken{
testDoubleToken{providerName: "test0", token: "foo", valid: true}, {providerName: "test0", token: "foo", valid: true},
testDoubleToken{providerName: "test1", token: "", valid: false}, {providerName: "test1", token: "", valid: false},
} }
func TestGetAccessToken(t *testing.T) { func TestGetAccessToken(t *testing.T) {
@@ -59,7 +59,7 @@ func TestIsValidResult(t *testing.T) {
assert.NoError(t, util.IsValidResult(&http.Response{StatusCode: 202})) assert.NoError(t, util.IsValidResult(&http.Response{StatusCode: 202}))
assert.NoError(t, util.IsValidResult(&http.Response{StatusCode: 204})) assert.NoError(t, util.IsValidResult(&http.Response{StatusCode: 204}))
u, err := url.Parse("https://localhost") u, err := url.Parse("https://127.0.0.1")
assert.NoError(t, err) assert.NoError(t, err)
assert.Error(t, util.IsValidResult(&http.Response{StatusCode: 500, Request: &http.Request{ assert.Error(t, util.IsValidResult(&http.Response{StatusCode: 500, Request: &http.Request{
Method: "POST", Method: "POST",

View File

@@ -35,13 +35,22 @@ type ChangelogTemplateConfig struct {
//AnalyzedCommit struct //AnalyzedCommit struct
type AnalyzedCommit struct { type AnalyzedCommit struct {
Commit Commit `yaml:"commit"` Commit Commit `yaml:"commit"`
ParsedMessage string `yaml:"parsedMessage"` ParsedMessage string `yaml:"parsedMessage"`
Scope Scope `yaml:"scope"` ParsedBreakingChangeMessage string `yaml:"parsedBreakingChangeMessage"`
ParsedBreakingChangeMessage string `yaml:"parsedBreakingChangeMessage"` Tag string `yaml:"tag"`
Tag string `yaml:"tag"` TagString string `yaml:"tagString"`
TagString string `yaml:"tagString"` Scope Scope `yaml:"scope"`
Print bool `yaml:"print"` Subject string `yaml:"subject"`
MessageBlocks map[string][]MessageBlock `yaml:"messageBlocks"`
IsBreaking bool `yaml:"isBreaking"`
Print bool `yaml:"print"`
}
// MessageBlock represents a block in the body section of a commit message
type MessageBlock struct {
Label string `yaml:"label"`
Content string `yaml:"content"`
} }
//Scope of the commit, like feat, fix,.. //Scope of the commit, like feat, fix,..

View File

@@ -9,13 +9,24 @@ import (
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
const (
DefaultTagPrefix = "v"
)
// AnalyzerConfig struct
type AnalyzerConfig struct {
TokenSeparators []string `yaml:"tokenSeparators"`
}
// ChangelogConfig struct // ChangelogConfig struct
type ChangelogConfig struct { type ChangelogConfig struct {
PrintAll bool `yaml:"printAll,omitempty"` PrintAll bool `yaml:"printAll,omitempty"`
TemplateTitle string `yaml:"title,omitempty"` TemplateTitle string `yaml:"title,omitempty"`
TemplatePath string `yaml:"templatePath,omitempty"` TemplatePath string `yaml:"templatePath,omitempty"`
Docker ChangelogDocker `yaml:"docker,omitempty"` ShowBodyAsHeader bool `yaml:"showBodyAsHeader,omitempty"`
NPM ChangelogNPM `yaml:"npm,omitempty"` ShowAuthors bool `yaml:"showAuthors,omitempty"`
Docker ChangelogDocker `yaml:"docker,omitempty"`
NPM ChangelogNPM `yaml:"npm,omitempty"`
} }
//ChangelogDocker type struct //ChangelogDocker type struct
@@ -26,8 +37,8 @@ type ChangelogDocker struct {
//ChangelogNPM type struct //ChangelogNPM type struct
type ChangelogNPM struct { type ChangelogNPM struct {
YARN bool `yaml:"latest"` Repository string `yaml:"repository"`
Repository string `yaml:"repository"` PackageName string `yaml:"name"`
} }
//Asset type struct //Asset type struct
@@ -44,6 +55,7 @@ type GitHubProvider struct {
User string `yaml:"user"` User string `yaml:"user"`
CustomURL string `yaml:"customUrl,omitempty"` CustomURL string `yaml:"customUrl,omitempty"`
AccessToken string AccessToken string
TagPrefix *string `yaml:"tagPrefix,omitempty"`
} }
// GitLabProvider struct // GitLabProvider struct
@@ -51,14 +63,16 @@ type GitLabProvider struct {
Repo string `yaml:"repo"` Repo string `yaml:"repo"`
CustomURL string `yaml:"customUrl,omitempty"` CustomURL string `yaml:"customUrl,omitempty"`
AccessToken string AccessToken string
TagPrefix *string `yaml:"tagPrefix,omitempty"`
} }
// GitProvider struct // GitProvider struct
type GitProvider struct { type GitProvider struct {
Email string `yaml:"email"` Email string `yaml:"email"`
Username string `yaml:"user"` Username string `yaml:"user"`
Auth string `yaml:"auth"` Auth string `yaml:"auth"`
SSH bool `yaml:"ssh"` SSH bool `yaml:"ssh"`
TagPrefix *string `yaml:"tagPrefix,omitempty"`
} }
// Hooks struct // Hooks struct
@@ -72,10 +86,22 @@ type Checksum struct {
Algorithm string `yaml:"algorithm"` Algorithm string `yaml:"algorithm"`
} }
// Checksum struct
type Integrations struct {
NPM IntegrationNPM `yaml:"npm"`
}
// Checksum struct
type IntegrationNPM struct {
Enabled bool `yaml:"enabled"`
Path string `yaml:"path"`
}
// ReleaseConfig struct // ReleaseConfig struct
type ReleaseConfig struct { type ReleaseConfig struct {
CommitFormat string `yaml:"commitFormat"` CommitFormat string `yaml:"commitFormat"`
Branch map[string]string `yaml:"branch"` Branch map[string]string `yaml:"branch"`
Analyzer AnalyzerConfig `yaml:"analyzer"`
Changelog ChangelogConfig `yaml:"changelog,omitempty"` Changelog ChangelogConfig `yaml:"changelog,omitempty"`
Release string `yaml:"release,omitempty"` Release string `yaml:"release,omitempty"`
GitHubProvider GitHubProvider `yaml:"github,omitempty"` GitHubProvider GitHubProvider `yaml:"github,omitempty"`
@@ -84,6 +110,7 @@ type ReleaseConfig struct {
Assets []Asset `yaml:"assets"` Assets []Asset `yaml:"assets"`
Checksum Checksum `yaml:"checksum,omitempty"` Checksum Checksum `yaml:"checksum,omitempty"`
Hooks Hooks `yaml:"hooks"` Hooks Hooks `yaml:"hooks"`
Integrations Integrations `yaml:"integrations"`
ReleaseTitle string `yaml:"title"` ReleaseTitle string `yaml:"title"`
IsPreRelease bool IsPreRelease bool
} }

View File

@@ -95,11 +95,12 @@ github:
}, },
}, },
Assets: []config.Asset{ Assets: []config.Asset{
config.Asset{ {
Name: "./build/go-semantic-release", Name: "./build/go-semantic-release",
Compress: false}}, Compress: false}},
ReleaseTitle: "go-semantic-release release", ReleaseTitle: "go-semantic-release release",
IsPreRelease: false, IsPreRelease: false,
Analyzer: config.AnalyzerConfig{TokenSeparators: []string{}},
}, result) }, result)
} }

View File

@@ -1,10 +1,18 @@
package semanticrelease package semanticrelease
import ( import (
"io/ioutil" "fmt"
"github.com/go-git/go-git/v5/plumbing"
"os"
"path/filepath"
"strings"
"time" "time"
"github.com/Nightapes/go-semantic-release/internal/integrations"
"github.com/Masterminds/semver" "github.com/Masterminds/semver"
log "github.com/sirupsen/logrus"
"github.com/Nightapes/go-semantic-release/internal/analyzer" "github.com/Nightapes/go-semantic-release/internal/analyzer"
"github.com/Nightapes/go-semantic-release/internal/assets" "github.com/Nightapes/go-semantic-release/internal/assets"
"github.com/Nightapes/go-semantic-release/internal/cache" "github.com/Nightapes/go-semantic-release/internal/cache"
@@ -16,13 +24,12 @@ import (
"github.com/Nightapes/go-semantic-release/internal/releaser" "github.com/Nightapes/go-semantic-release/internal/releaser"
"github.com/Nightapes/go-semantic-release/internal/shared" "github.com/Nightapes/go-semantic-release/internal/shared"
"github.com/Nightapes/go-semantic-release/pkg/config" "github.com/Nightapes/go-semantic-release/pkg/config"
log "github.com/sirupsen/logrus"
) )
// SemanticRelease struct // SemanticRelease struct
type SemanticRelease struct { type SemanticRelease struct {
config *config.ReleaseConfig config *config.ReleaseConfig
gitutil *gitutil.GitUtil gitUtil *gitutil.GitUtil
analyzer *analyzer.Analyzer analyzer *analyzer.Analyzer
calculator *calculator.Calculator calculator *calculator.Calculator
releaser releaser.Releaser releaser releaser.Releaser
@@ -38,7 +45,7 @@ func New(c *config.ReleaseConfig, repository string, checkConfig bool) (*Semanti
return nil, err return nil, err
} }
analyzer, err := analyzer.New(c.CommitFormat, c.Changelog) analyzer, err := analyzer.New(c.CommitFormat, c.Analyzer, c.Changelog)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -56,7 +63,7 @@ func New(c *config.ReleaseConfig, repository string, checkConfig bool) (*Semanti
return &SemanticRelease{ return &SemanticRelease{
config: c, config: c,
gitutil: util, gitUtil: util,
releaser: releaser, releaser: releaser,
analyzer: analyzer, analyzer: analyzer,
repository: repository, repository: repository,
@@ -66,15 +73,15 @@ func New(c *config.ReleaseConfig, repository string, checkConfig bool) (*Semanti
}, nil }, nil
} }
//GetCIProvider result with ci config // GetCIProvider result with ci config
func (s *SemanticRelease) GetCIProvider() (*ci.ProviderConfig, error) { func (s *SemanticRelease) GetCIProvider() (*ci.ProviderConfig, error) {
return ci.GetCIProvider(s.gitutil, s.checkConfig, ci.ReadAllEnvs()) return ci.GetCIProvider(s.gitUtil, s.checkConfig, ci.ReadAllEnvs())
} }
// GetNextVersion from .version or calculate new from commits // GetNextVersion from .version or calculate new from commits
func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool) (*shared.ReleaseVersion, error) { func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool, from string) (*shared.ReleaseVersion, error) {
log.Debugf("Ignore .version file if exits, %t", force) log.Debugf("Ignore .version file if exits, %t", force)
if !force { if !force && from == "" {
releaseVersion, err := cache.Read(s.repository) releaseVersion, err := cache.Read(s.repository)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -85,9 +92,20 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
} }
} }
lastVersion, lastVersionHash, err := s.gitutil.GetLastVersion() var lastVersion *semver.Version
if err != nil { var lastVersionHash *plumbing.Reference
return nil, err var err error
if from == "" {
lastVersion, lastVersionHash, err = s.gitUtil.GetLastVersion()
if err != nil {
return nil, err
}
} else {
lastVersion, lastVersionHash, err = s.gitUtil.GetVersion(from)
if err != nil {
return nil, err
}
} }
firstRelease := false firstRelease := false
@@ -98,9 +116,9 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
firstRelease = true firstRelease = true
} }
commits, err := s.gitutil.GetCommits(lastVersionHash) commits, err := s.gitUtil.GetCommits(lastVersionHash)
if err != nil { if err != nil {
return nil, err return nil, fmt.Errorf("could not get commits %w", err)
} }
log.Debugf("Found %d commits till last release", len(commits)) log.Debugf("Found %d commits till last release", len(commits))
@@ -129,12 +147,15 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
Version: &newVersion, Version: &newVersion,
}, },
Last: shared.ReleaseVersionEntry{ Last: shared.ReleaseVersionEntry{
Commit: lastVersionHash, Commit: "",
Version: lastVersion, Version: lastVersion,
}, },
Branch: provider.Branch, Branch: provider.Branch,
Commits: analyzedCommits, Commits: analyzedCommits,
} }
if lastVersionHash != nil {
releaseVersion.Last.Commit = lastVersionHash.Hash().String()
}
if firstRelease { if firstRelease {
releaseVersion.Last.Version, _ = semver.NewVersion("0.0.0") releaseVersion.Last.Version, _ = semver.NewVersion("0.0.0")
@@ -148,15 +169,14 @@ func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool
return &releaseVersion, err return &releaseVersion, err
} }
//SetVersion for git repository // SetVersion for git repository
func (s *SemanticRelease) SetVersion(provider *ci.ProviderConfig, version string) error { func (s *SemanticRelease) SetVersion(provider *ci.ProviderConfig, version string) error {
newVersion, err := semver.NewVersion(version) newVersion, err := semver.NewVersion(version)
if err != nil { if err != nil {
return err return err
} }
lastVersion, lastVersionHash, err := s.gitutil.GetLastVersion() lastVersion, lastVersionHash, err := s.gitUtil.GetLastVersion()
if err != nil { if err != nil {
return err return err
} }
@@ -170,7 +190,7 @@ func (s *SemanticRelease) SetVersion(provider *ci.ProviderConfig, version string
Version: newVersion, Version: newVersion,
}, },
Last: shared.ReleaseVersionEntry{ Last: shared.ReleaseVersionEntry{
Commit: lastVersionHash, Commit: lastVersionHash.Hash().String(),
Version: lastVersion, Version: lastVersion,
}, },
Branch: provider.Branch, Branch: provider.Branch,
@@ -180,23 +200,94 @@ func (s *SemanticRelease) SetVersion(provider *ci.ProviderConfig, version string
// GetChangelog from last version till now // GetChangelog from last version till now
func (s *SemanticRelease) GetChangelog(releaseVersion *shared.ReleaseVersion) (*shared.GeneratedChangelog, error) { func (s *SemanticRelease) GetChangelog(releaseVersion *shared.ReleaseVersion) (*shared.GeneratedChangelog, error) {
c := changelog.New(s.config, s.analyzer.GetRules(), time.Now()) c := changelog.New(s.config, s.analyzer.GetRules(), time.Now())
return c.GenerateChanglog(shared.ChangelogTemplateConfig{ return c.GenerateChangelog(shared.ChangelogTemplateConfig{
Version: releaseVersion.Next.Version.String(), Version: releaseVersion.Next.Version.String(),
Hash: releaseVersion.Last.Commit, Hash: releaseVersion.Last.Commit,
CommitURL: s.releaser.GetCommitURL(), CommitURL: s.releaser.GetCommitURL(),
CompareURL: s.releaser.GetCompareURL(releaseVersion.Last.Version.String(), releaseVersion.Next.Version.String()), CompareURL: s.releaser.GetCompareURL(releaseVersion.Last.Version.String(), releaseVersion.Next.Version.String()),
}, releaseVersion.Commits) }, releaseVersion.Commits)
} }
// WriteChangeLog wirtes changelog content to the given file // WriteChangeLog writes changelog content to the given file
func (s *SemanticRelease) WriteChangeLog(changelogContent, file string) error { func (s *SemanticRelease) WriteChangeLog(changelogContent, file string, overwrite bool, maxChangelogFileSize int64) error {
return ioutil.WriteFile(file, []byte(changelogContent), 0644) info, err := os.Stat(file)
if overwrite || err != nil {
return os.WriteFile(file, []byte(changelogContent), 0644)
}
if bytesToMB(info.Size()) >= float64(maxChangelogFileSize) {
err := moveExistingChangelogFile(file)
if err != nil {
return err
}
}
return prependToFile(changelogContent, file)
}
func bytesToMB(bytes int64) float64 {
return float64(bytes) / 1024 / 1024 / 1024
}
func moveExistingChangelogFile(file string) error {
filenameSeparated := strings.Split(filepath.Base(file), ".")
// check if file had several "." included.
// if yes the filename will be separated like this: "my.file.name", ".md"
if len(filenameSeparated) > 2 {
separatedFilenameWithExtension := make([]string, 0)
separatedFilenameWithExtension = append(separatedFilenameWithExtension, strings.Join(filenameSeparated[:len(filenameSeparated)-1], "."))
separatedFilenameWithExtension = append(separatedFilenameWithExtension, filenameSeparated[len(filenameSeparated)-1])
filenameSeparated = separatedFilenameWithExtension
}
var newFileName string
counter := 1
for {
newFileName = buildNewFileName(filenameSeparated, counter)
if _, err := os.Stat(newFileName); err != nil {
break
}
counter++
}
content, err := os.ReadFile(file)
if err != nil {
return err
}
err = os.WriteFile(newFileName, content, 0666)
if err != nil {
return err
}
_, err = os.Create(file)
return err
}
func buildNewFileName(currentFileNameSeparated []string, counter int) string {
if len(currentFileNameSeparated) == 1 {
return fmt.Sprintf("%s-%d", currentFileNameSeparated[0], counter)
}
fileNameWithoutExtension := strings.Join(currentFileNameSeparated[:len(currentFileNameSeparated)-1], ".")
fileExtension := currentFileNameSeparated[len(currentFileNameSeparated)-1]
return fmt.Sprintf("%s-%d.%s", fileNameWithoutExtension, counter, fileExtension)
}
func prependToFile(newChangelogContent, file string) error {
currentContent, err := os.ReadFile(file)
if err != nil {
return err
}
content := make([]byte, 0)
content = append(content, []byte(newChangelogContent)...)
content = append(content, []byte("\n---\n\n")...)
content = append(content, currentContent...)
return os.WriteFile(file, content, 0644)
} }
// Release publish release to provider // Release publish release to provider
func (s *SemanticRelease) Release(provider *ci.ProviderConfig, force bool) error { func (s *SemanticRelease) Release(provider *ci.ProviderConfig, force bool) error {
if provider.IsPR { if provider.IsPR {
log.Infof("Will not perform a new release. This is a pull request") log.Infof("Will not perform a new release. This is a pull request")
return nil return nil
@@ -211,7 +302,7 @@ func (s *SemanticRelease) Release(provider *ci.ProviderConfig, force bool) error
return err return err
} }
releaseVersion, err := s.GetNextVersion(provider, force) releaseVersion, err := s.GetNextVersion(provider, force, "")
if err != nil { if err != nil {
log.Debugf("Could not get next version") log.Debugf("Could not get next version")
return err return err
@@ -228,7 +319,9 @@ func (s *SemanticRelease) Release(provider *ci.ProviderConfig, force bool) error
return err return err
} }
if err := s.assets.GenerateChecksum(); err != nil { integrations := integrations.New(&s.config.Integrations, releaseVersion)
if err := integrations.Run(); err != nil {
log.Debugf("Error during integrations run")
return err return err
} }
@@ -238,6 +331,20 @@ func (s *SemanticRelease) Release(provider *ci.ProviderConfig, force bool) error
return err return err
} }
if s.config.Checksum.Algorithm != "" {
if err := s.assets.GenerateChecksum(); err != nil {
return err
}
}
for _, asset := range s.assets.All() {
if asset.IsCompressed() {
if _, err := asset.ZipFile(); err != nil {
return err
}
}
}
if err = s.releaser.CreateRelease(releaseVersion, generatedChangelog, s.assets); err != nil { if err = s.releaser.CreateRelease(releaseVersion, generatedChangelog, s.assets); err != nil {
return err return err
} }

View File

@@ -0,0 +1,83 @@
package semanticrelease
import (
"os"
"path/filepath"
"strings"
"testing"
"github.com/Nightapes/go-semantic-release/pkg/config"
)
func TestSemanticRelease_WriteChangeLog(t *testing.T) {
type args struct {
changelogContent string
file string
overwrite bool
maxChangelogFileSize int64
}
tests := []struct {
config *config.ReleaseConfig
name string
args args
wantErr bool
}{
{
name: "MoveExisting",
args: args{
changelogContent: "go-semantic-release-rocks!",
file: "test1.changelog.md",
overwrite: false,
maxChangelogFileSize: 0,
},
wantErr: false,
},
{
name: "ValidWithOverwrite",
args: args{
changelogContent: "go-semantic-release-rocks!",
file: "test2.changelog.md",
overwrite: true,
maxChangelogFileSize: 0,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := os.Create(tt.args.file)
if err != nil {
t.Error(err)
}
releaser := &SemanticRelease{}
if err := releaser.WriteChangeLog(tt.args.changelogContent, tt.args.file, tt.args.overwrite, tt.args.maxChangelogFileSize); (err != nil) != tt.wantErr {
t.Errorf("WriteChangeLog() error = %v, wantErr %v", err, tt.wantErr)
}
name := strings.Join(strings.Split(tt.args.file, ".")[:len(strings.Split(tt.args.file, "."))-1], ".")
files, err := filepath.Glob("./" + name + "*")
if err != nil {
t.Error(err)
}
if !tt.wantErr && !tt.args.overwrite && tt.args.maxChangelogFileSize == 0 && len(files) <= 1 {
t.Errorf("WriteChangelog() = should create a copy of the existing changelog file")
}
if !tt.wantErr && tt.args.overwrite && len(files) > 1 {
t.Errorf("WriteChangelog() = should not create a copy of the changelog file")
}
for _, i := range files {
err := os.Remove(i)
if err != nil {
t.Error(err)
}
}
})
}
}