You've already forked go-semantic-release
Compare commits
244 Commits
1.0.0-alph
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 8a8e746159 | |||
| ff1798b10b | |||
| fa40e6ee71 | |||
| 8a05b72ec8 | |||
| 732b1ee1a0 | |||
| 5636fecc14 | |||
| b13699d2f8 | |||
| f7f395c30f | |||
| 0bcede8594 | |||
| 34589749ba | |||
| b38abd00f2 | |||
| 913783cf08 | |||
| d701ce2352 | |||
| 4d0d1e4319 | |||
| c4cecdebb4 | |||
| ad8d69452d | |||
| 7f8ed11f79 | |||
| 6d1f8f0a9a | |||
| 3a93293318 | |||
| 1712dbdbaf | |||
| a442a82d15 | |||
| 70b6cbe8df | |||
| c981a99424 | |||
| a2b32024a1 | |||
| 8f5e47eecd | |||
| 274cabf05a | |||
| 77fb819342 | |||
| 0b309228d3 | |||
| 141f297c87 | |||
| 2236fe923c | |||
|
|
ade0e49736 | ||
|
|
ca6488ee78 | ||
|
|
979a378abd | ||
|
|
2c8d2d9ade | ||
|
|
8acb8b74b8 | ||
|
|
fd1063132f | ||
|
|
1d0c93b678 | ||
|
|
0c7338ab13 | ||
|
|
03f2eeadaa | ||
|
|
bcb21d917d | ||
|
|
ea2fbfba3d | ||
|
|
c5f993e7de | ||
|
|
ec8dc17df2 | ||
|
|
9e40e81fea | ||
|
|
2782fb5d03 | ||
|
|
0800219d60 | ||
|
|
f89150b698 | ||
|
|
780a6dbc2e | ||
|
|
2d7977993b | ||
|
|
9d7edbf756 | ||
|
|
d9e2f36927 | ||
|
|
a6783f23bd | ||
|
|
fbb3684f68 | ||
|
|
9bc3143f53 | ||
|
|
7b93801e88 | ||
|
|
749bbf720b | ||
|
|
d9e5dc4515 | ||
|
|
d66364e474 | ||
|
|
2fc6145149 | ||
|
|
a054cf9a60 | ||
|
|
155a16ddd5 | ||
|
|
d7878222bb | ||
|
|
f79466b238 | ||
|
|
5225b12c00 | ||
|
|
2cd24777b3 | ||
|
|
cb3084d0b7 | ||
|
|
795f5d54ef | ||
|
|
382cb54bcb | ||
|
|
3bc68d9794 | ||
|
|
c7d6c7cc7b | ||
|
|
47a54436f5 | ||
|
|
deed3a630e | ||
|
|
df058a927f | ||
|
|
5a58d039fb | ||
|
|
08ab3af547 | ||
|
|
7208daed1f | ||
|
|
a20992af14 | ||
|
|
dc4d1c581a | ||
|
|
81bdb68ee4 | ||
|
|
c485c3ee85 | ||
|
|
86c9512479 | ||
|
|
4574d00c28 | ||
|
|
0c4310d60b | ||
|
|
3a37a5e1db | ||
|
|
9594f39caa | ||
|
|
b9cbbd435f | ||
|
|
564c033cbb | ||
|
|
3deead130c | ||
|
|
ac1bb779bb | ||
|
|
6cd43d7957 | ||
|
|
450383bdbf | ||
|
|
d6c5e395a8 | ||
|
|
3731fa6e55 | ||
|
|
8db8b0d72c | ||
|
|
15a17e546b | ||
|
|
037983df1e | ||
|
|
01af837b40 | ||
|
|
0f1275fc30 | ||
|
|
115bc85d8d | ||
|
|
dee85c6877 | ||
|
|
ccfce5e135 | ||
|
|
8ffc0804ec | ||
|
|
348ea6607e | ||
|
|
00cbfd39a2 | ||
|
|
0cbc7a7885 | ||
|
|
1bc0185f70 | ||
|
|
f0ebb03e46 | ||
|
|
cc22d5d4db | ||
|
|
c84b51d18c | ||
|
|
11acc95a34 | ||
|
|
be35b743b4 | ||
|
|
322455b6d4 | ||
|
|
400a25f950 | ||
|
|
92600059c2 | ||
|
|
666716d627 | ||
|
|
6fd34d3e0a | ||
|
|
cc957cb3f2 | ||
|
|
cf87c74d1d | ||
|
|
0aa8146902 | ||
|
|
632e6ea2d3 | ||
|
|
460710ff39 | ||
|
|
ba59e8db63 | ||
|
|
5c5ca98978 | ||
|
|
9954e67e88 | ||
|
|
4f728a7984 | ||
|
|
a76aec25dd | ||
|
|
1b3687a99d | ||
|
|
875dbdcfc4 | ||
|
|
2208427b65 | ||
|
|
5cb83dead4 | ||
|
|
343e660e8e | ||
|
|
95bef6cb2d | ||
|
|
a6dcad2b69 | ||
|
|
af5c8f5ae3 | ||
|
|
c361744a35 | ||
|
|
6a375f3bab | ||
|
|
d4627a9d46 | ||
|
|
af2addbffd | ||
|
|
7157d64b7b | ||
|
|
575ba5d5bd | ||
|
|
a8b68f9182 | ||
|
|
f6a2d837b1 | ||
|
|
279509c922 | ||
|
|
d0035d6bca | ||
|
|
1342714579 | ||
|
|
d92438b339 | ||
|
|
aff2203d66 | ||
|
|
113ddf2b1f | ||
|
|
8e3c446605 | ||
|
|
8ea92efb90 | ||
|
|
42fc522a43 | ||
|
|
6211095c38 | ||
|
|
74e895b5ad | ||
|
|
a69da92340 | ||
|
|
ff87725801 | ||
|
|
272a9b6e89 | ||
|
|
07b606a21a | ||
|
|
44f95969bf | ||
|
|
399a3515f2 | ||
|
|
2074877a3b | ||
|
|
b5551d8432 | ||
|
|
c92020d3ac | ||
|
|
d9f2b163c7 | ||
|
|
4379551982 | ||
|
|
3eb13972ec | ||
|
|
8659b40960 | ||
|
|
7ead374039 | ||
|
|
ee1dc3d8db | ||
|
|
38e4c178ee | ||
|
|
e22d3d07f4 | ||
|
|
46ae2da821 | ||
|
|
e3265b1843 | ||
|
|
d03913e6d7 | ||
|
|
e5ed8edb75 | ||
|
|
76ffeda95b | ||
|
|
0994354089 | ||
|
|
e8d7feeca3 | ||
|
|
e0974e3140 | ||
|
|
8643656339 | ||
|
|
829f2925ab | ||
|
|
7729ba5914 | ||
|
|
72200582fd | ||
|
|
2c26c8aa6d | ||
|
|
4b72df07c8 | ||
|
|
df544f5be7 | ||
|
|
812723e1f4 | ||
|
|
e91d9b0dac | ||
|
|
a2fc03c64d | ||
|
|
e419086dbe | ||
|
|
4c7cfd5e90 | ||
|
|
89f4842a2b | ||
|
|
7857b5f6f3 | ||
|
|
115964c9c1 | ||
|
|
2f2f7e51fb | ||
|
|
f1bb5470c0 | ||
|
|
be1e483baa | ||
|
|
17f1890ca1 | ||
|
|
6a53c3e587 | ||
|
|
a068e65369 | ||
|
|
9e847c6af9 | ||
|
|
2eb64f153a | ||
|
|
a6c651a97f | ||
|
|
e0a4725f06 | ||
|
|
9cf4eab1d2 | ||
|
|
6a514158ce | ||
|
|
f30c508f2a | ||
|
|
7b16b164f2 | ||
|
|
0fd39c72a0 | ||
|
|
0e61bf7651 | ||
|
|
829fea1282 | ||
|
|
467ae1f87e | ||
|
|
5791d3b41c | ||
|
|
92b42c8ffa | ||
|
|
0bffe32a24 | ||
|
|
fab3fc030e | ||
|
|
42a6a5fcf0 | ||
|
|
2f20d8c31c | ||
|
|
ec10557cb1 | ||
|
|
c9d9420037 | ||
|
|
ff82ec7acd | ||
|
|
428514a1ef | ||
|
|
3bf84d5ad1 | ||
|
|
0037abfaf7 | ||
|
|
703d4b803c | ||
|
|
c086b12f01 | ||
|
|
3c500142aa | ||
|
|
bdc4fb1d74 | ||
|
|
682fae3239 | ||
|
|
e170ca9885 | ||
|
|
a15eaa597a | ||
|
|
6bdbc2173f | ||
|
|
1daff2bc8a | ||
|
|
e222734a1a | ||
|
|
6267e1cc81 | ||
|
|
5986e2819a | ||
|
|
581b62d324 | ||
|
|
7d68d5835f | ||
|
|
7b4db67cb7 | ||
|
|
58f2ebb6d0 | ||
|
|
409b260eb7 | ||
|
|
791983faae | ||
|
|
69db52e5b1 | ||
|
|
ab14ab397c | ||
|
|
c86ad684c6 |
10
.dockerignore
Normal file
10
.dockerignore
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
*
|
||||||
|
!build/
|
||||||
|
!cmd/
|
||||||
|
!internal/
|
||||||
|
!pkg/
|
||||||
|
!scripts/
|
||||||
|
!Dockerfile*
|
||||||
|
!.dockerignore
|
||||||
|
!go.mod
|
||||||
|
!go.sum
|
||||||
11
.githooks/commit-msg
Executable file
11
.githooks/commit-msg
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Run the script and get the return code if successful of if fails
|
||||||
|
./scripts/commit-filter-check.sh && rc=$? || rc=$?
|
||||||
|
echo return code : $rc
|
||||||
|
if [ ${rc} = 1 ]; then
|
||||||
|
echo "Script return code 1 so commit failed"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "No error returned so commit successful"
|
||||||
|
fi
|
||||||
70
.github/workflows/codeql-analysis.yml
vendored
Normal file
70
.github/workflows/codeql-analysis.yml
vendored
Normal 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
|
||||||
88
.github/workflows/main.yml
vendored
Normal file
88
.github/workflows/main.yml
vendored
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
name: Go
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
go: ["1.18", "1.19"]
|
||||||
|
env:
|
||||||
|
DEFAULT_GO: "1.19"
|
||||||
|
name: Build with go version ${{ matrix.go }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set up GoLang ${{ matrix.go }}
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.go }}
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v3
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: go test ./...
|
||||||
|
|
||||||
|
- name: Build binary
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/
|
||||||
|
./build/go-semantic-release-temp next --no-cache --loglevel trace
|
||||||
|
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o build/go-semantic-release.linux_x86_64 -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=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 PR
|
||||||
|
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: |
|
||||||
|
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
docker login -u nightapes -p ${{ secrets.GITHUB_TOKEN }} docker.pkg.github.com
|
||||||
|
docker build -t nightapes/go-semantic-release:development-${{matrix.go}} .
|
||||||
|
docker push nightapes/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}}
|
||||||
|
- uses: actions/upload-artifact@v1
|
||||||
|
if: matrix.go == env.DEFAULT_GO
|
||||||
|
with:
|
||||||
|
name: build
|
||||||
|
path: build
|
||||||
|
release:
|
||||||
|
name: Release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
steps:
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
- uses: actions/download-artifact@v1
|
||||||
|
with:
|
||||||
|
name: build
|
||||||
|
path: build
|
||||||
|
- name: Release
|
||||||
|
if: github.ref == 'refs/heads/master'
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
chmod -R +x build
|
||||||
|
docker login -u nightapes -p ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
docker login -u nightapes -p $GITHUB_TOKEN docker.pkg.github.com
|
||||||
|
./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
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -15,3 +15,6 @@ go-semantic-release
|
|||||||
.version
|
.version
|
||||||
.vscode/settings.json
|
.vscode/settings.json
|
||||||
CHANGELOG.md
|
CHANGELOG.md
|
||||||
|
cover.html
|
||||||
|
build/
|
||||||
|
.idea/
|
||||||
|
|||||||
43
.release.yml
43
.release.yml
@@ -1,22 +1,29 @@
|
|||||||
|
release: "gitea"
|
||||||
|
gitea:
|
||||||
|
repo: "go-semantic-release"
|
||||||
|
user: "cybercinch"
|
||||||
|
url: "https://hub.cybercinch.nz"
|
||||||
commitFormat: angular
|
commitFormat: angular
|
||||||
title: "go-semantic-release release"
|
|
||||||
branch:
|
branch:
|
||||||
master: release
|
master: release
|
||||||
rc: rc
|
develop: beta
|
||||||
beta: beta
|
|
||||||
alpha: alpha
|
|
||||||
add_git_releases: alpha
|
|
||||||
changelog:
|
|
||||||
printAll: false
|
|
||||||
template: ''
|
|
||||||
templatePath: ''
|
|
||||||
release: 'github'
|
|
||||||
assets:
|
assets:
|
||||||
- name: ./build/go-semantic-release
|
- path: ./build/go-semantic-release.linux_amd64
|
||||||
compress: false
|
compress: true
|
||||||
- name: ./build/go-semantic-release.exe
|
- path: ./build/go-semantic-release.linux_arm64
|
||||||
compress: false
|
compress: true
|
||||||
github:
|
- path: ./build/go-semantic-release.windows_i386.exe
|
||||||
repo: "go-semantic-release"
|
compress: true
|
||||||
user: "nightapes"
|
- path: ./build/go-semantic-release.windows_amd64.exe
|
||||||
customUrl: ""
|
compress: true
|
||||||
|
- path: ./build/go-semantic-release.darwin_amd64
|
||||||
|
compress: true
|
||||||
|
changelog:
|
||||||
|
docker:
|
||||||
|
latest: true
|
||||||
|
repository: hub.cybercinch.nz/cybercinch/go-semantic-release
|
||||||
|
showAuthors: true
|
||||||
|
|
||||||
|
hooks:
|
||||||
|
preRelease: []
|
||||||
|
postRelease: []
|
||||||
|
|||||||
112
.woodpecker.yml
Normal file
112
.woodpecker.yml
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
variables:
|
||||||
|
- &platforms 'linux/arm64,linux/amd64'
|
||||||
|
- &docker_creds
|
||||||
|
username:
|
||||||
|
from_secret: hub_username_cybercinch
|
||||||
|
password:
|
||||||
|
from_secret: docker_password_cybercinch
|
||||||
|
- &pypi_creds
|
||||||
|
username:
|
||||||
|
from_secret: hub_username_cybercinch
|
||||||
|
password:
|
||||||
|
from_secret: docker_password_cybercinch
|
||||||
|
- build_args: &build_args
|
||||||
|
- TAG: ${CI_COMMIT_TAG}
|
||||||
|
clone:
|
||||||
|
git:
|
||||||
|
image: woodpeckerci/plugin-git
|
||||||
|
settings:
|
||||||
|
partial: false
|
||||||
|
tags: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
build-release:
|
||||||
|
image: docker.io/cybercinch/go-semrelease:golang1.20
|
||||||
|
pull: true
|
||||||
|
commands:
|
||||||
|
- >
|
||||||
|
GOOS=linux
|
||||||
|
GOARCH=amd64
|
||||||
|
CGO_ENABLED=0
|
||||||
|
GOFLAGS=-mod=vendor
|
||||||
|
go build -o build/go-semantic-release.linux_amd64 -ldflags "-w -s --X main.version=`go-semantic-release next`"
|
||||||
|
./cmd/go-semantic-release/
|
||||||
|
- >
|
||||||
|
GOOS=linux
|
||||||
|
GOARCH=arm64
|
||||||
|
CGO_ENABLED=0
|
||||||
|
GOFLAGS=-mod=vendor
|
||||||
|
go build -o build/go-semantic-release.linux_arm64 -ldflags "-w -s --X main.version=`go-semantic-release next`"
|
||||||
|
./cmd/go-semantic-release/
|
||||||
|
- >
|
||||||
|
GOOS=windows
|
||||||
|
GOARCH=386
|
||||||
|
CGO_ENABLED=0
|
||||||
|
GOFLAGS=-mod=vendor
|
||||||
|
go build -o build/go-semantic-release.windows_i386.exe -ldflags "-w -s -X main.version=`go-semantic-release next`"
|
||||||
|
./cmd/go-semantic-release/
|
||||||
|
- >
|
||||||
|
GOOS=windows
|
||||||
|
GOARCH=amd64
|
||||||
|
CGO_ENABLED=0
|
||||||
|
GOFLAGS=-mod=vendor
|
||||||
|
go build -o build/go-semantic-release.windows_amd64.exe -ldflags "-w -s -X main.version=`go-semantic-release next`"
|
||||||
|
./cmd/go-semantic-release/
|
||||||
|
- >
|
||||||
|
GOOS=darwin
|
||||||
|
GOARCH=amd64
|
||||||
|
CGO_ENABLED=0
|
||||||
|
GOFLAGS=-mod=vendor
|
||||||
|
go build -o build/go-semantic-release.darwin_amd64 -ldflags "-w -s -X main.version=`go-semantic-release next`"
|
||||||
|
./cmd/go-semantic-release/
|
||||||
|
- go-semantic-release --loglevel debug release # Actually make the release on Gitea. Uploading assets
|
||||||
|
environment:
|
||||||
|
GITEA_TOKEN:
|
||||||
|
from_secret: gitea_token
|
||||||
|
GITEA_URL:
|
||||||
|
from_secret: gitea_server_url
|
||||||
|
when:
|
||||||
|
branch: ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
- manual
|
||||||
|
|
||||||
|
publish-docker-tagged:
|
||||||
|
image: woodpeckerci/plugin-docker-buildx
|
||||||
|
pull: true
|
||||||
|
settings:
|
||||||
|
<<: *docker_creds
|
||||||
|
registry: hub.cybercinch.nz
|
||||||
|
repo: hub.cybercinch.nz/cybercinch/${CI_REPO_NAME}
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
platforms: *platforms
|
||||||
|
build_args:
|
||||||
|
- TAG=${CI_COMMIT_TAG}
|
||||||
|
tags:
|
||||||
|
- latest
|
||||||
|
- ${CI_COMMIT_TAG}
|
||||||
|
when:
|
||||||
|
branch: ${CI_REPO_DEFAULT_BRANCH}
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
|
||||||
|
publish-docker-develop:
|
||||||
|
image: docker.io/cybercinch/woodpecker-plugin-depot
|
||||||
|
pull: true
|
||||||
|
settings:
|
||||||
|
<<: *docker_creds
|
||||||
|
token:
|
||||||
|
from_secret: depot_token
|
||||||
|
repohost: hub.cybercinch.nz
|
||||||
|
repo: cybercinch/${CI_REPO_NAME}
|
||||||
|
project:
|
||||||
|
from_secret: depot_project
|
||||||
|
dockerfile: Dockerfile.dev
|
||||||
|
push: true
|
||||||
|
platforms: linux/amd64
|
||||||
|
tags: ["develop"]
|
||||||
|
when:
|
||||||
|
branch: develop
|
||||||
|
event:
|
||||||
|
- push
|
||||||
|
- manual
|
||||||
21
Dockerfile
Normal file
21
Dockerfile
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
FROM alpine:3.14
|
||||||
|
ARG TARGETPLATFORM
|
||||||
|
# Set by build-arg
|
||||||
|
ARG TAG=v2.2.3
|
||||||
|
|
||||||
|
# Strip out the prefix
|
||||||
|
ENV PLAT=${TARGETPLATFORM//"linux/"/}
|
||||||
|
|
||||||
|
WORKDIR /code
|
||||||
|
|
||||||
|
ADD https://hub.cybercinch.nz/cybercinch/go-semantic-release/releases/download/${TAG}/go-semantic-release.linux_${PLAT}.zip /tmp
|
||||||
|
RUN apk add --no-cache unzip && \
|
||||||
|
unzip -d /tmp /tmp/go-semantic-release.linux_${PLAT}.zip && \
|
||||||
|
ls && \
|
||||||
|
ls /tmp && \
|
||||||
|
mv /tmp/go-semantic-release.linux_${PLAT} /usr/local/bin/go-semantic-release && \
|
||||||
|
rm -f /tmp/go-semantic-release.linux_${PLAT}.zip
|
||||||
|
|
||||||
|
USER 1000
|
||||||
|
|
||||||
|
ENTRYPOINT [ "go-semantic-release" ]
|
||||||
23
Dockerfile.dev
Normal file
23
Dockerfile.dev
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
FROM golang:1.20 as build
|
||||||
|
|
||||||
|
WORKDIR /code
|
||||||
|
|
||||||
|
# Copy code into build container
|
||||||
|
COPY . /code/
|
||||||
|
|
||||||
|
RUN GOOS=linux \
|
||||||
|
GOARCH=amd64 \
|
||||||
|
CGO_ENABLED=0 \
|
||||||
|
go build -o build/go-semantic-release.linux_x86_64 -ldflags "-w -s --X main.version=`go-semantic-release next`" \
|
||||||
|
./cmd/go-semantic-release/
|
||||||
|
|
||||||
|
|
||||||
|
FROM alpine:3.14
|
||||||
|
|
||||||
|
WORKDIR /code
|
||||||
|
|
||||||
|
COPY --from=build /code/build/go-semantic-release.linux_x86_64 /usr/local/bin/go-semantic-release
|
||||||
|
|
||||||
|
USER 1000
|
||||||
|
|
||||||
|
ENTRYPOINT [ "go-semantic-release" ]
|
||||||
14
Makefile
Normal file
14
Makefile
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
|
||||||
|
|
||||||
|
all: build
|
||||||
|
|
||||||
|
.PHONY: build
|
||||||
|
|
||||||
|
build:
|
||||||
|
GOFLAGS=-mod=vendor 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 ./...
|
||||||
362
README.md
362
README.md
@@ -1,25 +1,363 @@
|
|||||||
# go-semantic-release
|
# go-semantic-release
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Release Types
|
## Release Types
|
||||||
|
|
||||||
| Type | Git tag | Changelog | Release | Write access git | Api token |
|
| Type | Implemented | Git tag | Changelog | Release | Write access git | Api token |
|
||||||
|--- |:---: |:---: |:---: |:---: |:---: |
|
| ----------- | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: | :----------------: |
|
||||||
| `git` | :white_check_mark: | | | :white_check_mark:| |
|
| `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: |
|
| `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: |
|
| `git` | :white_check_mark: | :white_check_mark: | | | :white_check_mark: | |
|
||||||
|
| `bitbucket` | Comming soon | :white_check_mark: | | | :white_check_mark: | |
|
||||||
|
| `gitea` | Coming soon | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
|
||||||
|
|
||||||
|
|
||||||
|
## Supported CI Pipelines
|
||||||
|
|
||||||
|
* Github Actions
|
||||||
|
* Gitlab CI
|
||||||
|
* Travis CI
|
||||||
|
* Custom CI, set enviroment `CI=true`
|
||||||
|
|
||||||
|
## Download
|
||||||
|
|
||||||
|
You can download the newest version under [releases](https://github.com/Nightapes/go-semantic-release/releases)
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
|
you can use a Docker image
|
||||||
|
|
||||||
|
`docker pull nightapes/go-semantic-release:<VERSION>` or `docker pull docker.pkg.github.com/nightapes/go-semantic-release/go-semantic-release:<VERSION>`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Build
|
## How to use
|
||||||
|
|
||||||
`go build ./cmd/go-semantic-release/`
|
`go-semantic-release` config file
|
||||||
|
Create a file with the name `.release.yml` or anything else, but you need to set to every command `-c <your config file>`
|
||||||
|
|
||||||
## Run
|
### Example config
|
||||||
|
|
||||||
Print the next version
|
```yml
|
||||||
|
commitFormat: angular
|
||||||
|
branch:
|
||||||
|
master: release
|
||||||
|
release: 'github'
|
||||||
|
github:
|
||||||
|
repo: "go-semantic-release"
|
||||||
|
user: "nightapes"
|
||||||
|
assets:
|
||||||
|
- name: ./build/go-semantic-release
|
||||||
|
compress: false
|
||||||
|
- name: ./build/go-semantic-release.exe
|
||||||
|
compress: false
|
||||||
|
hooks:
|
||||||
|
preRelease:
|
||||||
|
- name: echo $RELEASE_VERSION
|
||||||
|
postRelease:
|
||||||
|
- name: echo $RELEASE_VERSION
|
||||||
|
integrations:
|
||||||
|
npm:
|
||||||
|
enabled: true
|
||||||
|
```
|
||||||
|
|
||||||
`./go-semantic-release version next`
|
#### CommitFormat
|
||||||
|
|
||||||
Set a version
|
Supported formats:
|
||||||
|
|
||||||
`./go-semantic-release version set v1.1.1`
|
* [angular](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit-message-format)
|
||||||
|
|
||||||
|
```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
|
||||||
|
|
||||||
|
You can define which kind of release should be created for different branches.
|
||||||
|
|
||||||
|
Supported release kinds:
|
||||||
|
|
||||||
|
* `release` -> `v1.0.0`
|
||||||
|
* `rc` -> `v1.0.0-rc.0`
|
||||||
|
* `beta` -> `v1.0.0-beta.0`
|
||||||
|
* `alpha` -> `v1.0.0-alpha.0`
|
||||||
|
|
||||||
|
Add a branch config to your config
|
||||||
|
|
||||||
|
```yml
|
||||||
|
branch:
|
||||||
|
<branch-name>: <kind>
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Release
|
||||||
|
|
||||||
|
At the moment we support releases to gitlab, github and gitea.
|
||||||
|
|
||||||
|
##### Github
|
||||||
|
|
||||||
|
You need to set the env `GITHUB_TOKEN` with an access token.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
release: 'github'
|
||||||
|
github:
|
||||||
|
user: "<user/group"
|
||||||
|
repo: "<repositroyname>"
|
||||||
|
## Optional, if you are not using github.com
|
||||||
|
customUrl: <https://your.github>
|
||||||
|
## Optional, if you want to change the default tag prefix ("v")
|
||||||
|
tagPrefix: ""
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Gitlab
|
||||||
|
|
||||||
|
You need to set the env `GITLAB_ACCESS_TOKEN` with an personal access token.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
release: 'gitlab'
|
||||||
|
gitlab:
|
||||||
|
repo: "<repositroyname>" ## Example group/project
|
||||||
|
## Optional, if your not using gitlab.com
|
||||||
|
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
|
||||||
|
|
||||||
|
Only via https at the moment. You need write access to your git repository
|
||||||
|
|
||||||
|
|
||||||
|
```yml
|
||||||
|
release: 'git'
|
||||||
|
git:
|
||||||
|
email: "<email>" # Used for creating tag
|
||||||
|
user: "<user>" : # Used for creating tag and pushing
|
||||||
|
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: ""
|
||||||
|
```
|
||||||
|
##### Gitea
|
||||||
|
|
||||||
|
You need to set the env `GITEA_TOKEN` with an access token.
|
||||||
|
|
||||||
|
```yml
|
||||||
|
release: 'gitea'
|
||||||
|
gitea:
|
||||||
|
user: "<user/group"
|
||||||
|
repo: "<repositoryname>"
|
||||||
|
## URL of your Gitea instance
|
||||||
|
Url: <https://your.github>
|
||||||
|
## Optional, if you want to change the default tag prefix ("v")
|
||||||
|
tagPrefix: ""
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Assets
|
||||||
|
|
||||||
|
You can upload assets to a release
|
||||||
|
|
||||||
|
Support for gitlab and github.
|
||||||
|
If you want, you can let the file be compressed before uploading
|
||||||
|
|
||||||
|
```yml
|
||||||
|
assets:
|
||||||
|
- name: ./build/go-semantic-release
|
||||||
|
compress: false
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Hooks
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
Following variables and objects can be used for templates:
|
||||||
|
|
||||||
|
__Top level__
|
||||||
|
|
||||||
|
| Field | Type | Description |
|
||||||
|
| -------- | ------ | ----- |
|
||||||
|
| `Commits` | string | Fully rendered commit messages. This is left for backward compatibility. |
|
||||||
|
| `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
|
||||||
|
changelog:
|
||||||
|
printAll: false ## Print all valid commits to changelog
|
||||||
|
title: "v{{.Version}} ({{.Now.Format "2006-01-02"}})" ## Used for releases (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
|
||||||
|
|
||||||
|
You can print a help text for a docker image
|
||||||
|
|
||||||
|
```yml
|
||||||
|
changelog:
|
||||||
|
docker:
|
||||||
|
latest: false ## If you uploaded a latest image
|
||||||
|
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
|
||||||
|
|
||||||
|
`go-semantic-release` has two modes for calculating the version: automatic or manual.
|
||||||
|
|
||||||
|
#### Automatic
|
||||||
|
|
||||||
|
Version will be calculated on the `next` or `release` command
|
||||||
|
|
||||||
|
#### Manual
|
||||||
|
|
||||||
|
If you don't want that `go-semantic-release` is calculating the version from the commits, you can set the version by hand with
|
||||||
|
following command:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./go-semantic-release set 1.1.1
|
||||||
|
```
|
||||||
|
|
||||||
|
### Print version
|
||||||
|
|
||||||
|
Print the next version, can be used to add version to your program
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./go-semantic-release next // show next version (calculated by new commits since last version)
|
||||||
|
./go-semantic-release last // show last released version
|
||||||
|
```
|
||||||
|
Example with go-lang
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go build -ldflags "--X main.version=`./go-semantic-release next`"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Create release
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./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
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go build ./cmd/go-semantic-release/
|
||||||
|
```
|
||||||
|
|
||||||
|
### Testing
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go test ./...
|
||||||
|
```
|
||||||
|
|
||||||
|
### Linting
|
||||||
|
|
||||||
|
```
|
||||||
|
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.16.0
|
||||||
|
golangci-lint run ./...
|
||||||
|
```
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
go build ./cmd/main.go && ./main.exe version next --path /f/Repro/ambassador/
|
|
||||||
go build ./cmd/main.go && ./main.exe --loglevel debug version set v1.1.1 --path /f/Repro/ambassador/
|
|
||||||
3
_config.yml
Normal file
3
_config.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
theme: jekyll-theme-cayman
|
||||||
|
plugins:
|
||||||
|
- jemoji
|
||||||
@@ -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,30 +34,51 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := semanticrelease.New(readConfig(config), repository)
|
configChecks, err := cmd.Flags().GetBool("checks")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
releaseVersion, err := s.GetNextVersion(force)
|
fromVersion, err := cmd.Flags().GetString("from")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
provider, err := s.GetCIProvider()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseVersion, err := s.GetNextVersion(provider, force, fromVersion)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Debugf("Found %d commits till last release", len(releaseVersion.Commits))
|
||||||
|
|
||||||
generatedChangelog, err := s.GetChangelog(releaseVersion)
|
generatedChangelog, err := s.GetChangelog(releaseVersion)
|
||||||
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
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
65
cmd/go-semantic-release/commands/hooks.go
Normal file
65
cmd/go-semantic-release/commands/hooks.go
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/hooks"
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/semanticrelease"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
hooksCmd.Flags().Bool("checks", false, "Check for missing values and envs")
|
||||||
|
rootCmd.AddCommand(hooksCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var hooksCmd = &cobra.Command{
|
||||||
|
Use: "hooks",
|
||||||
|
Short: "Run all hooks",
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
hook := hooks.New(releaseConfig, releaseVersion)
|
||||||
|
|
||||||
|
err = hook.PreRelease()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return hook.PostRelease()
|
||||||
|
},
|
||||||
|
}
|
||||||
62
cmd/go-semantic-release/commands/integrations.go
Normal file
62
cmd/go-semantic-release/commands/integrations.go
Normal 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()
|
||||||
|
},
|
||||||
|
}
|
||||||
59
cmd/go-semantic-release/commands/last.go
Normal file
59
cmd/go-semantic-release/commands/last.go
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/semanticrelease"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
lastCmd.Flags().Bool("checks", false, "Check for missing values and envs")
|
||||||
|
rootCmd.AddCommand(lastCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
var lastCmd = &cobra.Command{
|
||||||
|
Use: "last",
|
||||||
|
Short: "Get last version",
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
s, err := semanticrelease.New(readConfig(config), repository, configChecks)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
provider, err := s.GetCIProvider()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Infof("Will not calculate version, set fake version. Could not find CI Provider, if running locally, set env CI=true")
|
||||||
|
fmt.Println("0.0.0-fake.0")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseVersion, err := s.GetNextVersion(provider, force, "")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Println(releaseVersion.Last.Version.String())
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
}
|
||||||
@@ -2,12 +2,13 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/Nightapes/go-semantic-release/pkg/semanticrelease"
|
"github.com/Nightapes/go-semantic-release/pkg/semanticrelease"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
nextCmd.Flags().Bool("checks", false, "Check for missing values and envs")
|
||||||
rootCmd.AddCommand(nextCmd)
|
rootCmd.AddCommand(nextCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,12 +31,25 @@ var nextCmd = &cobra.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := semanticrelease.New(readConfig(config), repository)
|
configChecks, err := cmd.Flags().GetBool("checks")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
releaseVersion, err := s.GetNextVersion(force)
|
s, err := semanticrelease.New(readConfig(config), repository, configChecks)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
provider, err := s.GetCIProvider()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Infof("Will not calculate version, set fake version. Could not find CI Provider, if running locally, set env CI=true")
|
||||||
|
fmt.Println("0.0.0-fake.0")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseVersion, err := s.GetNextVersion(provider, force, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,10 +29,21 @@ var releaseCmd = &cobra.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := semanticrelease.New(readConfig(config), repository)
|
ignoreConfigChecks, err := cmd.Flags().GetBool("no-checks")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return s.Release(force)
|
|
||||||
|
s, err := semanticrelease.New(readConfig(config), repository, !ignoreConfigChecks)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
provider, err := s.GetCIProvider()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.Release(provider, force)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,11 +31,7 @@ func Execute(version string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
currentDir, err := os.Getwd()
|
rootCmd.PersistentFlags().StringP("repository", "r", "./", "Path to repository")
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
rootCmd.PersistentFlags().StringP("repository", "r", currentDir, "Path to repository")
|
|
||||||
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")
|
||||||
|
|||||||
@@ -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,11 +27,21 @@ var setCmd = &cobra.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := semanticrelease.New(readConfig(config), repository)
|
configChecks, err := cmd.Flags().GetBool("checks")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.SetVersion(args[0])
|
s, err := semanticrelease.New(readConfig(config), repository, configChecks)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
provider, err := s.GetCIProvider()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.SetVersion(provider, args[0])
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,14 @@ 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)")
|
||||||
rootCmd.AddCommand(zipCmd)
|
rootCmd.AddCommand(zipCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
var zipCmd = &cobra.Command{
|
var zipCmd = &cobra.Command{
|
||||||
Use: "zip",
|
Use: "zip",
|
||||||
Short: "Zip configured artifact from release config",
|
Short: "Zip configured artifact from release config (internal)",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
config, err := cmd.Flags().GetString("config")
|
config, err := cmd.Flags().GetString("config")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -23,7 +25,12 @@ var zipCmd = &cobra.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := semanticrelease.New(readConfig(config), repository)
|
configChecks, err := cmd.Flags().GetBool("checks")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
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
12
examples/.gitlab-ci.yml
Normal 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
|
||||||
@@ -29,11 +29,11 @@ script:
|
|||||||
- go test -v ./...
|
- go test -v ./...
|
||||||
- go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/
|
- go build -o build/go-semantic-release-temp ./cmd/go-semantic-release/
|
||||||
- echo "Building version `./build/go-semantic-release-temp next --loglevel debug --no-cache`"
|
- echo "Building version `./build/go-semantic-release-temp next --loglevel debug --no-cache`"
|
||||||
- go build -o build/go-semantic-release -ldflags "-X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
|
- go build -o build/go-semantic-release -ldflags "-w -s --X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
|
||||||
- GOOS=windows GOARCH=386 go build -o build/go-semantic-release.exe -ldflags "-X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
|
- GOOS=windows GOARCH=386 go build -o build/go-semantic-release.exe -ldflags "-w -s -X main.version=`./build/go-semantic-release-temp next`" ./cmd/go-semantic-release/
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- ./build/go-semantic-release-temp release --loglevel debug
|
- ./build/go-semantic-release-temp release --loglevel trace
|
||||||
|
|
||||||
branches:
|
branches:
|
||||||
except:
|
except:
|
||||||
37
examples/changelog.tmpl
Normal file
37
examples/changelog.tmpl
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
{{ 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"}})
|
||||||
|
{{ template "commitList" .CommitsContent -}}
|
||||||
|
|
||||||
|
{{ if .HasDocker}}
|
||||||
|
## Docker image
|
||||||
|
|
||||||
|
New docker image is released under {{$.Backtick}}{{.DockerRepository}}:{{.Version}}{{$.Backtick}}
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
{{$.Backtick}}docker run {{.DockerRepository}}:{{.Version}}{{$.Backtick}}
|
||||||
|
{{ if .HasDockerLatest}}
|
||||||
|
or
|
||||||
|
|
||||||
|
{{$.Backtick}}docker run {{.DockerRepository}}:latest{{$.Backtick}}
|
||||||
|
{{ end -}}
|
||||||
|
{{ end -}}
|
||||||
29
examples/github-actions.yml
Normal file
29
examples/github-actions.yml
Normal 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
|
||||||
67
go.mod
67
go.mod
@@ -1,21 +1,58 @@
|
|||||||
module github.com/Nightapes/go-semantic-release
|
module github.com/Nightapes/go-semantic-release
|
||||||
|
|
||||||
go 1.12
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Masterminds/semver v1.4.2
|
github.com/Masterminds/semver v1.5.0
|
||||||
github.com/gliderlabs/ssh v0.2.2 // indirect
|
github.com/go-git/go-billy/v5 v5.4.1
|
||||||
github.com/google/go-cmp v0.3.0 // indirect
|
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/kevinburke/ssh_config v0.0.0-20190630040420-2e50c441276c // indirect
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/sirupsen/logrus v1.4.2
|
github.com/sirupsen/logrus v1.9.0
|
||||||
github.com/spf13/cobra v0.0.5
|
github.com/spf13/cobra v1.6.1
|
||||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect
|
github.com/stretchr/testify v1.7.0
|
||||||
golang.org/x/net v0.0.0-20190628185345-da137c7871d7 // indirect
|
github.com/tidwall/sjson v1.2.5
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
|
golang.org/x/oauth2 v0.5.0
|
||||||
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb // indirect
|
gopkg.in/yaml.v2 v2.4.0
|
||||||
google.golang.org/appengine v1.6.1 // indirect
|
)
|
||||||
gopkg.in/src-d/go-billy.v4 v4.3.1 // indirect
|
|
||||||
gopkg.in/src-d/go-git.v4 v4.12.0
|
require (
|
||||||
gopkg.in/yaml.v2 v2.2.2
|
github.com/davidmz/go-pageant v1.0.2 // indirect
|
||||||
|
github.com/go-fed/httpsig v1.1.0 // indirect
|
||||||
|
github.com/hashicorp/go-version v1.6.0 // indirect
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
code.gitea.io/sdk/gitea v0.17.1
|
||||||
|
github.com/Microsoft/go-winio v0.6.0 // indirect
|
||||||
|
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
|
||||||
|
github.com/acomagu/bufpipe v1.0.3 // indirect
|
||||||
|
github.com/cloudflare/circl v1.3.2 // 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.17.0 // indirect
|
||||||
|
golang.org/x/mod v0.8.0 // indirect
|
||||||
|
golang.org/x/net v0.10.0 // indirect
|
||||||
|
golang.org/x/sys v0.15.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
|
||||||
)
|
)
|
||||||
|
|||||||
300
go.sum
300
go.sum
@@ -1,155 +1,217 @@
|
|||||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
code.gitea.io/sdk/gitea v0.17.1 h1:3jCPOG2ojbl8AcfaUCRYLT5MUcBMFwS0OSK2mA5Zok8=
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
code.gitea.io/sdk/gitea v0.17.1/go.mod h1:aCnBqhHpoEWA180gMbaCtdX9Pl6BWBAuuP2miadoTNM=
|
||||||
github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc=
|
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
|
||||||
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
|
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
|
||||||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=
|
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
|
||||||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
|
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
|
||||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA=
|
github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
|
||||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
|
github.com/ProtonMail/go-crypto v0.0.0-20221026131551-cf6655e29de4/go.mod h1:UBYPn8k0D56RtnR8RFQMjmh4KrZzWJ5o7Z9SYjossQ8=
|
||||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
|
||||||
|
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
|
||||||
|
github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk=
|
||||||
|
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/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
|
||||||
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
|
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
|
||||||
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
github.com/cloudflare/circl v1.3.2 h1:VWp8dY3yH69fdM7lM6A1+NhhVoDu9vqK0jOgmkQHFWk=
|
||||||
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
|
github.com/cloudflare/circl v1.3.2/go.mod h1:+CauBF6R70Jqcyl8N2hC8pAXYbWkGIezuSbuGLtRhnw=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
|
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||||
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/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
|
github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0=
|
||||||
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
|
github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE=
|
||||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
|
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
|
||||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
|
||||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
|
||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
|
||||||
github.com/gliderlabs/ssh v0.1.3/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI=
|
||||||
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
|
github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM=
|
||||||
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4=
|
||||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E=
|
||||||
|
github.com/go-git/go-billy/v5 v5.3.1/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0=
|
||||||
|
github.com/go-git/go-billy/v5 v5.4.0/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg=
|
||||||
|
github.com/go-git/go-billy/v5 v5.4.1 h1:Uwp5tDRkPr+l/TnbHOQzp+tmJfLceOlbVucgpTz8ix4=
|
||||||
|
github.com/go-git/go-billy/v5 v5.4.1/go.mod h1:vjbugF6Fz7JIflbVpl1hJsGjSHNltrSw45YK/ukIvQg=
|
||||||
|
github.com/go-git/go-git-fixtures/v4 v4.3.1 h1:y5z6dd3qi8Hl+stezc8p3JxDkoTRqMAlKnXHuzrfjTQ=
|
||||||
|
github.com/go-git/go-git-fixtures/v4 v4.3.1/go.mod h1:8LHG1a3SRW71ettAD/jW13h8c6AqjVSeL11RAdgaqpo=
|
||||||
|
github.com/go-git/go-git/v5 v5.5.2 h1:v8lgZa5k9ylUw+OR/roJHTxR4QItsNFI5nKtAXFuynw=
|
||||||
|
github.com/go-git/go-git/v5 v5.5.2/go.mod h1:BE5hUJ5yaV2YMxhmaP4l6RBQ08kMxKSPD4BlxtH7OjI=
|
||||||
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 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
|
|
||||||
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/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||||
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
|
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
|
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/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
|
||||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
|
||||||
|
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
|
||||||
|
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
|
||||||
|
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||||
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
|
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/kevinburke/ssh_config v0.0.0-20180830205328-81db2a75821e h1:RgQk53JHp/Cjunrr1WlsXSZpqXn+uREuHvUVcK82CV8=
|
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
|
||||||
github.com/kevinburke/ssh_config v0.0.0-20180830205328-81db2a75821e/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
||||||
github.com/kevinburke/ssh_config v0.0.0-20190630040420-2e50c441276c h1:VAx3LRNjVNvjtgO7KFRuT/3aye/0zJvwn01rHSfoolo=
|
|
||||||
github.com/kevinburke/ssh_config v0.0.0-20190630040420-2e50c441276c/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
|
|
||||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
|
||||||
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/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/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
|
||||||
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
|
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/pelletier/go-buffruneio v0.2.0 h1:U4t4R6YkofJ5xHm3dJzuRpPZ0mr5MMCoAWooScCR7aA=
|
github.com/pjbgf/sha1cd v0.2.3 h1:uKQP/7QOzNtKYH7UTohZLcjF5/55EnTw0jO/Ru4jZwI=
|
||||||
github.com/pelletier/go-buffruneio v0.2.0/go.mod h1:JkE26KsDizTr40EUHkXVtNPvgGtbSNq5BcowyYOWdKo=
|
github.com/pjbgf/sha1cd v0.2.3/go.mod h1:HOK9QrgzdHpbc2Kzip0Q1yi3M2MFGPADtR6HjG65m5M=
|
||||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pkg/errors v0.8.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/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
|
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||||
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
|
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
|
||||||
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
|
||||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||||
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
|
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
github.com/skeema/knownhosts v1.1.0 h1:Wvr9V0MxhjRbl3f9nMnKnFfiWTJmtECJ9Njkea3ysW0=
|
||||||
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
|
github.com/skeema/knownhosts v1.1.0/go.mod h1:sKFq3RD6/TKZkSWn8boUbDC7Qkgcv+8XXijpFO6roag=
|
||||||
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
|
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA=
|
||||||
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
|
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY=
|
||||||
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
|
|
||||||
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/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
|
||||||
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 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
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/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
|
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||||
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
|
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||||
|
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
|
||||||
|
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||||
|
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
||||||
|
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-20190422183909-d864b10871cd/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
|
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||||
|
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
||||||
|
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
|
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
|
||||||
|
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-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190502183928-7f726cade0ab/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
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-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU=
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=
|
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
|
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.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
|
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||||
|
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||||
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-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
|
golang.org/x/oauth2 v0.5.0 h1:HuArIo48skDwlrvM3sEdHXElYslAMsf3KwRkkW4MC4s=
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.5.0/go.mod h1:9/XBHVqLaWO3/BRHs5jbpYCnOZVjj5V0ndyaAM7KB4I=
|
||||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6 h1:bjcUS9ztw9kFmmIxJInhon/0Is3p+EHBKNgquIzo1OI=
|
|
||||||
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-20180903190138-2b024373dcd9 h1:lkiLiLBHGoH3XnqSLUIaBsilGMUjI+Uy2Xu2JLUtTas=
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20180903190138-2b024373dcd9/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||||
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
|
|
||||||
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-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb h1:fgwFCsaw9buMuxNd6+DQfAuSFqbNiQZpcgJQAgJsK6k=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/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/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
|
||||||
|
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/term v0.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/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
|
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
||||||
|
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
|
||||||
|
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
|
||||||
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/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
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/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
|
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
|
||||||
|
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||||
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-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
google.golang.org/appengine v1.1.0 h1:igQkv0AAhEIvTEpD5LIpAfav2eeVO9HBTjvKHVJPRSs=
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
|
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.1 h1:QzqyMA1tlu6CgqCDUtU9V+ZKhLFT2dkJuANu5QaxI3I=
|
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||||
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
|
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
|
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
|
||||||
|
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||||
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 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/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-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/src-d/go-billy.v4 v4.3.0/go.mod h1:tm33zBoOwxjYHZIE+OV8bxTWFMJLrconzFMd38aARFk=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/src-d/go-billy.v4 v4.3.1 h1:OkK1DmefDy1Z6Veu82wdNj/cLpYORhdX4qdaYCPwc7s=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
gopkg.in/src-d/go-billy.v4 v4.3.1/go.mod h1:tm33zBoOwxjYHZIE+OV8bxTWFMJLrconzFMd38aARFk=
|
|
||||||
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.12.0 h1:CKgvBCJCcdfNnyXPYI4Cp8PaDDAmAPEN0CtfEdEAbd8=
|
|
||||||
gopkg.in/src-d/go-git.v4 v4.12.0/go.mod h1:zjlNnzc1Wjn43v3Mtii7RVxiReNP0fIu9npcXKzuNp4=
|
|
||||||
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.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
|
||||||
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.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
|
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=
|
||||||
|
|||||||
@@ -2,95 +2,203 @@
|
|||||||
package analyzer
|
package analyzer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
"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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const breakingChangeKeywords = "BREAKING CHANGE"
|
||||||
|
const defaultBreakingChangePrefix = breakingChangeKeywords + ":"
|
||||||
|
const footerTokenRegex = "^(?P<token>[^\\s*-][\\w\\- ]+[^\\s])<SEP>.*"
|
||||||
|
|
||||||
|
var defaultTokenSeparators = [2]string{": ", " #"}
|
||||||
|
|
||||||
// Analyzer struct
|
// Analyzer struct
|
||||||
type Analyzer struct {
|
type Analyzer struct {
|
||||||
analyzeCommit analyzeCommit
|
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
|
||||||
Release string
|
Release shared.Release
|
||||||
Changelog bool
|
Changelog bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type analyzeCommit interface {
|
type analyzeCommits interface {
|
||||||
analyze(commit gitutil.Commit, tag Rule) (AnalyzedCommit, bool, error)
|
analyze(commit shared.Commit, tag Rule) *shared.AnalyzedCommit
|
||||||
getRules() []Rule
|
getRules() []Rule
|
||||||
}
|
}
|
||||||
|
|
||||||
//AnalyzedCommit struct
|
|
||||||
type AnalyzedCommit struct {
|
|
||||||
Commit gitutil.Commit
|
|
||||||
ParsedMessage string
|
|
||||||
Scope string
|
|
||||||
ParsedBreakingChangeMessage string
|
|
||||||
Tag string
|
|
||||||
TagString string
|
|
||||||
Print bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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:
|
||||||
log.Debugf("Commit format set to angular")
|
analyzer.analyzeCommits = newAngular()
|
||||||
analyzer.analyzeCommit = newAngular()
|
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
|
||||||
func (a *Analyzer) GetRules() []Rule {
|
func (a *Analyzer) GetRules() []Rule {
|
||||||
return a.analyzeCommit.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 []gitutil.Commit) map[string][]AnalyzedCommit {
|
func (a *Analyzer) Analyze(commits []shared.Commit) map[shared.Release][]shared.AnalyzedCommit {
|
||||||
|
analyzedCommits := make(map[shared.Release][]shared.AnalyzedCommit)
|
||||||
analyzedCommits := make(map[string][]AnalyzedCommit)
|
analyzedCommits["major"] = make([]shared.AnalyzedCommit, 0)
|
||||||
analyzedCommits["major"] = make([]AnalyzedCommit, 0)
|
analyzedCommits["minor"] = make([]shared.AnalyzedCommit, 0)
|
||||||
analyzedCommits["minor"] = make([]AnalyzedCommit, 0)
|
analyzedCommits["patch"] = make([]shared.AnalyzedCommit, 0)
|
||||||
analyzedCommits["patch"] = make([]AnalyzedCommit, 0)
|
analyzedCommits["none"] = make([]shared.AnalyzedCommit, 0)
|
||||||
analyzedCommits["none"] = make([]AnalyzedCommit, 0)
|
|
||||||
|
|
||||||
for _, commit := range commits {
|
for _, commit := range commits {
|
||||||
for _, rule := range a.analyzeCommit.getRules() {
|
for _, rule := range a.analyzeCommits.getRules() {
|
||||||
analyzedCommit, hasBreakingChange, err := a.analyzeCommit.analyze(commit, rule)
|
analyzedCommit := a.analyzeCommits.analyze(commit, rule)
|
||||||
if err == nil {
|
if analyzedCommit == nil {
|
||||||
if a.Config.PrintAll {
|
continue
|
||||||
|
}
|
||||||
|
if a.ChangelogConfig.PrintAll || rule.Changelog {
|
||||||
analyzedCommit.Print = true
|
analyzedCommit.Print = true
|
||||||
} else {
|
|
||||||
analyzedCommit.Print = rule.Changelog
|
|
||||||
}
|
|
||||||
if hasBreakingChange {
|
|
||||||
analyzedCommits["major"] = append(analyzedCommits["major"], analyzedCommit)
|
|
||||||
} else {
|
|
||||||
analyzedCommits[rule.Release] = append(analyzedCommits[rule.Release], analyzedCommit)
|
|
||||||
}
|
}
|
||||||
|
if analyzedCommit.IsBreaking {
|
||||||
|
analyzedCommits["major"] = append(analyzedCommits["major"], *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
|
||||||
|
}
|
||||||
|
|||||||
16
internal/analyzer/analyzer_test.go
Normal file
16
internal/analyzer/analyzer_test.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package analyzer_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/analyzer"
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAnalyzer(t *testing.T) {
|
||||||
|
|
||||||
|
_, err := analyzer.New("unknown", config.AnalyzerConfig{}, config.ChangelogConfig{})
|
||||||
|
assert.Error(t, err)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,23 +2,30 @@
|
|||||||
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"
|
||||||
|
|
||||||
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
)
|
)
|
||||||
|
|
||||||
type angular struct {
|
type angular struct {
|
||||||
rules []Rule
|
rules []Rule
|
||||||
regex string
|
regex string
|
||||||
|
log *log.Entry
|
||||||
|
config config.AnalyzerConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ANGULAR identifier
|
||||||
|
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),
|
||||||
rules: []Rule{
|
rules: []Rule{
|
||||||
{
|
{
|
||||||
Tag: "feat",
|
Tag: "feat",
|
||||||
@@ -31,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",
|
||||||
@@ -47,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",
|
||||||
@@ -76,38 +89,54 @@ func (a *angular) getRules() []Rule {
|
|||||||
return a.rules
|
return a.rules
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *angular) analyze(commit gitutil.Commit, rule Rule) (AnalyzedCommit, bool, error) {
|
func (a *angular) analyze(commit shared.Commit, rule Rule) *shared.AnalyzedCommit {
|
||||||
|
tokenSep := append(a.config.TokenSeparators, angularFooterTokenSep[:]...)
|
||||||
|
|
||||||
analyzed := AnalyzedCommit{
|
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)
|
||||||
|
|
||||||
|
log.Debugf("Found commit from Author %s", commit.Author)
|
||||||
|
|
||||||
|
analyzed := &shared.AnalyzedCommit{
|
||||||
Commit: commit,
|
Commit: commit,
|
||||||
Tag: rule.Tag,
|
Tag: rule.Tag,
|
||||||
TagString: rule.TagString,
|
TagString: rule.TagString,
|
||||||
|
Scope: shared.Scope(matches["scope"]),
|
||||||
|
Subject: strings.TrimSpace(matches["subject"]),
|
||||||
|
MessageBlocks: msgBlockMap,
|
||||||
}
|
}
|
||||||
|
|
||||||
re := regexp.MustCompile(strings.Replace(a.regex, "TAG", rule.Tag, -1))
|
isBreaking := strings.Contains(commit.Message, defaultBreakingChangePrefix)
|
||||||
matches := re.FindAllStringSubmatch(commit.Message, -1)
|
analyzed.IsBreaking = isBreaking
|
||||||
if len(matches) >= 1 {
|
|
||||||
if len(matches[0]) >= 3 {
|
|
||||||
|
|
||||||
analyzed.Scope = matches[0][2]
|
oldFormatMessage := strings.TrimSpace(matches["subject"] + "\n" + body)
|
||||||
|
|
||||||
message := strings.Join(matches[0][3:], "")
|
if !isBreaking {
|
||||||
if !strings.Contains(message, "BREAKING CHANGE:") {
|
analyzed.ParsedMessage = strings.Trim(oldFormatMessage, " ")
|
||||||
analyzed.ParsedMessage = message
|
a.log.Tracef("%s: found %s", commit.Message, rule.Tag)
|
||||||
|
return analyzed
|
||||||
log.Tracef("%s: found %s", commit.Message, rule.Tag)
|
|
||||||
return analyzed, false, nil
|
|
||||||
}
|
}
|
||||||
breakingChange := strings.SplitN(message, "BREAKING CHANGE:", 2)
|
|
||||||
|
|
||||||
analyzed.ParsedMessage = breakingChange[0]
|
a.log.Tracef(" %s, BREAKING CHANGE found", commit.Message)
|
||||||
analyzed.ParsedBreakingChangeMessage = breakingChange[1]
|
breakingChange := strings.SplitN(oldFormatMessage, defaultBreakingChangePrefix, 2)
|
||||||
|
|
||||||
log.Tracef(" %s, BREAKING CHANGE found", commit.Message)
|
if len(breakingChange) > 1 {
|
||||||
return analyzed, true, nil
|
analyzed.ParsedMessage = strings.TrimSpace(breakingChange[0])
|
||||||
|
analyzed.ParsedBreakingChangeMessage = strings.TrimSpace(breakingChange[1])
|
||||||
|
} else {
|
||||||
|
analyzed.ParsedBreakingChangeMessage = breakingChange[0]
|
||||||
}
|
}
|
||||||
}
|
return analyzed
|
||||||
log.Tracef("%s does not match %s, skip", commit.Message, rule.Tag)
|
|
||||||
return analyzed, false, fmt.Errorf("not found")
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
248
internal/analyzer/angular_test.go
Normal file
248
internal/analyzer/angular_test.go
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
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 TestAngular(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
testConfigs := []struct {
|
||||||
|
testCase string
|
||||||
|
commits []shared.Commit
|
||||||
|
analyzedCommits map[shared.Release][]shared.AnalyzedCommit
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
testCase: "feat",
|
||||||
|
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{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"major": {},
|
||||||
|
"patch": {},
|
||||||
|
"none": {},
|
||||||
|
},
|
||||||
|
commits: []shared.Commit{
|
||||||
|
{
|
||||||
|
Message: "feat(internal/changelog): my first commit",
|
||||||
|
Author: "me",
|
||||||
|
Hash: "12345667",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "feat breaking change",
|
||||||
|
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{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"major": {
|
||||||
|
{
|
||||||
|
Commit: shared.Commit{
|
||||||
|
Message: "feat(internal/changelog): my first break BREAKING CHANGE: change api to v2",
|
||||||
|
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 BREAKING CHANGE: change api to v2",
|
||||||
|
MessageBlocks: map[string][]shared.MessageBlock{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"patch": {},
|
||||||
|
"none": {},
|
||||||
|
},
|
||||||
|
commits: []shared.Commit{
|
||||||
|
{
|
||||||
|
Message: "feat(internal/changelog): my first commit",
|
||||||
|
Author: "me",
|
||||||
|
Hash: "12345667",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Message: "feat(internal/changelog): my first break BREAKING CHANGE: change api to v2",
|
||||||
|
Author: "me",
|
||||||
|
Hash: "12345668",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "feat breaking change footer",
|
||||||
|
commits: []shared.Commit{
|
||||||
|
{
|
||||||
|
Message: "feat(internal/changelog): my first commit",
|
||||||
|
Author: "me",
|
||||||
|
Hash: "12345667",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Message: "feat(internal/changelog): my first break \n\nBREAKING CHANGE: change api to v2\n",
|
||||||
|
Author: "me",
|
||||||
|
Hash: "12345668",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
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{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"major": {
|
||||||
|
{
|
||||||
|
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{
|
||||||
|
Message: "build(internal/changelog): my first build",
|
||||||
|
Author: "me",
|
||||||
|
Hash: "12345668",
|
||||||
|
},
|
||||||
|
Scope: "internal/changelog",
|
||||||
|
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(internal/changelog): my first commit",
|
||||||
|
Author: "me",
|
||||||
|
Hash: "12345667",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Message: "build(internal/changelog): my first build",
|
||||||
|
Author: "me",
|
||||||
|
Hash: "12345668",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
angular, err := analyzer.New("angular", config.AnalyzerConfig{}, config.ChangelogConfig{})
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
for _, test := range testConfigs {
|
||||||
|
analyzedCommits := angular.Analyze(test.commits)
|
||||||
|
assert.Equalf(t, test.analyzedCommits["major"], analyzedCommits["major"], "Testcase %s should have major commits", test.testCase)
|
||||||
|
assert.Equalf(t, test.analyzedCommits["minor"], analyzedCommits["minor"], "Testcase %s should have minor 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
143
internal/analyzer/conventional.go
Normal file
143
internal/analyzer/conventional.go
Normal 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
|
||||||
|
}
|
||||||
496
internal/analyzer/conventional_test.go
Normal file
496
internal/analyzer/conventional_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
179
internal/assets/asset.go
Normal file
179
internal/assets/asset.go
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
package assets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"archive/zip"
|
||||||
|
"crypto/md5"
|
||||||
|
"crypto/sha1"
|
||||||
|
"crypto/sha256"
|
||||||
|
"crypto/sha512"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"hash"
|
||||||
|
"hash/crc32"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Asset struct
|
||||||
|
type Asset struct {
|
||||||
|
name string
|
||||||
|
path string
|
||||||
|
zippedPath string
|
||||||
|
algorithm string
|
||||||
|
isCompressed bool
|
||||||
|
}
|
||||||
|
|
||||||
|
//NewAsset from a config
|
||||||
|
func NewAsset(repository string, assetConfig config.Asset, algorithm string) (*Asset, error) {
|
||||||
|
|
||||||
|
filePath := assetConfig.Path
|
||||||
|
if assetConfig.Name != "" && assetConfig.Path == "" {
|
||||||
|
filePath = assetConfig.Name
|
||||||
|
log.Warn("Name is deprecated. Please update your config. See https://nightapes.github.io/go-semantic-release/")
|
||||||
|
}
|
||||||
|
|
||||||
|
realPath := path.Join(repository, filePath)
|
||||||
|
|
||||||
|
file, err := os.Open(realPath)
|
||||||
|
if err != nil {
|
||||||
|
file.Close()
|
||||||
|
return nil, errors.Wrapf(err, "Could not open file %s", realPath)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
name := assetConfig.Rename
|
||||||
|
if assetConfig.Rename == "" {
|
||||||
|
info, _ := file.Stat()
|
||||||
|
name = info.Name()
|
||||||
|
}
|
||||||
|
|
||||||
|
asset := &Asset{
|
||||||
|
path: realPath,
|
||||||
|
name: name,
|
||||||
|
isCompressed: assetConfig.Compress,
|
||||||
|
algorithm: algorithm,
|
||||||
|
}
|
||||||
|
|
||||||
|
return asset, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Asset) getChecksum() (string, error) {
|
||||||
|
path, err := a.GetPath()
|
||||||
|
if err != nil {
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
log.Debugf("Calculating checksum for %s", path)
|
||||||
|
file, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.Wrapf(err, "Failed to open file %s to calculate checksum", a.name)
|
||||||
|
}
|
||||||
|
defer file.Close() // nolint: errcheck
|
||||||
|
var hash hash.Hash
|
||||||
|
switch a.algorithm {
|
||||||
|
case "crc32":
|
||||||
|
hash = crc32.NewIEEE()
|
||||||
|
case "md5":
|
||||||
|
hash = md5.New()
|
||||||
|
case "sha1":
|
||||||
|
hash = sha1.New()
|
||||||
|
case "sha224":
|
||||||
|
hash = sha256.New224()
|
||||||
|
case "sha384":
|
||||||
|
hash = sha512.New384()
|
||||||
|
case "sha256":
|
||||||
|
hash = sha256.New()
|
||||||
|
case "sha512":
|
||||||
|
hash = sha512.New()
|
||||||
|
default:
|
||||||
|
hash = sha256.New()
|
||||||
|
}
|
||||||
|
_, err = io.Copy(hash, file)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return hex.EncodeToString(hash.Sum(nil)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
if a.isCompressed {
|
||||||
|
return a.ZipFile()
|
||||||
|
}
|
||||||
|
return a.path, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName of asset
|
||||||
|
func (a *Asset) GetName() string {
|
||||||
|
if a.isCompressed {
|
||||||
|
return fmt.Sprintf("%s.zip", a.name)
|
||||||
|
}
|
||||||
|
return a.name
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsCompressed return true if file was zipped
|
||||||
|
func (a *Asset) IsCompressed() bool {
|
||||||
|
return a.isCompressed
|
||||||
|
}
|
||||||
|
|
||||||
|
// ZipFile compress given file in zip format
|
||||||
|
func (a *Asset) ZipFile() (string, error) {
|
||||||
|
|
||||||
|
if a.zippedPath != "" {
|
||||||
|
return a.zippedPath, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
path := a.path
|
||||||
|
fileToZip, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.Wrapf(err, "Could not open file %s", path)
|
||||||
|
}
|
||||||
|
defer fileToZip.Close()
|
||||||
|
|
||||||
|
zipFile, err := ioutil.TempFile(os.TempDir(), "asset.*.zip")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.Wrap(err, "Could not generate tmp file")
|
||||||
|
}
|
||||||
|
log.Debugf("Created zipfile %s", zipFile.Name())
|
||||||
|
|
||||||
|
fileToZipInfo, err := fileToZip.Stat()
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.Wrap(err, "Could not read file infos")
|
||||||
|
}
|
||||||
|
|
||||||
|
zipWriter := zip.NewWriter(zipFile)
|
||||||
|
|
||||||
|
fileToZipHeader, err := zip.FileInfoHeader(fileToZipInfo)
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.Wrap(err, "Could not add file infos to zip handler")
|
||||||
|
}
|
||||||
|
|
||||||
|
fileToZipHeader.Name = fileToZipInfo.Name()
|
||||||
|
|
||||||
|
fileToZipWriter, err := zipWriter.CreateHeader(fileToZipHeader)
|
||||||
|
if err != nil {
|
||||||
|
return "", errors.Wrap(err, "Could not create zip header")
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = io.Copy(fileToZipWriter, fileToZip); err != nil {
|
||||||
|
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 {
|
||||||
|
return "", errors.Wrap(err, "Could not close file")
|
||||||
|
}
|
||||||
|
a.zippedPath, err = filepath.Abs(zipFile.Name())
|
||||||
|
|
||||||
|
return a.zippedPath, err
|
||||||
|
}
|
||||||
79
internal/assets/assets.go
Normal file
79
internal/assets/assets.go
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
package assets
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Set struct
|
||||||
|
type Set struct {
|
||||||
|
assets []*Asset
|
||||||
|
repository string
|
||||||
|
algorithm string
|
||||||
|
}
|
||||||
|
|
||||||
|
//New container for assets
|
||||||
|
func New(repository, algorithm string) *Set {
|
||||||
|
return &Set{
|
||||||
|
assets: []*Asset{},
|
||||||
|
repository: repository,
|
||||||
|
algorithm: algorithm,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add assets to the list
|
||||||
|
func (s *Set) Add(assetConfigs ...config.Asset) error {
|
||||||
|
for _, assetConfig := range assetConfigs {
|
||||||
|
asset, err := NewAsset(s.repository, assetConfig, s.algorithm)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s.assets = append(s.assets, asset)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Set) All() []*Asset {
|
||||||
|
return s.assets
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Set) GenerateChecksum() error {
|
||||||
|
checksumFile, err := ioutil.TempFile(os.TempDir(), "checksum.*.txt")
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "Could not generate tmp file for checksum")
|
||||||
|
}
|
||||||
|
defer checksumFile.Close()
|
||||||
|
lines := []string{}
|
||||||
|
for _, asset := range s.assets {
|
||||||
|
checksum, err := asset.getChecksum()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
lines = append(lines, fmt.Sprintf("%s %s", checksum, asset.GetName()))
|
||||||
|
}
|
||||||
|
|
||||||
|
w := bufio.NewWriter(checksumFile)
|
||||||
|
for _, line := range lines {
|
||||||
|
fmt.Fprintln(w, line)
|
||||||
|
}
|
||||||
|
|
||||||
|
filePath, err := filepath.Abs(checksumFile.Name())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
s.assets = append(s.assets, &Asset{
|
||||||
|
path: filePath,
|
||||||
|
name: "checksum.txt",
|
||||||
|
isCompressed: false,
|
||||||
|
algorithm: "",
|
||||||
|
})
|
||||||
|
return w.Flush()
|
||||||
|
|
||||||
|
}
|
||||||
56
internal/cache/cache.go
vendored
56
internal/cache/cache.go
vendored
@@ -5,49 +5,61 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/Masterminds/semver"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ReleaseVersion struct
|
|
||||||
type ReleaseVersion struct {
|
|
||||||
Last ReleaseVersionEntry `yaml:"last"`
|
|
||||||
Next ReleaseVersionEntry `yaml:"next"`
|
|
||||||
Branch string `yaml:"branch"`
|
|
||||||
Draft bool `yaml:"draft"`
|
|
||||||
}
|
|
||||||
|
|
||||||
//ReleaseVersionEntry struct
|
|
||||||
type ReleaseVersionEntry struct {
|
|
||||||
Commit string `yaml:"commit"`
|
|
||||||
Version string `yaml:"version"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write version into .version
|
// Write version into .version
|
||||||
func Write(repository string, versionFileContent ReleaseVersion) error {
|
func Write(repository string, releaseVersion shared.ReleaseVersion) error {
|
||||||
completePath := path.Join(path.Dir(repository), ".version")
|
completePath := path.Join(path.Dir(repository), ".version")
|
||||||
|
|
||||||
data, err := yaml.Marshal(&versionFileContent)
|
if releaseVersion.Last.Version != nil {
|
||||||
|
releaseVersion.Last.VersionString = releaseVersion.Last.Version.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
if releaseVersion.Next.Version != nil {
|
||||||
|
releaseVersion.Next.VersionString = releaseVersion.Next.Version.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
//toCache := &ReleaseVersion(releaseVersion)
|
||||||
|
data, err := yaml.Marshal(releaseVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Infof("Save %s with hash %s to cache %s", releaseVersion.Next.Version.String(), releaseVersion.Next.Commit, completePath)
|
||||||
return ioutil.WriteFile(completePath, data, 0644)
|
return ioutil.WriteFile(completePath, data, 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read version into .version
|
// Read version into .version
|
||||||
func Read(repository string) (*ReleaseVersion, error) {
|
func Read(repository string) (*shared.ReleaseVersion, error) {
|
||||||
completePath := path.Join(path.Dir(repository), ".version")
|
completePath := path.Join(path.Dir(repository), ".version")
|
||||||
|
|
||||||
content, err := ioutil.ReadFile(completePath)
|
content, err := ioutil.ReadFile(completePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &ReleaseVersion{}, err
|
log.Warnf("Could not read cache %s, will ignore cache", completePath)
|
||||||
|
return &shared.ReleaseVersion{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var versionFileContent ReleaseVersion
|
var parsedContent shared.ReleaseVersion
|
||||||
err = yaml.Unmarshal(content, &versionFileContent)
|
err = yaml.Unmarshal(content, &parsedContent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &ReleaseVersion{}, err
|
return &shared.ReleaseVersion{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &versionFileContent, nil
|
parsedContent.Next.Version, err = semver.NewVersion(parsedContent.Next.VersionString)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
parsedContent.Last.Version, err = semver.NewVersion(parsedContent.Last.VersionString)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("Found cache, will return cached version %s", parsedContent.Next.Version)
|
||||||
|
return &parsedContent, nil
|
||||||
}
|
}
|
||||||
|
|||||||
110
internal/cache/cache_test.go
vendored
Normal file
110
internal/cache/cache_test.go
vendored
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
package cache_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"github.com/Masterminds/semver"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/cache"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestReadCacheNotFound(t *testing.T) {
|
||||||
|
|
||||||
|
resp, err := cache.Read("notfound/dir")
|
||||||
|
assert.NoErrorf(t, err, "Read non exsiting file")
|
||||||
|
assert.NotNil(t, resp)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadCacheInvalidContent(t *testing.T) {
|
||||||
|
|
||||||
|
dir, err := ioutil.TempDir("", "prefix")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
|
completePath := path.Join(path.Dir(dir), ".version")
|
||||||
|
brokenContent := []byte("hello broken\ngo: lang\n")
|
||||||
|
err = ioutil.WriteFile(completePath, brokenContent, 0644)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
_, readError := cache.Read(dir)
|
||||||
|
assert.Errorf(t, readError, "Should give error, when broken content")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWriteAndReadCache(t *testing.T) {
|
||||||
|
|
||||||
|
dir, err := ioutil.TempDir("", "prefix")
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
content := shared.ReleaseVersion{
|
||||||
|
Last: shared.ReleaseVersionEntry{
|
||||||
|
Commit: "12345",
|
||||||
|
Version: createVersion("1.0.0"),
|
||||||
|
VersionString: "1.0.0",
|
||||||
|
},
|
||||||
|
Next: shared.ReleaseVersionEntry{
|
||||||
|
Commit: "12346",
|
||||||
|
Version: createVersion("1.1.0"),
|
||||||
|
VersionString: "1.1.0",
|
||||||
|
},
|
||||||
|
Branch: "master",
|
||||||
|
Commits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
|
"major": {
|
||||||
|
{
|
||||||
|
Commit: shared.Commit{
|
||||||
|
Message: "Message",
|
||||||
|
Author: "Author",
|
||||||
|
Hash: "Hash",
|
||||||
|
},
|
||||||
|
ParsedMessage: "add gitlab as release option",
|
||||||
|
Scope: "releaser",
|
||||||
|
ParsedBreakingChangeMessage: "",
|
||||||
|
Tag: "feat",
|
||||||
|
TagString: "Features",
|
||||||
|
Print: true,
|
||||||
|
Subject: "add gitlab as release option",
|
||||||
|
MessageBlocks: map[string][]shared.MessageBlock{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
|
writeError := cache.Write(dir, content)
|
||||||
|
assert.NoErrorf(t, writeError, "Should write file")
|
||||||
|
result, readError := cache.Read(dir)
|
||||||
|
assert.NoErrorf(t, readError, "Should read file")
|
||||||
|
|
||||||
|
assert.EqualValues(t, &content, result)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWriteNotFound(t *testing.T) {
|
||||||
|
|
||||||
|
err := cache.Write("notfound/dir", shared.ReleaseVersion{
|
||||||
|
Last: shared.ReleaseVersionEntry{
|
||||||
|
Commit: "12345",
|
||||||
|
Version: createVersion("1.0.0"),
|
||||||
|
},
|
||||||
|
Next: shared.ReleaseVersionEntry{
|
||||||
|
Commit: "12346",
|
||||||
|
Version: createVersion("1.1.0"),
|
||||||
|
},
|
||||||
|
Branch: "master",
|
||||||
|
})
|
||||||
|
assert.Errorf(t, err, "Write non exsiting file")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func createVersion(version string) *semver.Version {
|
||||||
|
ver, _ := semver.NewVersion(version)
|
||||||
|
return ver
|
||||||
|
}
|
||||||
87
internal/calculator/calculator.go
Normal file
87
internal/calculator/calculator.go
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
package calculator
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Masterminds/semver"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Calculator struct
|
||||||
|
type Calculator struct{}
|
||||||
|
|
||||||
|
// New Calculator struct
|
||||||
|
func New() *Calculator {
|
||||||
|
return &Calculator{}
|
||||||
|
}
|
||||||
|
|
||||||
|
//IncPrerelease increase prerelease by one
|
||||||
|
func (c *Calculator) IncPrerelease(preReleaseType string, version semver.Version) (semver.Version, error) {
|
||||||
|
defaultPrerelease := preReleaseType + ".0"
|
||||||
|
if !c.hasPrerelease(version, preReleaseType) {
|
||||||
|
return version.SetPrerelease(defaultPrerelease)
|
||||||
|
}
|
||||||
|
|
||||||
|
parts := strings.Split(version.Prerelease(), ".")
|
||||||
|
if len(parts) == 2 {
|
||||||
|
i, err := strconv.Atoi(parts[1])
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("Could not parse release tag %s, use version %s", version.Prerelease(), version.String())
|
||||||
|
return version.SetPrerelease(defaultPrerelease)
|
||||||
|
}
|
||||||
|
return version.SetPrerelease(preReleaseType + "." + strconv.Itoa(i+1))
|
||||||
|
|
||||||
|
}
|
||||||
|
log.Warnf("Could not parse release tag %s, use version %s", version.Prerelease(), version.String())
|
||||||
|
return version.SetPrerelease(defaultPrerelease)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Calculator) hasPrerelease(version semver.Version, preReleaseType string) bool {
|
||||||
|
if version.Prerelease() == "" || !strings.HasPrefix(version.Prerelease(), preReleaseType) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
//CalculateNewVersion from given commits and lastversion
|
||||||
|
func (c *Calculator) CalculateNewVersion(commits map[shared.Release][]shared.AnalyzedCommit, lastVersion *semver.Version, releaseType string, firstRelease bool) semver.Version {
|
||||||
|
switch releaseType {
|
||||||
|
case "beta", "alpha", "rc":
|
||||||
|
var version = *lastVersion
|
||||||
|
if !c.hasPrerelease(*lastVersion, releaseType) {
|
||||||
|
version, _ = c.inc(commits, lastVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(commits["major"]) > 0 || len(commits["minor"]) > 0 || len(commits["patch"]) > 0 {
|
||||||
|
version, _ := c.IncPrerelease(releaseType, version)
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
case "release":
|
||||||
|
if !firstRelease {
|
||||||
|
if lastVersion.Prerelease() != "" {
|
||||||
|
newVersion, _ := lastVersion.SetPrerelease("")
|
||||||
|
return newVersion
|
||||||
|
}
|
||||||
|
version, done := c.inc(commits, lastVersion)
|
||||||
|
if done {
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *lastVersion
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Calculator) inc(commits map[shared.Release][]shared.AnalyzedCommit, lastVersion *semver.Version) (semver.Version, bool) {
|
||||||
|
if len(commits["major"]) > 0 {
|
||||||
|
return lastVersion.IncMajor(), true
|
||||||
|
} else if len(commits["minor"]) > 0 {
|
||||||
|
return lastVersion.IncMinor(), true
|
||||||
|
} else if len(commits["patch"]) > 0 {
|
||||||
|
return lastVersion.IncPatch(), true
|
||||||
|
}
|
||||||
|
return semver.Version{}, false
|
||||||
|
}
|
||||||
212
internal/calculator/calculator_test.go
Normal file
212
internal/calculator/calculator_test.go
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
package calculator_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Masterminds/semver"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/calculator"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func createVersion(version string) *semver.Version {
|
||||||
|
ver, _ := semver.NewVersion(version)
|
||||||
|
return ver
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCalculator_IncPrerelease(t *testing.T) {
|
||||||
|
|
||||||
|
testConfigs := []struct {
|
||||||
|
testCase string
|
||||||
|
preReleaseType string
|
||||||
|
lastVersion *semver.Version
|
||||||
|
nextVersion string
|
||||||
|
hasError bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
testCase: "version without preRelease",
|
||||||
|
preReleaseType: "alpha",
|
||||||
|
lastVersion: createVersion("1.0.0"),
|
||||||
|
nextVersion: "1.0.0-alpha.0",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "version with preRelease",
|
||||||
|
preReleaseType: "alpha",
|
||||||
|
lastVersion: createVersion("1.0.0-alpha.0"),
|
||||||
|
nextVersion: "1.0.0-alpha.1",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "version with preRelease, change type",
|
||||||
|
preReleaseType: "beta",
|
||||||
|
lastVersion: createVersion("1.0.0-alpha.0"),
|
||||||
|
nextVersion: "1.0.0-beta.0",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "version with preRelease but broken",
|
||||||
|
preReleaseType: "alpha",
|
||||||
|
lastVersion: createVersion("1.0.0-alpha.br0ken"),
|
||||||
|
nextVersion: "1.0.0-alpha.0",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "version with preRelease but broken 2",
|
||||||
|
preReleaseType: "alpha",
|
||||||
|
lastVersion: createVersion("1.0.0-alphabr0ken"),
|
||||||
|
nextVersion: "1.0.0-alpha.0",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
c := calculator.New()
|
||||||
|
|
||||||
|
for _, test := range testConfigs {
|
||||||
|
t.Run(test.testCase, func(t *testing.T) {
|
||||||
|
next, err := c.IncPrerelease(test.preReleaseType, *test.lastVersion)
|
||||||
|
assert.Equalf(t, test.hasError, err != nil, "Testcase %s should have error: %t -> %s", test.testCase, test.hasError, err)
|
||||||
|
assert.Equal(t, test.nextVersion, next.String())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCalculator_CalculateNewVersion(t *testing.T) {
|
||||||
|
|
||||||
|
testConfigs := []struct {
|
||||||
|
testCase string
|
||||||
|
releaseType string
|
||||||
|
lastVersion *semver.Version
|
||||||
|
nextVersion string
|
||||||
|
isFirst bool
|
||||||
|
analyzedCommits map[shared.Release][]shared.AnalyzedCommit
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
testCase: "version with preRelease alpha",
|
||||||
|
releaseType: "alpha",
|
||||||
|
lastVersion: createVersion("1.0.0"),
|
||||||
|
nextVersion: "1.1.0-alpha.0",
|
||||||
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
|
"major": {},
|
||||||
|
"minor": {
|
||||||
|
{},
|
||||||
|
},
|
||||||
|
"patch": {},
|
||||||
|
"none": {},
|
||||||
|
},
|
||||||
|
isFirst: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "version with preRelease beta",
|
||||||
|
releaseType: "beta",
|
||||||
|
lastVersion: createVersion("1.0.0"),
|
||||||
|
nextVersion: "1.1.0-beta.0",
|
||||||
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
|
"major": {},
|
||||||
|
"minor": {
|
||||||
|
{},
|
||||||
|
},
|
||||||
|
"patch": {},
|
||||||
|
"none": {},
|
||||||
|
},
|
||||||
|
isFirst: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "version without commits",
|
||||||
|
releaseType: "alpha",
|
||||||
|
lastVersion: createVersion("1.0.0"),
|
||||||
|
nextVersion: "1.0.0",
|
||||||
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
|
"major": {},
|
||||||
|
"minor": {},
|
||||||
|
"patch": {},
|
||||||
|
"none": {},
|
||||||
|
},
|
||||||
|
isFirst: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "version with commits and first release",
|
||||||
|
releaseType: "release",
|
||||||
|
lastVersion: createVersion("1.0.0"),
|
||||||
|
nextVersion: "1.0.0",
|
||||||
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
|
"major": {{}},
|
||||||
|
"minor": {},
|
||||||
|
"patch": {},
|
||||||
|
"none": {},
|
||||||
|
},
|
||||||
|
isFirst: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "version with commits and rc release",
|
||||||
|
releaseType: "rc",
|
||||||
|
lastVersion: createVersion("1.0.0"),
|
||||||
|
nextVersion: "2.0.0-rc.0",
|
||||||
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
|
"major": {{}},
|
||||||
|
"minor": {{}},
|
||||||
|
"patch": {{}},
|
||||||
|
"none": {},
|
||||||
|
},
|
||||||
|
isFirst: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "version with commits and rc release",
|
||||||
|
releaseType: "rc",
|
||||||
|
lastVersion: createVersion("1.0.0-rc.0"),
|
||||||
|
nextVersion: "1.0.0-rc.1",
|
||||||
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
|
"major": {},
|
||||||
|
"minor": {{}},
|
||||||
|
"patch": {{}},
|
||||||
|
"none": {},
|
||||||
|
},
|
||||||
|
isFirst: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "version with commits and major release",
|
||||||
|
releaseType: "release",
|
||||||
|
lastVersion: createVersion("1.0.0"),
|
||||||
|
nextVersion: "2.0.0",
|
||||||
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
|
"major": {{}},
|
||||||
|
"minor": {{}},
|
||||||
|
"patch": {{}},
|
||||||
|
"none": {},
|
||||||
|
},
|
||||||
|
isFirst: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "version with commits and minor release",
|
||||||
|
releaseType: "release",
|
||||||
|
lastVersion: createVersion("1.0.0"),
|
||||||
|
nextVersion: "1.1.0",
|
||||||
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
|
"major": {},
|
||||||
|
"minor": {{}},
|
||||||
|
"patch": {{}},
|
||||||
|
"none": {},
|
||||||
|
},
|
||||||
|
isFirst: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "version with commits and minor patch",
|
||||||
|
releaseType: "release",
|
||||||
|
lastVersion: createVersion("1.0.0"),
|
||||||
|
nextVersion: "1.0.1",
|
||||||
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
|
"major": {},
|
||||||
|
"minor": {},
|
||||||
|
"patch": {{}},
|
||||||
|
"none": {},
|
||||||
|
},
|
||||||
|
isFirst: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
c := calculator.New()
|
||||||
|
|
||||||
|
for _, test := range testConfigs {
|
||||||
|
t.Run(test.testCase, func(t *testing.T) {
|
||||||
|
next := c.CalculateNewVersion(test.analyzedCommits, test.lastVersion, test.releaseType, test.isFirst)
|
||||||
|
assert.Equalf(t, test.nextVersion, next.String(), "Should have version %s for testcase %s", test.nextVersion, test.testCase)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
package changelog
|
package changelog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"io/ioutil"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
@@ -13,24 +16,112 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultChangelogTitle string = `v{{.Version}} ({{.Now.Format "2006-01-02"}})`
|
const defaultCommitList string = `{{ range $index,$commit := .BreakingChanges -}}
|
||||||
const defaultChangelog string = `# v{{$.Version}} ({{.Now.Format "2006-01-02"}})
|
{{ if eq $index 0 -}}
|
||||||
{{ range $key := .Order }}
|
## BREAKING CHANGES
|
||||||
{{ $commits := index $.Commits $key}} {{if $commits -}}
|
{{ end -}}
|
||||||
|
* {{ if $commit.Scope }}**{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}**{{ end }} {{$commit.ParsedBreakingChangeMessage}}
|
||||||
|
introduced by commit:
|
||||||
|
{{$commit.Subject}} {{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 }}
|
### {{ $key }}
|
||||||
{{ range $index,$commit := $commits -}}
|
{{ range $index,$commit := $commits -}}
|
||||||
* **{{$.Backtick}}{{$commit.Scope}}{{$.Backtick}}** {{$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 defaultCommitListSubTemplate = `{{ define "commitList" }}` + defaultCommitList + "{{ end }}"
|
||||||
|
const defaultChangelogTitle = `v{{.Version}} ({{.Now.Format "2006-01-02"}})`
|
||||||
|
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}}
|
||||||
|
## Docker image
|
||||||
|
|
||||||
|
New docker image is released under {{$.Backtick}}{{.DockerRepository}}:{{.Version}}{{$.Backtick}}
|
||||||
|
|
||||||
|
### Usage
|
||||||
|
|
||||||
|
{{$.Backtick}}docker run {{.DockerRepository}}:{{.Version}}{{$.Backtick}}
|
||||||
|
{{ if .HasDockerLatest}}
|
||||||
|
or
|
||||||
|
|
||||||
|
{{$.Backtick}}docker run {{.DockerRepository}}:latest{{$.Backtick}}
|
||||||
|
{{ 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 map[string][]analyzer.AnalyzedCommit
|
Commits string
|
||||||
Order []string
|
CommitsContent commitsContent
|
||||||
Version string
|
Version string
|
||||||
Now time.Time
|
Now time.Time
|
||||||
Backtick string
|
Backtick string
|
||||||
|
ShowBodyAsHeader bool
|
||||||
|
HasDocker bool
|
||||||
|
HasDockerLatest bool
|
||||||
|
DockerRepository string
|
||||||
|
HasNPM bool
|
||||||
|
IsYarn bool
|
||||||
|
NPMRepository string
|
||||||
|
NPMPackageName string
|
||||||
|
Authors []string
|
||||||
|
ShowAuthors bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type commitsContent struct {
|
||||||
|
Commits map[string][]shared.AnalyzedCommit
|
||||||
|
BreakingChanges []shared.AnalyzedCommit
|
||||||
|
Order []string
|
||||||
|
ShowBodyAsHeader bool
|
||||||
|
Backtick string
|
||||||
HasURL bool
|
HasURL bool
|
||||||
URL string
|
URL string
|
||||||
}
|
}
|
||||||
@@ -39,63 +130,137 @@ type changelogContent struct {
|
|||||||
type Changelog struct {
|
type Changelog struct {
|
||||||
config *config.ReleaseConfig
|
config *config.ReleaseConfig
|
||||||
rules []analyzer.Rule
|
rules []analyzer.Rule
|
||||||
|
releaseTime time.Time
|
||||||
|
log *log.Entry
|
||||||
}
|
}
|
||||||
|
|
||||||
//New Changelog struct for generating changelog from commits
|
//New Changelog struct for generating changelog from commits
|
||||||
func New(config *config.ReleaseConfig, rules []analyzer.Rule) *Changelog {
|
func New(config *config.ReleaseConfig, rules []analyzer.Rule, releaseTime time.Time) *Changelog {
|
||||||
return &Changelog{
|
return &Changelog{
|
||||||
config: config,
|
config: config,
|
||||||
rules: rules,
|
rules: rules,
|
||||||
|
releaseTime: releaseTime,
|
||||||
|
log: log.WithField("changelog", config.CommitFormat),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateChanglog from given commits
|
// GenerateChangelog from given commits
|
||||||
func (c *Changelog) GenerateChanglog(templateConfig shared.ChangelogTemplateConfig, analyzedCommits map[string][]analyzer.AnalyzedCommit) (*shared.GeneratedChangelog, error) {
|
func (c *Changelog) GenerateChangelog(templateConfig shared.ChangelogTemplateConfig, analyzedCommits map[shared.Release][]shared.AnalyzedCommit) (*shared.GeneratedChangelog, error) {
|
||||||
|
|
||||||
commitsPerScope := map[string][]analyzer.AnalyzedCommit{}
|
commitsPerScope := map[string][]shared.AnalyzedCommit{}
|
||||||
|
var commitsBreakingChange []shared.AnalyzedCommit
|
||||||
order := make([]string, 0)
|
order := make([]string, 0)
|
||||||
|
|
||||||
for _, rule := range c.rules {
|
for _, rule := range c.rules {
|
||||||
log.Debugf("Add %s to list", rule.TagString)
|
c.log.Tracef("Add %s to list", rule.TagString)
|
||||||
if rule.Changelog || c.config.Changelog.PrintAll {
|
if rule.Changelog || c.config.Changelog.PrintAll {
|
||||||
order = append(order, rule.TagString)
|
order = append(order, rule.TagString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.IsBreaking {
|
||||||
|
commitsBreakingChange = append(commitsBreakingChange, commit)
|
||||||
|
continue
|
||||||
|
}
|
||||||
if _, ok := commitsPerScope[commit.TagString]; !ok {
|
if _, ok := commitsPerScope[commit.TagString]; !ok {
|
||||||
commitsPerScope[commit.TagString] = make([]analyzer.AnalyzedCommit, 0)
|
commitsPerScope[commit.TagString] = make([]shared.AnalyzedCommit, 0)
|
||||||
}
|
}
|
||||||
commitsPerScope[commit.TagString] = append(commitsPerScope[commit.TagString], commit)
|
commitsPerScope[commit.TagString] = append(commitsPerScope[commit.TagString], commit)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
changelogContent := changelogContent{
|
commitsContent := commitsContent{
|
||||||
Version: templateConfig.Version,
|
|
||||||
Commits: commitsPerScope,
|
Commits: commitsPerScope,
|
||||||
Now: time.Now(),
|
BreakingChanges: commitsBreakingChange,
|
||||||
Backtick: "`",
|
Backtick: "`",
|
||||||
Order: order,
|
Order: order,
|
||||||
|
ShowBodyAsHeader: c.config.Changelog.ShowBodyAsHeader,
|
||||||
HasURL: templateConfig.CommitURL != "",
|
HasURL: templateConfig.CommitURL != "",
|
||||||
URL: templateConfig.CommitURL,
|
URL: templateConfig.CommitURL,
|
||||||
}
|
}
|
||||||
|
|
||||||
title, err := generateTemplate(defaultChangelogTitle, changelogContent)
|
authorsNames := make([]string, len(authors))
|
||||||
|
i := 0
|
||||||
|
for k := range authors {
|
||||||
|
authorsNames[i] = k
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Strings(authorsNames)
|
||||||
|
|
||||||
|
changelogContent := changelogContent{
|
||||||
|
CommitsContent: commitsContent,
|
||||||
|
Version: templateConfig.Version,
|
||||||
|
Now: c.releaseTime,
|
||||||
|
Backtick: "`",
|
||||||
|
HasDocker: c.config.Changelog.Docker.Repository != "",
|
||||||
|
HasDockerLatest: c.config.Changelog.Docker.Latest,
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
||||||
|
chglogTemplate := defaultCommitListSubTemplate + defaultChangelog
|
||||||
|
if c.config.Changelog.TemplatePath != "" {
|
||||||
|
content, err := ioutil.ReadFile(c.config.Changelog.TemplatePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
content, err := generateTemplate(defaultChangelog, changelogContent)
|
chglogTemplate = string(content)
|
||||||
|
|
||||||
return &shared.GeneratedChangelog{Title: title, Content: content}, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateTemplate(text string, values changelogContent) (string, error) {
|
templateTitle := defaultChangelogTitle
|
||||||
|
if c.config.Changelog.TemplateTitle != "" {
|
||||||
|
templateTitle = c.config.Changelog.TemplateTitle
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("Render title")
|
||||||
|
renderedTitle, err := generateTemplate(templateTitle, changelogContent, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("Render commits")
|
||||||
|
renderedCommitList, err := generateTemplate(defaultCommitList, commitsContent, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Tracef("Commits %s", renderedCommitList)
|
||||||
|
changelogContent.Commits = renderedCommitList
|
||||||
|
|
||||||
|
extraFuncMap := template.FuncMap{
|
||||||
|
"commitUrl": func() string { return templateConfig.CommitURL },
|
||||||
|
}
|
||||||
|
log.Debugf("Render changelog")
|
||||||
|
renderedContent, err := generateTemplate(chglogTemplate, changelogContent, extraFuncMap)
|
||||||
|
|
||||||
|
return &shared.GeneratedChangelog{Title: renderedTitle, Content: renderedContent}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
@@ -113,3 +278,30 @@ func generateTemplate(text string, values changelogContent) (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
|
||||||
|
}
|
||||||
|
|||||||
414
internal/changelog/changelog_test.go
Normal file
414
internal/changelog/changelog_test.go
Normal file
@@ -0,0 +1,414 @@
|
|||||||
|
package changelog_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/analyzer"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/changelog"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestChangelog(t *testing.T) {
|
||||||
|
|
||||||
|
templateConfig := shared.ChangelogTemplateConfig{
|
||||||
|
CommitURL: "https://commit.url",
|
||||||
|
CompareURL: "https://compare.url",
|
||||||
|
Hash: "hash",
|
||||||
|
Version: "1.0.0",
|
||||||
|
}
|
||||||
|
|
||||||
|
testConfigs := []struct {
|
||||||
|
testCase string
|
||||||
|
analyzedCommits map[shared.Release][]shared.AnalyzedCommit
|
||||||
|
result *shared.GeneratedChangelog
|
||||||
|
hasError bool
|
||||||
|
showAuthors bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
testCase: "feat",
|
||||||
|
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{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
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",
|
||||||
|
},
|
||||||
|
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",
|
||||||
|
analyzedCommits: map[shared.Release][]shared.AnalyzedCommit{
|
||||||
|
"minor": {
|
||||||
|
{
|
||||||
|
Commit: shared.Commit{
|
||||||
|
Message: "feat: my first commit",
|
||||||
|
Author: "me",
|
||||||
|
Hash: "12345667",
|
||||||
|
},
|
||||||
|
ParsedMessage: "my first commit",
|
||||||
|
Tag: "feat",
|
||||||
|
TagString: "Features",
|
||||||
|
Print: true,
|
||||||
|
Subject: "my first 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* my first commit ([1234566](https://commit.url))\n",
|
||||||
|
},
|
||||||
|
hasError: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "feat breaking change",
|
||||||
|
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 first break: BREAKING CHANGE: change api to v2",
|
||||||
|
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{
|
||||||
|
"body": {shared.MessageBlock{
|
||||||
|
Label: "BREAKING CHANGE",
|
||||||
|
Content: "change api to v2",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
result: &shared.GeneratedChangelog{
|
||||||
|
Title: "v1.0.0 (2019-07-19)",
|
||||||
|
Content: "# v1.0.0 (2019-07-19)\n## BREAKING CHANGES\n* **`internal/changelog`** change api to v2 \nintroduced by commit: \nmy first break ([1234566](https://commit.url))\n### Features\n* **`internal/changelog`** my first commit ([1234566](https://commit.url))\n",
|
||||||
|
},
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
testCase: "docker",
|
||||||
|
releaseConfig: &config.ReleaseConfig{
|
||||||
|
Changelog: config.ChangelogConfig{
|
||||||
|
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"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testCase: "npm",
|
||||||
|
releaseConfig: &config.ReleaseConfig{
|
||||||
|
Changelog: config.ChangelogConfig{
|
||||||
|
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"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
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{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, config := range testConfigs {
|
||||||
|
t.Run(config.testCase, func(t *testing.T) {
|
||||||
|
templateConfig := shared.ChangelogTemplateConfig{
|
||||||
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,10 @@ package ci
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@@ -21,24 +25,42 @@ type ProviderConfig struct {
|
|||||||
|
|
||||||
// Service interface
|
// Service interface
|
||||||
type Service interface {
|
type Service interface {
|
||||||
Detect() (*ProviderConfig, error)
|
detect(envs map[string]string) (*ProviderConfig, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReadAllEnvs as a map
|
||||||
|
func ReadAllEnvs() map[string]string {
|
||||||
|
envs := map[string]string{}
|
||||||
|
for _, pair := range os.Environ() {
|
||||||
|
splitted := strings.SplitN(pair, "=", 2)
|
||||||
|
envs[splitted[0]] = splitted[1]
|
||||||
|
}
|
||||||
|
return envs
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCIProvider get provider
|
// GetCIProvider get provider
|
||||||
func GetCIProvider(gitUtil *gitutil.GitUtil) (*ProviderConfig, error) {
|
func GetCIProvider(gitUtil *gitutil.GitUtil, configCheck bool, envs map[string]string) (*ProviderConfig, error) {
|
||||||
|
|
||||||
services := []Service{
|
services := []Service{
|
||||||
Travis{},
|
Travis{},
|
||||||
Git{gitUtil: gitUtil}, // GIt must be the last option to check
|
GithubActions{},
|
||||||
|
GitlabCI{},
|
||||||
|
WoodpeckerCI{},
|
||||||
|
Git{gitUtil: gitUtil}, // Git must be the last option to check
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, service := range services {
|
for _, service := range services {
|
||||||
config, err := service.Detect()
|
config, err := service.detect(envs)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Infof("Found CI: %s", config.Name)
|
log.Infof("Found CI: %s", config.Name)
|
||||||
|
log.Tracef("Found CI config: %+v", config)
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
log.Debugf("%s", err.Error())
|
log.Debugf("%s", err.Error())
|
||||||
}
|
}
|
||||||
|
if configCheck {
|
||||||
return nil, fmt.Errorf("could not find any CI, if running locally set env CI=true")
|
return nil, fmt.Errorf("could not find any CI, if running locally set env CI=true")
|
||||||
|
|
||||||
|
}
|
||||||
|
return Git{gitUtil: gitUtil}.detect(map[string]string{"CI": "true"})
|
||||||
}
|
}
|
||||||
|
|||||||
135
internal/ci/ci_test.go
Normal file
135
internal/ci/ci_test.go
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
package ci_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/ci"
|
||||||
|
"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"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCi(t *testing.T) {
|
||||||
|
|
||||||
|
fs := memfs.New()
|
||||||
|
|
||||||
|
repository, err := git.Init(memory.NewStorage(), fs)
|
||||||
|
assert.NoError(t, err, "should open git repository")
|
||||||
|
|
||||||
|
file, err := fs.Create("README.md")
|
||||||
|
assert.NoError(t, err, "should create file")
|
||||||
|
|
||||||
|
w, err := repository.Worktree()
|
||||||
|
assert.NoError(t, err, "should get worktree")
|
||||||
|
|
||||||
|
_, err = w.Add(file.Name())
|
||||||
|
assert.NoError(t, err, "should add file")
|
||||||
|
|
||||||
|
gitUtilInMemory := &gitutil.GitUtil{
|
||||||
|
Repository: repository,
|
||||||
|
}
|
||||||
|
|
||||||
|
newCommit, err := w.Commit("fix(test): add a commit", &git.CommitOptions{
|
||||||
|
Author: &object.Signature{
|
||||||
|
Name: "John Doe",
|
||||||
|
Email: "john@doe.org",
|
||||||
|
When: time.Now(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
assert.NoError(t, err, "should commit")
|
||||||
|
|
||||||
|
testConfigs := []struct {
|
||||||
|
service string
|
||||||
|
envs map[string]string
|
||||||
|
result *ci.ProviderConfig
|
||||||
|
hasError bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
service: "none",
|
||||||
|
envs: map[string]string{},
|
||||||
|
result: nil,
|
||||||
|
hasError: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
service: "Git",
|
||||||
|
envs: map[string]string{
|
||||||
|
"CI": "true",
|
||||||
|
},
|
||||||
|
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "master", Tag: "", Commit: newCommit.String(), BuildURL: "", Service: "git", Name: "Git only"},
|
||||||
|
hasError: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
service: "Travis PR",
|
||||||
|
envs: map[string]string{
|
||||||
|
"TRAVIS": "true",
|
||||||
|
"TRAVIS_PULL_REQUEST": "10",
|
||||||
|
"TRAVIS_COMMIT": "190bfd6aa60022afd0ef830342cfb07e33c45f37",
|
||||||
|
"TRAVIS_TAG": "TAG",
|
||||||
|
"TRAVIS_BUILD_WEB_URL": "https://travis-ci.com/owner/repo/builds/1234",
|
||||||
|
"TRAVIS_BRANCH": "master",
|
||||||
|
"TRAVIS_PULL_REQUEST_BRANCH": "pr",
|
||||||
|
},
|
||||||
|
result: &ci.ProviderConfig{IsPR: true, PR: "10", PRBranch: "pr", Branch: "master", Tag: "TAG", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "https://travis-ci.com/owner/repo/builds/1234", Service: "travis", Name: "Travis CI"},
|
||||||
|
hasError: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
service: "Travis Push",
|
||||||
|
envs: map[string]string{
|
||||||
|
"TRAVIS": "true",
|
||||||
|
"TRAVIS_PULL_REQUEST": "false",
|
||||||
|
"TRAVIS_COMMIT": "190bfd6aa60022afd0ef830342cfb07e33c45f37",
|
||||||
|
"TRAVIS_TAG": "TAG",
|
||||||
|
"TRAVIS_BUILD_WEB_URL": "https://travis-ci.com/owner/repo/builds/1234",
|
||||||
|
"TRAVIS_BRANCH": "master",
|
||||||
|
},
|
||||||
|
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "master", Tag: "TAG", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "https://travis-ci.com/owner/repo/builds/1234", Service: "travis", Name: "Travis CI"},
|
||||||
|
hasError: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
service: "Github Actions PR",
|
||||||
|
envs: map[string]string{
|
||||||
|
"GITHUB_EVENT_NAME": "pull_request",
|
||||||
|
"GITHUB_SHA": "190bfd6aa60022afd0ef830342cfb07e33c45f37",
|
||||||
|
"GITHUB_REF": "master",
|
||||||
|
"GITHUB_ACTION": "action",
|
||||||
|
},
|
||||||
|
result: &ci.ProviderConfig{IsPR: true, PR: "", PRBranch: "", Branch: "master", Tag: "", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "", Service: "GithubActions", Name: "GithubActions CI"},
|
||||||
|
hasError: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
service: "Github Actions Push",
|
||||||
|
envs: map[string]string{
|
||||||
|
"GITHUB_EVENT_NAME": "push",
|
||||||
|
"GITHUB_SHA": "190bfd6aa60022afd0ef830342cfb07e33c45f37",
|
||||||
|
"GITHUB_REF": "refs/heads/feature-branch-1",
|
||||||
|
"GITHUB_ACTION": "action",
|
||||||
|
},
|
||||||
|
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "feature-branch-1", Tag: "", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "", Service: "GithubActions", Name: "GithubActions CI"},
|
||||||
|
hasError: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
service: "GitLab CI/CD PR",
|
||||||
|
envs: map[string]string{
|
||||||
|
"GITLAB_CI": "true",
|
||||||
|
"CI_COMMIT_SHA": "190bfd6aa60022afd0ef830342cfb07e33c45f37",
|
||||||
|
"CI_COMMIT_REF_NAME": "master",
|
||||||
|
"CI_COMMIT_TAG": "tag",
|
||||||
|
"CI_PROJECT_URL": "https://my.gitlab.com",
|
||||||
|
"CI_PIPELINE_ID": "1",
|
||||||
|
},
|
||||||
|
result: &ci.ProviderConfig{IsPR: false, PR: "", PRBranch: "", Branch: "master", Tag: "tag", Commit: "190bfd6aa60022afd0ef830342cfb07e33c45f37", BuildURL: "https://my.gitlab.com/pipelines/1", Service: "gitlab", Name: "GitLab CI/CD"},
|
||||||
|
hasError: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, config := range testConfigs {
|
||||||
|
provider, err := ci.GetCIProvider(gitUtilInMemory, true, config.envs)
|
||||||
|
assert.Equalf(t, config.hasError, err != nil, "Service %s should have error: %t -> %s", config.service, config.hasError, err)
|
||||||
|
assert.Equalf(t, config.result, provider, "Service %s should have provider", config.service)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@ package ci
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//Git struct
|
//Git struct
|
||||||
@@ -12,9 +11,9 @@ type Git struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Detect if on Git
|
//Detect if on Git
|
||||||
func (t Git) Detect() (*ProviderConfig, error) {
|
func (t Git) detect(envs map[string]string) (*ProviderConfig, error) {
|
||||||
|
|
||||||
if _, exists := os.LookupEnv("CI"); !exists {
|
if _, exists := envs["CI"]; !exists {
|
||||||
return nil, fmt.Errorf("running not git only")
|
return nil, fmt.Errorf("running not git only")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +28,7 @@ func (t Git) Detect() (*ProviderConfig, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &ProviderConfig{
|
return &ProviderConfig{
|
||||||
Service: "Git",
|
Service: "git",
|
||||||
Name: "Git only",
|
Name: "Git only",
|
||||||
Commit: hash,
|
Commit: hash,
|
||||||
Branch: currentBranch,
|
Branch: currentBranch,
|
||||||
|
|||||||
43
internal/ci/github_actions.go
Normal file
43
internal/ci/github_actions.go
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package ci
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
//GithubActions struct
|
||||||
|
type GithubActions struct{}
|
||||||
|
|
||||||
|
//Detect if on GithubActions
|
||||||
|
func (t GithubActions) detect(envs map[string]string) (*ProviderConfig, error) {
|
||||||
|
|
||||||
|
if _, exists := envs["GITHUB_ACTION"]; !exists {
|
||||||
|
return nil, fmt.Errorf("not running on Github Actions")
|
||||||
|
}
|
||||||
|
|
||||||
|
isPR := false
|
||||||
|
|
||||||
|
value := envs["GITHUB_EVENT_NAME"]
|
||||||
|
|
||||||
|
if value == "pull_request" {
|
||||||
|
isPR = true
|
||||||
|
} else {
|
||||||
|
log.Debugf("GITHUB_EVENT_NAME=%s, not running on pr", value)
|
||||||
|
}
|
||||||
|
|
||||||
|
branch := envs["GITHUB_REF"]
|
||||||
|
|
||||||
|
if strings.HasPrefix(envs["GITHUB_REF"], "refs/heads/") {
|
||||||
|
branch = strings.Replace(branch, "refs/heads/", "", 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ProviderConfig{
|
||||||
|
Service: "GithubActions",
|
||||||
|
Name: "GithubActions CI",
|
||||||
|
Commit: envs["GITHUB_SHA"],
|
||||||
|
Branch: branch,
|
||||||
|
IsPR: isPR,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
26
internal/ci/gitlab_ci.go
Normal file
26
internal/ci/gitlab_ci.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package ci
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
//GitlabCI struct
|
||||||
|
type GitlabCI struct{}
|
||||||
|
|
||||||
|
//Detect if on GitlabCI
|
||||||
|
func (t GitlabCI) detect(envs map[string]string) (*ProviderConfig, error) {
|
||||||
|
|
||||||
|
if _, exists := envs["GITLAB_CI"]; !exists {
|
||||||
|
return nil, fmt.Errorf("not running on gitlab")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ProviderConfig{
|
||||||
|
Service: "gitlab",
|
||||||
|
Name: "GitLab CI/CD",
|
||||||
|
Commit: envs["CI_COMMIT_SHA"],
|
||||||
|
Tag: envs["CI_COMMIT_TAG"],
|
||||||
|
BuildURL: envs["CI_PROJECT_URL"] + "/pipelines/" + envs["CI_PIPELINE_ID"],
|
||||||
|
Branch: envs["CI_COMMIT_REF_NAME"],
|
||||||
|
IsPR: false,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -3,37 +3,39 @@ package ci
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//Travis struct
|
//Travis struct
|
||||||
type Travis struct{}
|
type Travis struct{}
|
||||||
|
|
||||||
//Detect if on travis
|
//Detect if on travis
|
||||||
func (t Travis) Detect() (*ProviderConfig, error) {
|
func (t Travis) detect(envs map[string]string) (*ProviderConfig, error) {
|
||||||
|
|
||||||
if _, exists := os.LookupEnv("TRAVIS"); !exists {
|
if _, exists := envs["TRAVIS"]; !exists {
|
||||||
return nil, fmt.Errorf("not running on travis")
|
return nil, fmt.Errorf("not running on travis")
|
||||||
}
|
}
|
||||||
|
|
||||||
isPR := false
|
isPR := false
|
||||||
|
|
||||||
value := os.Getenv("TRAVIS_PULL_REQUEST")
|
value := envs["TRAVIS_PULL_REQUEST"]
|
||||||
|
pr := ""
|
||||||
|
|
||||||
if value == "false" {
|
if value == "false" {
|
||||||
log.Debugf("TRAVIS_PULL_REQUEST=%s, not running on pr", value)
|
log.Debugf("TRAVIS_PULL_REQUEST=%s, not running on pr", value)
|
||||||
} else {
|
} else {
|
||||||
isPR = true
|
isPR = true
|
||||||
|
pr = value
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ProviderConfig{
|
return &ProviderConfig{
|
||||||
Service: "travis",
|
Service: "travis",
|
||||||
Name: "Travis CI",
|
Name: "Travis CI",
|
||||||
Commit: os.Getenv("TRAVIS_COMMIT"),
|
Commit: envs["TRAVIS_COMMIT"],
|
||||||
Tag: os.Getenv("TRAVIS_TAG"),
|
Tag: envs["TRAVIS_TAG"],
|
||||||
BuildURL: os.Getenv("TRAVIS_BUILD_WEB_URL"),
|
BuildURL: envs["TRAVIS_BUILD_WEB_URL"],
|
||||||
Branch: os.Getenv("TRAVIS_BRANCH"),
|
Branch: envs["TRAVIS_BRANCH"],
|
||||||
IsPR: isPR,
|
IsPR: isPR,
|
||||||
PRBranch: os.Getenv("TRAVIS_PULL_REQUEST_BRANCH"),
|
PR: pr,
|
||||||
|
PRBranch: envs["TRAVIS_PULL_REQUEST_BRANCH"],
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
42
internal/ci/woodpecker.go
Normal file
42
internal/ci/woodpecker.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package ci
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Travis struct
|
||||||
|
type WoodpeckerCI struct{}
|
||||||
|
|
||||||
|
// Detect if on travis
|
||||||
|
func (t WoodpeckerCI) detect(envs map[string]string) (*ProviderConfig, error) {
|
||||||
|
|
||||||
|
if envs["CI"] != "woodpecker" {
|
||||||
|
return nil, fmt.Errorf("not running on woodpecker")
|
||||||
|
}
|
||||||
|
|
||||||
|
isPR := false
|
||||||
|
|
||||||
|
value := envs["CI_COMMIT_PULL_REQUEST"]
|
||||||
|
pr := ""
|
||||||
|
|
||||||
|
if value == "" {
|
||||||
|
log.Debugf("CI_COMMIT_PULL_REQUEST=%s, not running on pr", value)
|
||||||
|
} else {
|
||||||
|
isPR = true
|
||||||
|
pr = value
|
||||||
|
}
|
||||||
|
|
||||||
|
return &ProviderConfig{
|
||||||
|
Service: "woodpecker",
|
||||||
|
Name: "Woodpecker CI",
|
||||||
|
Commit: envs["CI_COMMIT_SHA"],
|
||||||
|
Tag: envs["CI_COMMIT_TAG"],
|
||||||
|
BuildURL: envs["CI_PIPELINE_URL"],
|
||||||
|
Branch: envs["CI_COMMIT_BRANCH"],
|
||||||
|
IsPR: isPR,
|
||||||
|
PR: pr,
|
||||||
|
PRBranch: envs["CI_COMMIT_SOURCE_BRANCH"],
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@@ -5,19 +5,15 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/Masterminds/semver"
|
"github.com/pkg/errors"
|
||||||
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"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Commit struct
|
"github.com/Masterminds/semver"
|
||||||
type Commit struct {
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
Message string
|
"github.com/go-git/go-git/v5"
|
||||||
Author string
|
"github.com/go-git/go-git/v5/plumbing"
|
||||||
Hash string
|
"github.com/go-git/go-git/v5/plumbing/object"
|
||||||
}
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
// GitUtil struct
|
// GitUtil struct
|
||||||
type GitUtil struct {
|
type GitUtil struct {
|
||||||
@@ -81,27 +77,38 @@ 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 {
|
||||||
v, err := semver.NewVersion(p.Name().Short())
|
v, err := semver.NewVersion(p.Name().Short())
|
||||||
log.Tracef("%+v", p.Name().Short())
|
log.Tracef("Tag %+v with hash: %s", p.Name().Short(), p.Hash())
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_, err := g.Repository.TagObject(p.Hash())
|
|
||||||
if err == nil {
|
|
||||||
log.Debugf("Add tag %s", p.Name().Short())
|
|
||||||
tags = append(tags, v)
|
tags = append(tags, v)
|
||||||
} else {
|
|
||||||
log.Debugf("Found tag, but is not annotated, skip")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
log.Debugf("Tag %s is not a valid version, skip", p.Name().Short())
|
log.Debugf("Tag %s is not a valid version, skip", p.Name().Short())
|
||||||
}
|
}
|
||||||
@@ -109,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
|
||||||
}
|
}
|
||||||
|
|
||||||
tagObject, err := g.Repository.TagObject(tag.Hash())
|
log.Debugf("Found old hash %s", tag.Hash().String())
|
||||||
if err != nil {
|
return tags[0], tag, nil
|
||||||
return nil, "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("Found old hash %s", tagObject.Target.String())
|
|
||||||
return tags[0], tagObject.Target.String(), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetCommits from git hash to HEAD
|
// GetCommits from git hash to HEAD
|
||||||
func (g *GitUtil) GetCommits(lastTagHash string) ([]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 []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
|
|
||||||
}
|
|
||||||
log.Tracef("Found commit with hash %s", c.Hash.String())
|
|
||||||
if !foundEnd {
|
|
||||||
commit := Commit{
|
|
||||||
Message: c.Message,
|
Message: c.Message,
|
||||||
Author: c.Committer.Name,
|
Author: c.Author.Name,
|
||||||
Hash: c.Hash.String(),
|
Hash: c.Hash.String(),
|
||||||
}
|
}
|
||||||
commits = append(commits, commit)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
return commits, err
|
return nil, errors.Wrap(err, "Could not read commits, check git clone depth in your ci")
|
||||||
|
}
|
||||||
|
|
||||||
|
l := make([]shared.Commit, 0)
|
||||||
|
|
||||||
|
for _, value := range commits {
|
||||||
|
l = append(l, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
return l, nil
|
||||||
}
|
}
|
||||||
|
|||||||
91
internal/hooks/hooks.go
Normal file
91
internal/hooks/hooks.go
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
package hooks
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
//Hooks struct
|
||||||
|
type Hooks struct {
|
||||||
|
version *shared.ReleaseVersion
|
||||||
|
config *config.ReleaseConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
// New hooks struct
|
||||||
|
func New(config *config.ReleaseConfig, version *shared.ReleaseVersion) *Hooks {
|
||||||
|
return &Hooks{
|
||||||
|
config: config,
|
||||||
|
version: version,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PreRelease runs before creating release
|
||||||
|
func (h *Hooks) PreRelease() error {
|
||||||
|
log.Infof("Run pre release hooks")
|
||||||
|
for _, cmd := range h.config.Hooks.PreRelease {
|
||||||
|
log.Debugf("Run %s", cmd)
|
||||||
|
err := h.runCommand(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostRelease runs after creating release
|
||||||
|
func (h *Hooks) PostRelease() error {
|
||||||
|
log.Infof("Run post release hooks")
|
||||||
|
for _, cmd := range h.config.Hooks.PostRelease {
|
||||||
|
err := h.runCommand(cmd)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Hooks) runCommand(command string) error {
|
||||||
|
|
||||||
|
cmdReplaced := strings.ReplaceAll(command, "$RELEASE_VERSION", h.version.Next.Version.String())
|
||||||
|
|
||||||
|
var cmd *exec.Cmd
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
cmd = exec.Command("cmd.exe", "/C", cmdReplaced)
|
||||||
|
} else {
|
||||||
|
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()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
h.printOutput(cmdReader, strings.Fields(cmdReplaced)[0])
|
||||||
|
|
||||||
|
cmdErrReader, err := cmd.StderrPipe()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
h.printOutput(cmdErrReader, strings.Fields(cmdReplaced)[0])
|
||||||
|
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
103
internal/hooks/hooks_test.go
Normal file
103
internal/hooks/hooks_test.go
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
package hooks_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Masterminds/semver"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/hooks"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPreReleaseHooks(t *testing.T) {
|
||||||
|
|
||||||
|
os.Setenv("GO_WANT_HELPER_PROCESS", "1")
|
||||||
|
hooks := hooks.New(&config.ReleaseConfig{
|
||||||
|
Hooks: config.Hooks{
|
||||||
|
PreRelease: []string{
|
||||||
|
"go test -test.run=TestHelperProcess -- " + "$RELEASE_VERSION",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&shared.ReleaseVersion{
|
||||||
|
Next: shared.ReleaseVersionEntry{
|
||||||
|
Version: createVersion("1.0.0"),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
err := hooks.PreRelease()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
os.Unsetenv("GO_WANT_HELPER_PROCESS")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPreReleaseHooksError(t *testing.T) {
|
||||||
|
|
||||||
|
hooks := hooks.New(&config.ReleaseConfig{
|
||||||
|
Hooks: config.Hooks{
|
||||||
|
PreRelease: []string{
|
||||||
|
"exit 1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&shared.ReleaseVersion{
|
||||||
|
Next: shared.ReleaseVersionEntry{
|
||||||
|
Version: createVersion("1.0.0"),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
err := hooks.PreRelease()
|
||||||
|
assert.Error(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPostReleaseHooks(t *testing.T) {
|
||||||
|
|
||||||
|
os.Setenv("GO_WANT_HELPER_PROCESS", "1")
|
||||||
|
hooks := hooks.New(&config.ReleaseConfig{
|
||||||
|
Hooks: config.Hooks{
|
||||||
|
PostRelease: []string{
|
||||||
|
"go test -test.run=TestHelperProcess -- " + "$RELEASE_VERSION",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&shared.ReleaseVersion{
|
||||||
|
Next: shared.ReleaseVersionEntry{
|
||||||
|
Version: createVersion("1.0.0"),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
err := hooks.PostRelease()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
os.Unsetenv("GO_WANT_HELPER_PROCESS")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPostReleaseHooksError(t *testing.T) {
|
||||||
|
|
||||||
|
hooks := hooks.New(&config.ReleaseConfig{
|
||||||
|
Hooks: config.Hooks{
|
||||||
|
PostRelease: []string{
|
||||||
|
"exit 1",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
&shared.ReleaseVersion{
|
||||||
|
Next: shared.ReleaseVersionEntry{
|
||||||
|
Version: createVersion("1.0.0"),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
err := hooks.PostRelease()
|
||||||
|
assert.Error(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHelperProcess(t *testing.T) {
|
||||||
|
if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" {
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
assert.Contains(t, os.Args, "1.0.0")
|
||||||
|
}
|
||||||
|
|
||||||
|
func createVersion(version string) *semver.Version {
|
||||||
|
ver, _ := semver.NewVersion(version)
|
||||||
|
return ver
|
||||||
|
}
|
||||||
26
internal/integrations/integrations.go
Normal file
26
internal/integrations/integrations.go
Normal 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
|
||||||
|
}
|
||||||
28
internal/integrations/npm.go
Normal file
28
internal/integrations/npm.go
Normal 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)
|
||||||
|
}
|
||||||
62
internal/integrations/npm_test.go
Normal file
62
internal/integrations/npm_test.go
Normal 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))
|
||||||
|
|
||||||
|
}
|
||||||
107
internal/releaser/git/git.go
Normal file
107
internal/releaser/git/git.go
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
package git
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/assets"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||||
|
"github.com/go-git/go-git/v5"
|
||||||
|
gitConfig "github.com/go-git/go-git/v5/config"
|
||||||
|
"github.com/go-git/go-git/v5/plumbing/object"
|
||||||
|
"github.com/go-git/go-git/v5/plumbing/transport/http"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GITONLY identifer for git interface
|
||||||
|
const GITONLY = "git"
|
||||||
|
|
||||||
|
// Client type struct
|
||||||
|
type Client struct {
|
||||||
|
config *config.GitProvider
|
||||||
|
log *log.Entry
|
||||||
|
git *gitutil.GitUtil
|
||||||
|
}
|
||||||
|
|
||||||
|
// New initialize a new gitRelease
|
||||||
|
func New(config *config.GitProvider, git *gitutil.GitUtil, checkConfig bool) (*Client, error) {
|
||||||
|
|
||||||
|
logger := log.WithField("releaser", GITONLY)
|
||||||
|
|
||||||
|
if config.Email == "" && checkConfig {
|
||||||
|
return nil, fmt.Errorf("git email not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Username == "" && checkConfig {
|
||||||
|
return nil, fmt.Errorf("git username not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !config.SSH && config.Auth == "" && checkConfig {
|
||||||
|
return nil, fmt.Errorf("git auth not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.SSH {
|
||||||
|
return nil, fmt.Errorf("git ssh not supported yet")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Client{
|
||||||
|
config: config,
|
||||||
|
log: logger,
|
||||||
|
git: git,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//GetCommitURL for git
|
||||||
|
func (g *Client) GetCommitURL() string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
//GetCompareURL for git
|
||||||
|
func (g *Client) GetCompareURL(oldVersion, newVersion string) string {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateRelease creates release on remote
|
||||||
|
func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog, _ *assets.Set) error {
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
head, err := g.git.Repository.Head()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = g.git.Repository.CreateTag(tag, head.Hash(), &git.CreateTagOptions{Message: "Release " + tag, Tagger: &object.Signature{
|
||||||
|
Name: g.config.Username,
|
||||||
|
Email: g.config.Email,
|
||||||
|
When: time.Now(),
|
||||||
|
}})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
g.log.Infof("Created release")
|
||||||
|
|
||||||
|
return g.git.Repository.Push(&git.PushOptions{
|
||||||
|
Auth: &http.BasicAuth{
|
||||||
|
Username: g.config.Username,
|
||||||
|
Password: g.config.Auth,
|
||||||
|
},
|
||||||
|
RefSpecs: []gitConfig.RefSpec{"refs/tags/*:refs/tags/*"},
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// UploadAssets uploads specified assets
|
||||||
|
func (g *Client) UploadAssets(repoDir string, assets []config.Asset) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
161
internal/releaser/gitea/gitea.go
Normal file
161
internal/releaser/gitea/gitea.go
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/assets"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/releaser/util"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||||
|
|
||||||
|
"code.gitea.io/sdk/gitea"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GITEA identifer for gitea interface
|
||||||
|
const GITEA = "gitea"
|
||||||
|
|
||||||
|
// Client type struct
|
||||||
|
type GiteaClient struct {
|
||||||
|
client *gitea.Client
|
||||||
|
config *config.GiteaProvider
|
||||||
|
context context.Context
|
||||||
|
release *gitea.Release
|
||||||
|
baseURL string
|
||||||
|
log *log.Entry
|
||||||
|
}
|
||||||
|
|
||||||
|
// New initialize a new GiteaRelease
|
||||||
|
func New(c *config.GiteaProvider, checkConfig bool) (*GiteaClient, error) {
|
||||||
|
|
||||||
|
token, err := util.GetAccessToken("GITEA_TOKEN")
|
||||||
|
if err != nil && checkConfig {
|
||||||
|
return &GiteaClient{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.AccessToken = token
|
||||||
|
|
||||||
|
if c.URL == "" {
|
||||||
|
url, err := util.GetAccessToken("GITEA_URL")
|
||||||
|
if err != nil && checkConfig {
|
||||||
|
return &GiteaClient{}, err
|
||||||
|
}
|
||||||
|
c.URL = url
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
//httpClient := util.CreateBearerHTTPClient(ctx, c.AccessToken)
|
||||||
|
|
||||||
|
if c.Repo == "" && checkConfig {
|
||||||
|
return nil, fmt.Errorf("gitea repo is not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.User == "" && checkConfig {
|
||||||
|
return nil, fmt.Errorf("gitea user is not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.URL == "" && checkConfig {
|
||||||
|
return nil, fmt.Errorf("gitea url is not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := gitea.NewClient(c.URL,
|
||||||
|
gitea.SetToken(c.AccessToken),
|
||||||
|
// gitea.SetHTTPClient(p.HTTPClient()),
|
||||||
|
gitea.SetContext(ctx))
|
||||||
|
if err != nil {
|
||||||
|
return &GiteaClient{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &GiteaClient{
|
||||||
|
config: c,
|
||||||
|
client: client,
|
||||||
|
context: ctx,
|
||||||
|
baseURL: c.URL,
|
||||||
|
log: log.WithField("releaser", GITEA),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCommitURL for gitea
|
||||||
|
func (g *GiteaClient) GetCommitURL() string {
|
||||||
|
return fmt.Sprintf("%s/%s/%s/commit/{{hash}}", g.baseURL, g.config.User, g.config.Repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetCompareURL for gitea
|
||||||
|
func (g *GiteaClient) GetCompareURL(oldVersion, newVersion string) string {
|
||||||
|
return fmt.Sprintf("%s/%s/%s/compare/%s...%s", g.baseURL, g.config.User, g.config.Repo, oldVersion, newVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateRelease creates release on remote
|
||||||
|
func (g *GiteaClient) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog, assets *assets.Set) error {
|
||||||
|
err := g.makeRelease(releaseVersion, generatedChangelog)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return g.uploadAssets(assets)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateRelease creates release on remote
|
||||||
|
func (g *GiteaClient) makeRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error {
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
prerelease := releaseVersion.Next.Version.Prerelease() != ""
|
||||||
|
|
||||||
|
opt := gitea.CreateReleaseOption{TagName: tag,
|
||||||
|
Target: releaseVersion.Branch,
|
||||||
|
Title: generatedChangelog.Title,
|
||||||
|
Note: generatedChangelog.Content,
|
||||||
|
IsPrerelease: prerelease}
|
||||||
|
// TODO Test if this prevents release double-up
|
||||||
|
release, _, err := g.client.CreateRelease(g.config.User, g.config.Repo, opt)
|
||||||
|
|
||||||
|
g.log.Debugf("Release response: %+v", *release)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
g.log.Debugf("Release Error response: %+v", err)
|
||||||
|
if strings.Contains(err.Error(), "Release is has no Tag") {
|
||||||
|
g.log.Infof("A release with tag %s already exits, will not perform a release or update", tag)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf("could not create release: %s", err.Error())
|
||||||
|
}
|
||||||
|
g.release = release
|
||||||
|
g.log.Infof("Created release")
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// UploadAssets uploads specified assets
|
||||||
|
func (g *GiteaClient) uploadAssets(assets *assets.Set) error {
|
||||||
|
if g.release != nil {
|
||||||
|
for _, asset := range assets.All() {
|
||||||
|
path, err := asset.GetPath()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
file, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, resp, err := g.client.CreateReleaseAttachment(g.config.User, g.config.Repo, g.release.ID, file, asset.GetName())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode >= http.StatusBadRequest {
|
||||||
|
return fmt.Errorf("could not upload asset %s: %s", asset.GetName(), resp.Status)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
199
internal/releaser/gitea/gitea_test.go
Normal file
199
internal/releaser/gitea/gitea_test.go
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"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"
|
||||||
|
)
|
||||||
|
|
||||||
|
type testHelperMethodStruct struct {
|
||||||
|
config config.GitHubProvider
|
||||||
|
valid bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type testReleaseStruct struct {
|
||||||
|
config config.GitHubProvider
|
||||||
|
releaseVersion *shared.ReleaseVersion
|
||||||
|
generatedChangelog *shared.GeneratedChangelog
|
||||||
|
requestResponseBody string
|
||||||
|
requestResponseCode int
|
||||||
|
valid bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var testNewClient = []testHelperMethodStruct{
|
||||||
|
{config: config.GitHubProvider{
|
||||||
|
Repo: "foo",
|
||||||
|
User: "bar",
|
||||||
|
},
|
||||||
|
valid: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
{config: config.GitHubProvider{
|
||||||
|
Repo: "foo",
|
||||||
|
User: "bar",
|
||||||
|
CustomURL: "https://test.com",
|
||||||
|
},
|
||||||
|
valid: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var lastVersion, _ = semver.NewVersion("1.0.0")
|
||||||
|
var newVersion, _ = semver.NewVersion("2.0.0")
|
||||||
|
|
||||||
|
var testReleases = []testReleaseStruct{
|
||||||
|
{
|
||||||
|
config: config.GitHubProvider{
|
||||||
|
Repo: "foo",
|
||||||
|
User: "bar",
|
||||||
|
},
|
||||||
|
releaseVersion: &shared.ReleaseVersion{
|
||||||
|
Last: shared.ReleaseVersionEntry{
|
||||||
|
Version: lastVersion,
|
||||||
|
Commit: "foo",
|
||||||
|
},
|
||||||
|
Next: shared.ReleaseVersionEntry{
|
||||||
|
Version: newVersion,
|
||||||
|
Commit: "bar",
|
||||||
|
},
|
||||||
|
Branch: "master",
|
||||||
|
},
|
||||||
|
generatedChangelog: &shared.GeneratedChangelog{
|
||||||
|
Title: "title",
|
||||||
|
Content: "content",
|
||||||
|
},
|
||||||
|
requestResponseBody: "{ \"url\": \"https://api.github.com/repos/octocat/Hello-World/releases/1\", \"html_url\": \"https://github.com/octocat/Hello-World/releases/v1.0.0\", \"assets_url\": \"https://api.github.com/repos/octocat/Hello-World/releases/1/assets\", \"upload_url\": \"https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}\", \"tarball_url\": \"https://api.github.com/repos/octocat/Hello-World/tarball/v1.0.0\", \"zipball_url\": \"https://api.github.com/repos/octocat/Hello-World/zipball/v1.0.0\", \"id\": 1, \"node_id\": \"MDc6UmVsZWFzZTE=\", \"tag_name\": \"v1.0.0\", \"target_commitish\": \"master\", \"name\": \"v1.0.0\", \"body\": \"Description of the release\", \"draft\": false, \"prerelease\": false, \"created_at\": \"2013-02-27T19:35:32Z\", \"published_at\": \"2013-02-27T19:35:32Z\", \"author\": { \"login\": \"octocat\", \"id\": 1, \"node_id\": \"MDQ6VXNlcjE=\", \"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\", \"gravatar_id\": \"\", \"url\": \"https://api.github.com/users/octocat\", \"html_url\": \"https://github.com/octocat\", \"followers_url\": \"https://api.github.com/users/octocat/followers\", \"following_url\": \"https://api.github.com/users/octocat/following{/other_user}\", \"gists_url\": \"https://api.github.com/users/octocat/gists{/gist_id}\", \"starred_url\": \"https://api.github.com/users/octocat/starred{/owner}{/repo}\", \"subscriptions_url\": \"https://api.github.com/users/octocat/subscriptions\", \"organizations_url\": \"https://api.github.com/users/octocat/orgs\", \"repos_url\": \"https://api.github.com/users/octocat/repos\", \"events_url\": \"https://api.github.com/users/octocat/events{/privacy}\", \"received_events_url\": \"https://api.github.com/users/octocat/received_events\", \"type\": \"User\", \"site_admin\": false }, \"assets\": [ ]}",
|
||||||
|
requestResponseCode: 200,
|
||||||
|
valid: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
config: config.GitHubProvider{
|
||||||
|
Repo: "foo",
|
||||||
|
User: "bar",
|
||||||
|
},
|
||||||
|
releaseVersion: &shared.ReleaseVersion{
|
||||||
|
Last: shared.ReleaseVersionEntry{
|
||||||
|
Version: lastVersion,
|
||||||
|
Commit: "foo",
|
||||||
|
},
|
||||||
|
Next: shared.ReleaseVersionEntry{
|
||||||
|
Version: newVersion,
|
||||||
|
Commit: "bar",
|
||||||
|
},
|
||||||
|
Branch: "master",
|
||||||
|
},
|
||||||
|
generatedChangelog: &shared.GeneratedChangelog{
|
||||||
|
Title: "title",
|
||||||
|
Content: "content",
|
||||||
|
},
|
||||||
|
requestResponseCode: 400,
|
||||||
|
valid: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func initHTTPServer(respCode int, body string) *httptest.Server {
|
||||||
|
|
||||||
|
return httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
|
log.Infof("Got call from %s %s", req.Method, req.URL.String())
|
||||||
|
|
||||||
|
rw.WriteHeader(respCode)
|
||||||
|
rw.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
if _, err := rw.Write([]byte(body)); err != nil {
|
||||||
|
log.Info(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNew(t *testing.T) {
|
||||||
|
for _, testOject := range testNewClient {
|
||||||
|
if testOject.valid {
|
||||||
|
os.Setenv("GITHUB_TOKEN", "XXX")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := New(&testOject.config, true)
|
||||||
|
assert.Equal(t, testOject.valid, err == nil)
|
||||||
|
|
||||||
|
os.Unsetenv("GITHUB_TOKEN")
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetCommitURL(t *testing.T) {
|
||||||
|
os.Setenv("GITHUB_TOKEN", "XX")
|
||||||
|
for _, testOject := range testNewClient {
|
||||||
|
client, _ := New(&testOject.config, false)
|
||||||
|
actualURL := client.GetCommitURL()
|
||||||
|
if testOject.config.CustomURL != "" {
|
||||||
|
expectedURL := fmt.Sprintf("%s/api/v3/%s/%s/commit/{{hash}}", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo)
|
||||||
|
assert.EqualValues(t, expectedURL, actualURL)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
expectedURL := fmt.Sprintf("%s/%s/%s/commit/{{hash}}", "https://github.com", testOject.config.User, testOject.config.Repo)
|
||||||
|
assert.EqualValues(t, expectedURL, actualURL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os.Unsetenv("GITHUB_TOKEN")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetCompareURL(t *testing.T) {
|
||||||
|
os.Setenv("GITHUB_TOKEN", "XX")
|
||||||
|
for _, testOject := range testNewClient {
|
||||||
|
client, _ := New(&testOject.config, false)
|
||||||
|
actualURL := client.GetCompareURL("1", "2")
|
||||||
|
if testOject.config.CustomURL != "" {
|
||||||
|
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)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
expectedURL := fmt.Sprintf("%s/%s/%s/compare/%s...%s", "https://github.com", testOject.config.User, testOject.config.Repo, "1", "2")
|
||||||
|
assert.EqualValues(t, expectedURL, actualURL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os.Unsetenv("GITHUB_TOKEN")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCreateRelease(t *testing.T) {
|
||||||
|
os.Setenv("GITHUB_TOKEN", "XX")
|
||||||
|
|
||||||
|
for _, testObejct := range testReleases {
|
||||||
|
if testObejct.valid {
|
||||||
|
server := initHTTPServer(testObejct.requestResponseCode, testObejct.requestResponseBody)
|
||||||
|
testObejct.config.CustomURL = server.URL
|
||||||
|
client, _ := New(&testObejct.config, false)
|
||||||
|
|
||||||
|
err := client.makeRelease(testObejct.releaseVersion, testObejct.generatedChangelog)
|
||||||
|
if err != nil {
|
||||||
|
t.Log(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, testObejct.valid, err == nil)
|
||||||
|
|
||||||
|
server.Close()
|
||||||
|
|
||||||
|
} else {
|
||||||
|
testObejct.config.CustomURL = "http://foo"
|
||||||
|
client, _ := New(&testObejct.config, false)
|
||||||
|
|
||||||
|
err := client.makeRelease(testObejct.releaseVersion, testObejct.generatedChangelog)
|
||||||
|
if err != nil {
|
||||||
|
t.Log(err)
|
||||||
|
}
|
||||||
|
assert.Error(t, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os.Unsetenv("GITHUB_TOKEN")
|
||||||
|
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/assets"
|
||||||
"github.com/Nightapes/go-semantic-release/internal/releaser/util"
|
"github.com/Nightapes/go-semantic-release/internal/releaser/util"
|
||||||
"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"
|
||||||
@@ -25,34 +26,49 @@ type Client struct {
|
|||||||
context context.Context
|
context context.Context
|
||||||
release *github.RepositoryRelease
|
release *github.RepositoryRelease
|
||||||
baseURL string
|
baseURL string
|
||||||
|
log *log.Entry
|
||||||
}
|
}
|
||||||
|
|
||||||
// New initialize a new GitHubRelease
|
// New initialize a new GitHubRelease
|
||||||
func New(c *config.GitHubProvider) (*Client, error) {
|
func New(c *config.GitHubProvider, checkConfig bool) (*Client, error) {
|
||||||
var err error
|
|
||||||
|
|
||||||
if c.AccessToken, err = util.GetAccessToken(GITHUB); err != nil {
|
token, err := util.GetAccessToken("GITHUB_TOKEN")
|
||||||
|
if err != nil && checkConfig {
|
||||||
return &Client{}, err
|
return &Client{}, err
|
||||||
}
|
}
|
||||||
|
c.AccessToken = token
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
httpClient := util.CreateBearerHTTPClient(ctx, c.AccessToken)
|
httpClient := util.CreateBearerHTTPClient(ctx, c.AccessToken)
|
||||||
|
|
||||||
var client *github.Client
|
var client *github.Client
|
||||||
baseURL := "https://github.com"
|
baseURL := "https://github.com"
|
||||||
|
|
||||||
|
if c.Repo == "" && checkConfig {
|
||||||
|
return nil, fmt.Errorf("github repro is not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.User == "" && checkConfig {
|
||||||
|
return nil, fmt.Errorf("github user is not set")
|
||||||
|
}
|
||||||
|
|
||||||
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,
|
||||||
client: client,
|
client: client,
|
||||||
context: ctx,
|
context: ctx,
|
||||||
baseURL: baseURL,
|
baseURL: baseURL,
|
||||||
}, err
|
log: log.WithField("releaser", GITHUB),
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetCommitURL for github
|
//GetCommitURL for github
|
||||||
@@ -65,75 +81,68 @@ func (g *Client) GetCompareURL(oldVersion, newVersion string) string {
|
|||||||
return fmt.Sprintf("%s/%s/%s/compare/%s...%s", g.baseURL, g.config.User, g.config.Repo, oldVersion, newVersion)
|
return fmt.Sprintf("%s/%s/%s/compare/%s...%s", g.baseURL, g.config.User, g.config.Repo, oldVersion, newVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
//ValidateConfig for github
|
// CreateRelease creates release on remote
|
||||||
func (g *Client) ValidateConfig() error {
|
func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog, assets *assets.Set) error {
|
||||||
log.Debugf("validate GitHub provider config")
|
err := g.makeRelease(releaseVersion, generatedChangelog)
|
||||||
|
if err != nil {
|
||||||
if g.config.Repo == "" {
|
return err
|
||||||
return fmt.Errorf("github Repro is not set")
|
|
||||||
}
|
}
|
||||||
|
return g.uploadAssets(assets)
|
||||||
if g.config.User == "" {
|
|
||||||
return fmt.Errorf("github User is not set")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateRelease creates release on remote
|
// CreateRelease creates release on remote
|
||||||
func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error {
|
func (g *Client) makeRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error {
|
||||||
|
|
||||||
tag := releaseVersion.Next.Version.String()
|
tagPrefix := config.DefaultTagPrefix
|
||||||
log.Debugf("create release with version %s", tag)
|
if g.config.TagPrefix != nil {
|
||||||
|
tagPrefix = *g.config.TagPrefix
|
||||||
|
}
|
||||||
|
tag := tagPrefix + releaseVersion.Next.Version.String()
|
||||||
|
g.log.Debugf("create release with version %s", tag)
|
||||||
|
|
||||||
prerelease := releaseVersion.Next.Version.Prerelease() != ""
|
prerelease := releaseVersion.Next.Version.Prerelease() != ""
|
||||||
|
|
||||||
release, resp, err := g.client.Repositories.CreateRelease(g.context, g.config.User, g.config.Repo, &github.RepositoryRelease{
|
release, _, err := g.client.Repositories.CreateRelease(g.context, g.config.User, g.config.Repo, &github.RepositoryRelease{
|
||||||
TagName: &tag,
|
TagName: &tag,
|
||||||
TargetCommitish: &releaseVersion.Branch,
|
TargetCommitish: &releaseVersion.Branch,
|
||||||
Name: &generatedChangelog.Title,
|
Name: &generatedChangelog.Title,
|
||||||
Body: &generatedChangelog.Content,
|
Body: &generatedChangelog.Content,
|
||||||
Draft: &releaseVersion.Draft,
|
|
||||||
Prerelease: &prerelease,
|
Prerelease: &prerelease,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !strings.Contains(err.Error(), "already_exists") && resp.StatusCode >= http.StatusUnprocessableEntity {
|
if strings.Contains(err.Error(), "already_exists") {
|
||||||
return fmt.Errorf("could not create release: %v", err)
|
g.log.Infof("A release with tag %s already exits, will not perform a release or update", tag)
|
||||||
}
|
|
||||||
log.Infof("A release with tag %s already exits, will not perform a release or update", tag)
|
|
||||||
} else {
|
|
||||||
g.release = release
|
|
||||||
log.Debugf("Release repsone: %+v", *release)
|
|
||||||
log.Infof("Crated release")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
return fmt.Errorf("could not create release: %s", err.Error())
|
||||||
|
}
|
||||||
|
g.release = release
|
||||||
|
g.log.Debugf("Release response: %+v", *release)
|
||||||
|
g.log.Infof("Created release")
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// UploadAssets uploads specified assets
|
// UploadAssets uploads specified assets
|
||||||
func (g *Client) UploadAssets(repoDir string, assets []config.Asset) error {
|
func (g *Client) uploadAssets(assets *assets.Set) error {
|
||||||
if g.release != nil {
|
if g.release != nil {
|
||||||
filesToUpload, err := util.PrepareAssets(repoDir, assets)
|
for _, asset := range assets.All() {
|
||||||
|
path, err := asset.GetPath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, f := range filesToUpload {
|
file, err := os.Open(path)
|
||||||
|
|
||||||
file, err := os.Open(*f)
|
|
||||||
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("releaser: github: Could not upload asset %s: %s", file.Name(), resp.Status)
|
return fmt.Errorf("could not upload asset %s: %s", asset.GetName(), resp.Status)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
199
internal/releaser/github/github_test.go
Normal file
199
internal/releaser/github/github_test.go
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
package github
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"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"
|
||||||
|
)
|
||||||
|
|
||||||
|
type testHelperMethodStruct struct {
|
||||||
|
config config.GitHubProvider
|
||||||
|
valid bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type testReleaseStruct struct {
|
||||||
|
config config.GitHubProvider
|
||||||
|
releaseVersion *shared.ReleaseVersion
|
||||||
|
generatedChangelog *shared.GeneratedChangelog
|
||||||
|
requestResponseBody string
|
||||||
|
requestResponseCode int
|
||||||
|
valid bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var testNewClient = []testHelperMethodStruct{
|
||||||
|
{config: config.GitHubProvider{
|
||||||
|
Repo: "foo",
|
||||||
|
User: "bar",
|
||||||
|
},
|
||||||
|
valid: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
{config: config.GitHubProvider{
|
||||||
|
Repo: "foo",
|
||||||
|
User: "bar",
|
||||||
|
CustomURL: "https://test.com",
|
||||||
|
},
|
||||||
|
valid: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var lastVersion, _ = semver.NewVersion("1.0.0")
|
||||||
|
var newVersion, _ = semver.NewVersion("2.0.0")
|
||||||
|
|
||||||
|
var testReleases = []testReleaseStruct{
|
||||||
|
{
|
||||||
|
config: config.GitHubProvider{
|
||||||
|
Repo: "foo",
|
||||||
|
User: "bar",
|
||||||
|
},
|
||||||
|
releaseVersion: &shared.ReleaseVersion{
|
||||||
|
Last: shared.ReleaseVersionEntry{
|
||||||
|
Version: lastVersion,
|
||||||
|
Commit: "foo",
|
||||||
|
},
|
||||||
|
Next: shared.ReleaseVersionEntry{
|
||||||
|
Version: newVersion,
|
||||||
|
Commit: "bar",
|
||||||
|
},
|
||||||
|
Branch: "master",
|
||||||
|
},
|
||||||
|
generatedChangelog: &shared.GeneratedChangelog{
|
||||||
|
Title: "title",
|
||||||
|
Content: "content",
|
||||||
|
},
|
||||||
|
requestResponseBody: "{ \"url\": \"https://api.github.com/repos/octocat/Hello-World/releases/1\", \"html_url\": \"https://github.com/octocat/Hello-World/releases/v1.0.0\", \"assets_url\": \"https://api.github.com/repos/octocat/Hello-World/releases/1/assets\", \"upload_url\": \"https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}\", \"tarball_url\": \"https://api.github.com/repos/octocat/Hello-World/tarball/v1.0.0\", \"zipball_url\": \"https://api.github.com/repos/octocat/Hello-World/zipball/v1.0.0\", \"id\": 1, \"node_id\": \"MDc6UmVsZWFzZTE=\", \"tag_name\": \"v1.0.0\", \"target_commitish\": \"master\", \"name\": \"v1.0.0\", \"body\": \"Description of the release\", \"draft\": false, \"prerelease\": false, \"created_at\": \"2013-02-27T19:35:32Z\", \"published_at\": \"2013-02-27T19:35:32Z\", \"author\": { \"login\": \"octocat\", \"id\": 1, \"node_id\": \"MDQ6VXNlcjE=\", \"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\", \"gravatar_id\": \"\", \"url\": \"https://api.github.com/users/octocat\", \"html_url\": \"https://github.com/octocat\", \"followers_url\": \"https://api.github.com/users/octocat/followers\", \"following_url\": \"https://api.github.com/users/octocat/following{/other_user}\", \"gists_url\": \"https://api.github.com/users/octocat/gists{/gist_id}\", \"starred_url\": \"https://api.github.com/users/octocat/starred{/owner}{/repo}\", \"subscriptions_url\": \"https://api.github.com/users/octocat/subscriptions\", \"organizations_url\": \"https://api.github.com/users/octocat/orgs\", \"repos_url\": \"https://api.github.com/users/octocat/repos\", \"events_url\": \"https://api.github.com/users/octocat/events{/privacy}\", \"received_events_url\": \"https://api.github.com/users/octocat/received_events\", \"type\": \"User\", \"site_admin\": false }, \"assets\": [ ]}",
|
||||||
|
requestResponseCode: 200,
|
||||||
|
valid: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
config: config.GitHubProvider{
|
||||||
|
Repo: "foo",
|
||||||
|
User: "bar",
|
||||||
|
},
|
||||||
|
releaseVersion: &shared.ReleaseVersion{
|
||||||
|
Last: shared.ReleaseVersionEntry{
|
||||||
|
Version: lastVersion,
|
||||||
|
Commit: "foo",
|
||||||
|
},
|
||||||
|
Next: shared.ReleaseVersionEntry{
|
||||||
|
Version: newVersion,
|
||||||
|
Commit: "bar",
|
||||||
|
},
|
||||||
|
Branch: "master",
|
||||||
|
},
|
||||||
|
generatedChangelog: &shared.GeneratedChangelog{
|
||||||
|
Title: "title",
|
||||||
|
Content: "content",
|
||||||
|
},
|
||||||
|
requestResponseCode: 400,
|
||||||
|
valid: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func initHTTPServer(respCode int, body string) *httptest.Server {
|
||||||
|
|
||||||
|
return httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
|
log.Infof("Got call from %s %s", req.Method, req.URL.String())
|
||||||
|
|
||||||
|
rw.WriteHeader(respCode)
|
||||||
|
rw.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
if _, err := rw.Write([]byte(body)); err != nil {
|
||||||
|
log.Info(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNew(t *testing.T) {
|
||||||
|
for _, testOject := range testNewClient {
|
||||||
|
if testOject.valid {
|
||||||
|
os.Setenv("GITHUB_TOKEN", "XXX")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := New(&testOject.config, true)
|
||||||
|
assert.Equal(t, testOject.valid, err == nil)
|
||||||
|
|
||||||
|
os.Unsetenv("GITHUB_TOKEN")
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetCommitURL(t *testing.T) {
|
||||||
|
os.Setenv("GITHUB_TOKEN", "XX")
|
||||||
|
for _, testOject := range testNewClient {
|
||||||
|
client, _ := New(&testOject.config, false)
|
||||||
|
actualURL := client.GetCommitURL()
|
||||||
|
if testOject.config.CustomURL != "" {
|
||||||
|
expectedURL := fmt.Sprintf("%s/api/v3/%s/%s/commit/{{hash}}", testOject.config.CustomURL, testOject.config.User, testOject.config.Repo)
|
||||||
|
assert.EqualValues(t, expectedURL, actualURL)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
expectedURL := fmt.Sprintf("%s/%s/%s/commit/{{hash}}", "https://github.com", testOject.config.User, testOject.config.Repo)
|
||||||
|
assert.EqualValues(t, expectedURL, actualURL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os.Unsetenv("GITHUB_TOKEN")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetCompareURL(t *testing.T) {
|
||||||
|
os.Setenv("GITHUB_TOKEN", "XX")
|
||||||
|
for _, testOject := range testNewClient {
|
||||||
|
client, _ := New(&testOject.config, false)
|
||||||
|
actualURL := client.GetCompareURL("1", "2")
|
||||||
|
if testOject.config.CustomURL != "" {
|
||||||
|
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)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
expectedURL := fmt.Sprintf("%s/%s/%s/compare/%s...%s", "https://github.com", testOject.config.User, testOject.config.Repo, "1", "2")
|
||||||
|
assert.EqualValues(t, expectedURL, actualURL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os.Unsetenv("GITHUB_TOKEN")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCreateRelease(t *testing.T) {
|
||||||
|
os.Setenv("GITHUB_TOKEN", "XX")
|
||||||
|
|
||||||
|
for _, testObejct := range testReleases {
|
||||||
|
if testObejct.valid {
|
||||||
|
server := initHTTPServer(testObejct.requestResponseCode, testObejct.requestResponseBody)
|
||||||
|
testObejct.config.CustomURL = server.URL
|
||||||
|
client, _ := New(&testObejct.config, false)
|
||||||
|
|
||||||
|
err := client.makeRelease(testObejct.releaseVersion, testObejct.generatedChangelog)
|
||||||
|
if err != nil {
|
||||||
|
t.Log(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, testObejct.valid, err == nil)
|
||||||
|
|
||||||
|
server.Close()
|
||||||
|
|
||||||
|
} else {
|
||||||
|
testObejct.config.CustomURL = "http://foo"
|
||||||
|
client, _ := New(&testObejct.config, false)
|
||||||
|
|
||||||
|
err := client.makeRelease(testObejct.releaseVersion, testObejct.generatedChangelog)
|
||||||
|
if err != nil {
|
||||||
|
t.Log(err)
|
||||||
|
}
|
||||||
|
assert.Error(t, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
os.Unsetenv("GITHUB_TOKEN")
|
||||||
|
|
||||||
|
}
|
||||||
225
internal/releaser/gitlab/gitlab.go
Normal file
225
internal/releaser/gitlab/gitlab.go
Normal file
@@ -0,0 +1,225 @@
|
|||||||
|
package gitlab
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"mime/multipart"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/assets"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/releaser/util"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GITLAB identifer for gitlab interface
|
||||||
|
const GITLAB = "gitlab"
|
||||||
|
|
||||||
|
// Client type struct
|
||||||
|
type Client struct {
|
||||||
|
config *config.GitLabProvider
|
||||||
|
client *http.Client
|
||||||
|
baseURL string
|
||||||
|
apiURL string
|
||||||
|
token string
|
||||||
|
Release string
|
||||||
|
log *log.Entry
|
||||||
|
}
|
||||||
|
|
||||||
|
// New initialize a new gitlabRelease
|
||||||
|
func New(config *config.GitLabProvider, checkConfig bool) (*Client, error) {
|
||||||
|
accessToken, err := util.GetAccessToken(fmt.Sprintf("%s_ACCESS_TOKEN", strings.ToUpper(GITLAB)))
|
||||||
|
if err != nil && checkConfig {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenHeader := util.NewAddHeaderTransport(nil, "PRIVATE-TOKEN", accessToken)
|
||||||
|
acceptHeader := util.NewAddHeaderTransport(tokenHeader, "Accept", "application/json")
|
||||||
|
contentHeader := util.NewAddHeaderTransport(acceptHeader, "Content-Type", "application/json")
|
||||||
|
httpClient := &http.Client{
|
||||||
|
Transport: contentHeader,
|
||||||
|
Timeout: time.Second * 60,
|
||||||
|
}
|
||||||
|
|
||||||
|
logger := log.WithField("releaser", GITLAB)
|
||||||
|
|
||||||
|
logger.Debugf("validate gitlab provider config")
|
||||||
|
|
||||||
|
if config.Repo == "" && checkConfig {
|
||||||
|
return nil, fmt.Errorf("gitlab Repro is not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
config.Repo = strings.Trim(config.Repo, "/")
|
||||||
|
|
||||||
|
if config.CustomURL == "" {
|
||||||
|
config.CustomURL = "https://gitlab.com"
|
||||||
|
}
|
||||||
|
|
||||||
|
config.CustomURL = strings.Trim(config.CustomURL, "/")
|
||||||
|
logger.Debugf("Use gitlab url %s", config.CustomURL)
|
||||||
|
|
||||||
|
return &Client{
|
||||||
|
token: accessToken,
|
||||||
|
config: config,
|
||||||
|
baseURL: config.CustomURL,
|
||||||
|
apiURL: config.CustomURL + "/api/v4",
|
||||||
|
client: httpClient,
|
||||||
|
log: logger,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//GetCommitURL for gitlab
|
||||||
|
func (g *Client) GetCommitURL() string {
|
||||||
|
return fmt.Sprintf("%s/%s/commit/{{hash}}", g.baseURL, g.config.Repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
//GetCompareURL for gitlab
|
||||||
|
func (g *Client) GetCompareURL(oldVersion, newVersion string) string {
|
||||||
|
return fmt.Sprintf("%s/%s/compare/%s...%s", g.baseURL, g.config.Repo, oldVersion, newVersion)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateRelease creates release on remote
|
||||||
|
func (g *Client) CreateRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog, assets *assets.Set) error {
|
||||||
|
err := g.makeRelease(releaseVersion, generatedChangelog)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return g.uploadAssets(assets)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateRelease creates release on remote
|
||||||
|
func (g *Client) makeRelease(releaseVersion *shared.ReleaseVersion, generatedChangelog *shared.GeneratedChangelog) error {
|
||||||
|
|
||||||
|
tagPrefix := config.DefaultTagPrefix
|
||||||
|
if g.config.TagPrefix != nil{
|
||||||
|
tagPrefix = *g.config.TagPrefix
|
||||||
|
}
|
||||||
|
tag := tagPrefix + releaseVersion.Next.Version.String()
|
||||||
|
g.Release = tag
|
||||||
|
g.log.Infof("create release with version %s", tag)
|
||||||
|
url := fmt.Sprintf("%s/projects/%s/releases", g.apiURL, util.PathEscape(g.config.Repo))
|
||||||
|
g.log.Infof("Send release to %s", url)
|
||||||
|
|
||||||
|
bodyBytes, err := json.Marshal(Release{
|
||||||
|
TagName: tag,
|
||||||
|
Name: generatedChangelog.Title,
|
||||||
|
Description: generatedChangelog.Content,
|
||||||
|
Ref: releaseVersion.Branch,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
g.log.Tracef("Send release config %s", bodyBytes)
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", url, bytes.NewReader(bodyBytes))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not create request: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := util.Do(g.client, req, nil)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not create release: %s", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := util.IsValidResult(resp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
g.log.Infof("Created release")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Client) uploadAssets(assets *assets.Set) error {
|
||||||
|
for _, asset := range assets.All() {
|
||||||
|
path, err := asset.GetPath()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
file, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
result, err := g.uploadFile(asset.GetName(), file)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("could not upload asset %s: %s", file.Name(), err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
downloadURL := fmt.Sprintf("%s/%s%s", g.baseURL, g.config.Repo, result.URL)
|
||||||
|
|
||||||
|
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(asset.GetName()), downloadURL)
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", uploadURL, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
g.log.Infof("Link file %s with release %s", file.Name(), g.Release)
|
||||||
|
|
||||||
|
resp, err := util.Do(g.client, req, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = util.IsValidResult(resp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
g.log.Infof("Link file with release %s is done", g.Release)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *Client) uploadFile(fileName string, file *os.File) (*ProjectFile, error) {
|
||||||
|
|
||||||
|
b := &bytes.Buffer{}
|
||||||
|
w := multipart.NewWriter(b)
|
||||||
|
|
||||||
|
fw, err := w.CreateFormFile("file", fileName)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = io.Copy(fw, file)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
w.Close()
|
||||||
|
|
||||||
|
url := fmt.Sprintf("%s/projects/%s/uploads", g.apiURL, util.PathEscape(g.config.Repo))
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Body = ioutil.NopCloser(b)
|
||||||
|
req.ContentLength = int64(b.Len())
|
||||||
|
req.Header.Set("Content-Type", w.FormDataContentType())
|
||||||
|
|
||||||
|
uf := &ProjectFile{}
|
||||||
|
resp, err := util.Do(g.client, req, uf)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = util.IsValidResult(resp); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return uf, nil
|
||||||
|
}
|
||||||
338
internal/releaser/gitlab/gitlab_test.go
Normal file
338
internal/releaser/gitlab/gitlab_test.go
Normal file
@@ -0,0 +1,338 @@
|
|||||||
|
package gitlab
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/Masterminds/semver"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/assets"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/shared"
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetCommitURL(t *testing.T) {
|
||||||
|
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
|
||||||
|
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||||
|
client, err := New(&config.GitLabProvider{
|
||||||
|
CustomURL: "https://127.0.0.1/",
|
||||||
|
Repo: "test/test",
|
||||||
|
}, true)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "https://127.0.0.1/test/test/commit/{{hash}}", client.GetCommitURL())
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetCompareURL(t *testing.T) {
|
||||||
|
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
|
||||||
|
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||||
|
client, err := New(&config.GitLabProvider{
|
||||||
|
CustomURL: "https://127.0.0.1/",
|
||||||
|
Repo: "test/test",
|
||||||
|
}, true)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
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) {
|
||||||
|
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
|
||||||
|
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||||
|
_, err := New(&config.GitLabProvider{
|
||||||
|
CustomURL: "https://127.0.0.1/",
|
||||||
|
}, true)
|
||||||
|
assert.Error(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidateConfig_DefaultURL(t *testing.T) {
|
||||||
|
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
|
||||||
|
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||||
|
config := &config.GitLabProvider{
|
||||||
|
Repo: "127.0.0.1/test",
|
||||||
|
}
|
||||||
|
_, err := New(config, true)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "https://gitlab.com", config.CustomURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestValidateConfig_CustomURL(t *testing.T) {
|
||||||
|
os.Setenv("GITLAB_ACCESS_TOKEN", "XXX")
|
||||||
|
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||||
|
config := &config.GitLabProvider{
|
||||||
|
Repo: "/127.0.0.1/test/",
|
||||||
|
CustomURL: "https://127.0.0.1/",
|
||||||
|
}
|
||||||
|
_, err := New(config, true)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, "https://127.0.0.1", config.CustomURL)
|
||||||
|
assert.Equal(t, "127.0.0.1/test", config.Repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCreateRelease(t *testing.T) {
|
||||||
|
|
||||||
|
lastVersion, _ := semver.NewVersion("1.0.0")
|
||||||
|
newVersion, _ := semver.NewVersion("2.0.0")
|
||||||
|
|
||||||
|
testReleases := []struct {
|
||||||
|
config config.GitLabProvider
|
||||||
|
releaseVersion *shared.ReleaseVersion
|
||||||
|
generatedChangelog *shared.GeneratedChangelog
|
||||||
|
responseBody string
|
||||||
|
responseCode int
|
||||||
|
requestBody string
|
||||||
|
valid bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
config: config.GitLabProvider{
|
||||||
|
Repo: "foo/bar",
|
||||||
|
},
|
||||||
|
releaseVersion: &shared.ReleaseVersion{
|
||||||
|
Last: shared.ReleaseVersionEntry{
|
||||||
|
Version: lastVersion,
|
||||||
|
Commit: "foo",
|
||||||
|
},
|
||||||
|
Next: shared.ReleaseVersionEntry{
|
||||||
|
Version: newVersion,
|
||||||
|
Commit: "bar",
|
||||||
|
},
|
||||||
|
Branch: "master",
|
||||||
|
},
|
||||||
|
generatedChangelog: &shared.GeneratedChangelog{
|
||||||
|
Title: "title",
|
||||||
|
Content: "content",
|
||||||
|
},
|
||||||
|
responseBody: "{}",
|
||||||
|
responseCode: 200,
|
||||||
|
requestBody: `{"tag_name":"v2.0.0","name":"title","ref":"master","description":"content"}`,
|
||||||
|
valid: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
config: config.GitLabProvider{
|
||||||
|
Repo: "foo/bar",
|
||||||
|
},
|
||||||
|
releaseVersion: &shared.ReleaseVersion{
|
||||||
|
Last: shared.ReleaseVersionEntry{
|
||||||
|
Version: lastVersion,
|
||||||
|
Commit: "foo",
|
||||||
|
},
|
||||||
|
Next: shared.ReleaseVersionEntry{
|
||||||
|
Version: newVersion,
|
||||||
|
Commit: "bar",
|
||||||
|
},
|
||||||
|
Branch: "master",
|
||||||
|
},
|
||||||
|
generatedChangelog: &shared.GeneratedChangelog{
|
||||||
|
Title: "title",
|
||||||
|
Content: "content",
|
||||||
|
},
|
||||||
|
responseBody: "{}",
|
||||||
|
responseCode: 500,
|
||||||
|
requestBody: `{"tag_name":"v2.0.0","name":"title","ref":"master","description":"content"}`,
|
||||||
|
valid: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
config: config.GitLabProvider{
|
||||||
|
Repo: "foo/bar",
|
||||||
|
CustomURL: "broken",
|
||||||
|
},
|
||||||
|
releaseVersion: &shared.ReleaseVersion{
|
||||||
|
Last: shared.ReleaseVersionEntry{
|
||||||
|
Version: lastVersion,
|
||||||
|
Commit: "foo",
|
||||||
|
},
|
||||||
|
Next: shared.ReleaseVersionEntry{
|
||||||
|
Version: newVersion,
|
||||||
|
Commit: "bar",
|
||||||
|
},
|
||||||
|
Branch: "master",
|
||||||
|
},
|
||||||
|
generatedChangelog: &shared.GeneratedChangelog{
|
||||||
|
Title: "title",
|
||||||
|
Content: "content",
|
||||||
|
},
|
||||||
|
responseCode: 400,
|
||||||
|
responseBody: "{}",
|
||||||
|
requestBody: `{"tag_name":"v2.0.0","name":"title","ref":"master","description":"content"}`,
|
||||||
|
valid: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testObject := range testReleases {
|
||||||
|
testServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
|
log.Infof("Got call from %s %s", req.Method, req.URL.String())
|
||||||
|
|
||||||
|
assert.Equal(t, req.Header.Get("PRIVATE-TOKEN"), "aToken")
|
||||||
|
assert.Equal(t, req.Header.Get("Accept"), "application/json")
|
||||||
|
|
||||||
|
bodyBytes, err := ioutil.ReadAll(req.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, testObject.requestBody, string(bodyBytes))
|
||||||
|
|
||||||
|
rw.WriteHeader(testObject.responseCode)
|
||||||
|
rw.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
if _, err := rw.Write([]byte(testObject.responseBody)); err != nil {
|
||||||
|
log.Info(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}))
|
||||||
|
|
||||||
|
if testObject.config.CustomURL == "" {
|
||||||
|
testObject.config.CustomURL = testServer.URL
|
||||||
|
}
|
||||||
|
os.Setenv("GITLAB_ACCESS_TOKEN", "aToken")
|
||||||
|
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||||
|
client, err := New(&testObject.config, false)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
err = client.makeRelease(testObject.releaseVersion, testObject.generatedChangelog)
|
||||||
|
if err != nil {
|
||||||
|
t.Log(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, testObject.valid, err == nil)
|
||||||
|
|
||||||
|
testServer.Close()
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUploadAssets(t *testing.T) {
|
||||||
|
|
||||||
|
file, err := ioutil.TempFile("", "prefix")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer os.Remove(file.Name())
|
||||||
|
|
||||||
|
_, err = file.WriteString("testFile")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
testReleases := []struct {
|
||||||
|
config config.GitLabProvider
|
||||||
|
responseBody []string
|
||||||
|
responseCode []int
|
||||||
|
assets []config.Asset
|
||||||
|
requestBody []string
|
||||||
|
testDir string
|
||||||
|
url []string
|
||||||
|
method []string
|
||||||
|
valid bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
config: config.GitLabProvider{
|
||||||
|
Repo: "foo/bar",
|
||||||
|
},
|
||||||
|
responseBody: []string{`{"alt" : "dk", "url": "/uploads/66dbcd21ec5d24ed6ea225176098d52b/dk.png", "markdown" :""}`, ""},
|
||||||
|
responseCode: []int{200, 200},
|
||||||
|
requestBody: []string{
|
||||||
|
filepath.Base(file.Name()), ""},
|
||||||
|
url: []string{`/api/v4/projects/foo%2Fbar/uploads`, "/api/v4/projects/foo%2Fbar/releases/1.0.0/assets/links?name=" + filepath.Base(file.Name()) + "&url=<SERVER>/foo/bar/uploads/"},
|
||||||
|
method: []string{"POST", "POST"},
|
||||||
|
valid: true,
|
||||||
|
testDir: os.TempDir(),
|
||||||
|
assets: []config.Asset{
|
||||||
|
{
|
||||||
|
Name: filepath.Base(file.Name()),
|
||||||
|
Compress: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
config: config.GitLabProvider{
|
||||||
|
Repo: "foo/bar",
|
||||||
|
},
|
||||||
|
responseBody: []string{`{"alt" : "dk", "url": "/uploads/66dbcd21ec5d24ed6ea225176098d52b/dk.png", "markdown" :""}`, ""},
|
||||||
|
responseCode: []int{400, 200},
|
||||||
|
requestBody: []string{
|
||||||
|
filepath.Base(file.Name()), ""},
|
||||||
|
url: []string{`/api/v4/projects/foo%2Fbar/uploads`, "/api/v4/projects/foo%2Fbar/releases/1.0.0/assets/links?name=" + filepath.Base(file.Name()) + "&url=<SERVER>/foo/bar/uploads/"},
|
||||||
|
method: []string{"POST", "POST"},
|
||||||
|
valid: false,
|
||||||
|
testDir: os.TempDir(),
|
||||||
|
assets: []config.Asset{
|
||||||
|
{
|
||||||
|
Name: filepath.Base(file.Name()),
|
||||||
|
Compress: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
config: config.GitLabProvider{
|
||||||
|
Repo: "foo/bar",
|
||||||
|
},
|
||||||
|
responseBody: []string{`broken`, ""},
|
||||||
|
responseCode: []int{200, 200},
|
||||||
|
requestBody: []string{
|
||||||
|
filepath.Base(file.Name()), ""},
|
||||||
|
url: []string{`/api/v4/projects/foo%2Fbar/uploads`, "/api/v4/projects/foo%2Fbar/releases/1.0.0/assets/links?name=" + filepath.Base(file.Name()) + "&url=<SERVER>/foo/bar/uploads/"},
|
||||||
|
method: []string{"POST", "POST"},
|
||||||
|
valid: false,
|
||||||
|
testDir: os.TempDir(),
|
||||||
|
assets: []config.Asset{
|
||||||
|
{
|
||||||
|
Name: filepath.Base(file.Name()),
|
||||||
|
Compress: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testObject := range testReleases {
|
||||||
|
calls := 0
|
||||||
|
testServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
|
log.Infof("Got call from %s %s", req.Method, req.URL.String())
|
||||||
|
|
||||||
|
assert.Contains(t, req.URL.String(), strings.ReplaceAll(testObject.url[calls], "<SERVER>", testObject.config.CustomURL))
|
||||||
|
assert.Equal(t, req.Method, testObject.method[calls])
|
||||||
|
|
||||||
|
assert.Equal(t, req.Header.Get("PRIVATE-TOKEN"), "aToken")
|
||||||
|
assert.Equal(t, req.Header.Get("Accept"), "application/json")
|
||||||
|
|
||||||
|
bodyBytes, err := ioutil.ReadAll(req.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
assert.Contains(t, string(bodyBytes), testObject.requestBody[calls])
|
||||||
|
|
||||||
|
rw.WriteHeader(testObject.responseCode[calls])
|
||||||
|
rw.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
if _, err := rw.Write([]byte(testObject.responseBody[calls])); err != nil {
|
||||||
|
log.Info(err)
|
||||||
|
}
|
||||||
|
calls++
|
||||||
|
}))
|
||||||
|
|
||||||
|
if testObject.config.CustomURL == "" {
|
||||||
|
testObject.config.CustomURL = testServer.URL
|
||||||
|
}
|
||||||
|
os.Setenv("GITLAB_ACCESS_TOKEN", "aToken")
|
||||||
|
defer os.Unsetenv("GITLAB_ACCESS_TOKEN")
|
||||||
|
client, err := New(&testObject.config, false)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
client.Release = "1.0.0"
|
||||||
|
|
||||||
|
assets := assets.New(testObject.testDir, "")
|
||||||
|
err = assets.Add(testObject.assets...)
|
||||||
|
if err != nil {
|
||||||
|
t.Log(err)
|
||||||
|
}
|
||||||
|
err = client.uploadAssets(assets)
|
||||||
|
if err != nil {
|
||||||
|
t.Log(err)
|
||||||
|
}
|
||||||
|
assert.Equal(t, testObject.valid, err == nil)
|
||||||
|
|
||||||
|
testServer.Close()
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
22
internal/releaser/gitlab/types.go
Normal file
22
internal/releaser/gitlab/types.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package gitlab
|
||||||
|
|
||||||
|
// Release struct
|
||||||
|
type Release struct {
|
||||||
|
TagName string `json:"tag_name"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Ref string `json:"ref"`
|
||||||
|
Description string `json:"description,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReleaseLink struct
|
||||||
|
type ReleaseLink struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProjectFile struct
|
||||||
|
type ProjectFile struct {
|
||||||
|
Alt string `json:"alt"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Markdown string `json:"markdown"`
|
||||||
|
}
|
||||||
@@ -3,7 +3,12 @@ package releaser
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/assets"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/gitutil"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/releaser/git"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/releaser/gitea"
|
||||||
"github.com/Nightapes/go-semantic-release/internal/releaser/github"
|
"github.com/Nightapes/go-semantic-release/internal/releaser/github"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/releaser/gitlab"
|
||||||
"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"
|
||||||
@@ -13,30 +18,39 @@ import (
|
|||||||
// Releasers struct type
|
// Releasers struct type
|
||||||
type Releasers struct {
|
type Releasers struct {
|
||||||
config *config.ReleaseConfig
|
config *config.ReleaseConfig
|
||||||
|
git *gitutil.GitUtil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Releaser interface for providers
|
// Releaser interface for providers
|
||||||
type Releaser interface {
|
type Releaser interface {
|
||||||
ValidateConfig() error
|
CreateRelease(*shared.ReleaseVersion, *shared.GeneratedChangelog, *assets.Set) error
|
||||||
CreateRelease(*shared.ReleaseVersion, *shared.GeneratedChangelog) error
|
|
||||||
UploadAssets(repoDir string, assets []config.Asset) error
|
|
||||||
GetCommitURL() string
|
GetCommitURL() string
|
||||||
GetCompareURL(oldVersion, newVersion string) string
|
GetCompareURL(oldVersion, newVersion string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New initialize a Relerser
|
// New initialize a releaser
|
||||||
func New(c *config.ReleaseConfig) *Releasers {
|
func New(c *config.ReleaseConfig, git *gitutil.GitUtil) *Releasers {
|
||||||
return &Releasers{
|
return &Releasers{
|
||||||
config: c,
|
config: c,
|
||||||
|
git: git,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetReleaser returns an initialized releaser
|
// GetReleaser returns an initialized releaser
|
||||||
func (r *Releasers) GetReleaser() (Releaser, error) {
|
func (r *Releasers) GetReleaser(checkConfig bool) (Releaser, error) {
|
||||||
switch r.config.Release {
|
switch r.config.Release {
|
||||||
case github.GITHUB:
|
case github.GITHUB:
|
||||||
log.Debugf("initialize new %s-provider", github.GITHUB)
|
log.Debugf("initialize new %s-provider", github.GITHUB)
|
||||||
return github.New(&r.config.GitHubProvider)
|
return github.New(&r.config.GitHubProvider, checkConfig)
|
||||||
|
case gitlab.GITLAB:
|
||||||
|
log.Debugf("initialize new %s-provider", gitlab.GITLAB)
|
||||||
|
return gitlab.New(&r.config.GitLabProvider, checkConfig)
|
||||||
|
case gitea.GITEA:
|
||||||
|
log.Debugf("initialize new %s-provider", gitea.GITEA)
|
||||||
|
return gitea.New(&r.config.GiteaProvider, checkConfig)
|
||||||
|
case git.GITONLY:
|
||||||
|
log.Debugf("initialize new %s-provider", git.GITONLY)
|
||||||
|
return git.New(&r.config.GitProvider, r.git, checkConfig)
|
||||||
}
|
}
|
||||||
return nil, fmt.Errorf("could not initialize a releaser from this type: %s", r.config.Release)
|
return nil, fmt.Errorf("could not initialize a releaser from this type: %s", r.config.Release)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"archive/zip"
|
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Nightapes/go-semantic-release/pkg/config"
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
@@ -25,83 +25,152 @@ func CreateBearerHTTPClient(ctx context.Context, token string) *http.Client {
|
|||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddHeaderTransport struct
|
||||||
|
type AddHeaderTransport struct {
|
||||||
|
T http.RoundTripper
|
||||||
|
key string
|
||||||
|
value string
|
||||||
|
}
|
||||||
|
|
||||||
|
// RoundTrip add header
|
||||||
|
func (adt *AddHeaderTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
|
req.Header.Add(adt.key, adt.value)
|
||||||
|
return adt.T.RoundTrip(req)
|
||||||
|
}
|
||||||
|
|
||||||
|
//NewAddHeaderTransport to add default header
|
||||||
|
func NewAddHeaderTransport(T http.RoundTripper, key, value string) *AddHeaderTransport {
|
||||||
|
if T == nil {
|
||||||
|
T = http.DefaultTransport
|
||||||
|
}
|
||||||
|
return &AddHeaderTransport{T, key, value}
|
||||||
|
}
|
||||||
|
|
||||||
// GetAccessToken lookup for the providers accesstoken
|
// GetAccessToken lookup for the providers accesstoken
|
||||||
func GetAccessToken(providerName string) (string, error) {
|
func GetAccessToken(envName string) (string, error) {
|
||||||
var token string
|
var token string
|
||||||
var exists bool
|
var exists bool
|
||||||
envName := fmt.Sprintf("%s_ACCESS_TOKEN", strings.ToUpper(providerName))
|
|
||||||
|
|
||||||
log.Debugf("check if %s environment variable is set", envName)
|
log.Debugf("check if %s environment variable is set", envName)
|
||||||
|
|
||||||
if token, exists = os.LookupEnv(envName); !exists {
|
if token, exists = os.LookupEnv(envName); !exists {
|
||||||
return "", fmt.Errorf("could not find %s in the enviroment variables. Please check if it is set", envName)
|
return "", fmt.Errorf("could not find %s in the enviroment variables. Please check if it is set", envName)
|
||||||
|
} else if token == "" {
|
||||||
|
return "", fmt.Errorf("token %s is set in environment variables but is empty", envName)
|
||||||
}
|
}
|
||||||
return token, nil
|
return token, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrepareAssets prepare all files before uploading
|
// // PrepareAssets prepare all files before uploading
|
||||||
func PrepareAssets(repository string, assets []config.Asset) ([]*string, error) {
|
// func PrepareAssets(repository string, assets []config.Asset) ([]*string, error) {
|
||||||
filesToUpload := []*string{}
|
// filesToUpload := []*string{}
|
||||||
for _, asset := range assets {
|
// for _, asset := range assets {
|
||||||
if asset.Compress {
|
// if asset.Name != "" && asset.Path == "" {
|
||||||
log.Debugf("Asset %s will now be compressed", asset.Name)
|
// log.Warn("Name is deprecated. Please update your config. See https://nightapes.github.io/go-semantic-release/")
|
||||||
log.Debugf("Repo url %s", repository)
|
// }
|
||||||
zipNameWithPath, err := zipFile(repository, asset.Name)
|
|
||||||
if err != nil {
|
// if asset.Path == "" {
|
||||||
return filesToUpload, err
|
// return nil, fmt.Errorf("asset path declaration is empty, please check your configuration file")
|
||||||
|
// } else if asset.Compress {
|
||||||
|
// log.Debugf("Asset %s will now be compressed", asset.Name)
|
||||||
|
// log.Debugf("Repo url %s", repository)
|
||||||
|
// zipNameWithPath, err := zipFile(repository, asset.Name)
|
||||||
|
// if err != nil {
|
||||||
|
// return filesToUpload, err
|
||||||
|
// }
|
||||||
|
// filesToUpload = append(filesToUpload, &zipNameWithPath)
|
||||||
|
// } else {
|
||||||
|
// tmpFileName := fmt.Sprintf("%s/%s", repository, asset.Name)
|
||||||
|
// filesToUpload = append(filesToUpload, &tmpFileName)
|
||||||
|
// }
|
||||||
|
// log.Debugf("Add asset %s to files to upload", asset.Name)
|
||||||
|
// }
|
||||||
|
// return filesToUpload, nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // ZipFile compress given file in zip format
|
||||||
|
// func zipFile(repository string, file string) (string, error) {
|
||||||
|
|
||||||
|
// fileToZip, err := os.Open(repository + "/" + file)
|
||||||
|
// if err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
// defer fileToZip.Close()
|
||||||
|
|
||||||
|
// zipFileName := fmt.Sprintf("%s/%s.zip", strings.TrimSuffix(repository, "/"), file)
|
||||||
|
// zipFile, err := os.Create(zipFileName)
|
||||||
|
|
||||||
|
// if err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
// log.Debugf("Created zipfile %s", zipFile.Name())
|
||||||
|
|
||||||
|
// defer zipFile.Close()
|
||||||
|
|
||||||
|
// fileToZipInfo, err := fileToZip.Stat()
|
||||||
|
// if err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// zipWriter := zip.NewWriter(zipFile)
|
||||||
|
// defer zipWriter.Close()
|
||||||
|
|
||||||
|
// fileToZipHeader, err := zip.FileInfoHeader(fileToZipInfo)
|
||||||
|
// if err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fileToZipHeader.Name = fileToZipInfo.Name()
|
||||||
|
|
||||||
|
// fileToZipWriter, err := zipWriter.CreateHeader(fileToZipHeader)
|
||||||
|
// if err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// if _, err = io.Copy(fileToZipWriter, fileToZip); err != nil {
|
||||||
|
// return "", err
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return zipFileName, nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
//PathEscape to be url save
|
||||||
|
func PathEscape(s string) string {
|
||||||
|
return strings.Replace(url.PathEscape(s), ".", "%2E", -1)
|
||||||
}
|
}
|
||||||
filesToUpload = append(filesToUpload, &zipNameWithPath)
|
|
||||||
|
// Do request for client
|
||||||
|
func Do(client *http.Client, req *http.Request, v interface{}) (*http.Response, error) {
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
switch resp.StatusCode {
|
||||||
|
case 200, 201, 202, 204:
|
||||||
|
if v != nil {
|
||||||
|
if w, ok := v.(io.Writer); ok {
|
||||||
|
_, err = io.Copy(w, resp.Body)
|
||||||
} else {
|
} else {
|
||||||
tmpFileName := fmt.Sprintf("%s/%s", repository, asset.Name)
|
err = json.NewDecoder(resp.Body).Decode(v)
|
||||||
filesToUpload = append(filesToUpload, &tmpFileName)
|
|
||||||
}
|
}
|
||||||
log.Debugf("Add asset %s to files to upload", asset.Name)
|
|
||||||
}
|
}
|
||||||
return filesToUpload, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ZipFile compress given file in zip format
|
return resp, err
|
||||||
func zipFile(repository string, file string) (string, error) {
|
|
||||||
|
|
||||||
zipFileName := fmt.Sprintf("%s/%s.zip", strings.TrimSuffix(repository, "/"), file)
|
|
||||||
zipFile, err := os.Create(zipFileName)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
log.Debugf("Created zipfile %s", zipFile.Name())
|
|
||||||
|
|
||||||
defer zipFile.Close()
|
|
||||||
|
|
||||||
fileToZip, err := os.Open(repository + "/" + file)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
defer fileToZip.Close()
|
|
||||||
|
|
||||||
fileToZipInfo, err := fileToZip.Stat()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zipWriter := zip.NewWriter(zipFile)
|
// IsValidResult validates response code
|
||||||
defer zipWriter.Close()
|
func IsValidResult(resp *http.Response) error {
|
||||||
|
switch resp.StatusCode {
|
||||||
fileToZipHeader, err := zip.FileInfoHeader(fileToZipInfo)
|
case 200, 201, 202, 204:
|
||||||
if err != nil {
|
return nil
|
||||||
return "", err
|
default:
|
||||||
|
return fmt.Errorf("%s %s: %d", resp.Request.Method, resp.Request.URL, resp.StatusCode)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fileToZipHeader.Name = fileToZipInfo.Name()
|
// ShouldRetry request
|
||||||
|
func ShouldRetry(resp *http.Response) bool {
|
||||||
fileToZipWriter, err := zipWriter.CreateHeader(fileToZipHeader)
|
return resp.StatusCode == http.StatusTooManyRequests
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err = io.Copy(fileToZipWriter, fileToZip); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return zipFileName, nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
155
internal/releaser/util/util_test.go
Normal file
155
internal/releaser/util/util_test.go
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
package util_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/releaser/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateBearerHTTPClient(t *testing.T) {
|
||||||
|
client := util.CreateBearerHTTPClient(context.Background(), "")
|
||||||
|
|
||||||
|
assert.True(t, client != nil, "Client is empty")
|
||||||
|
}
|
||||||
|
|
||||||
|
type testDoubleToken struct {
|
||||||
|
providerName, token string
|
||||||
|
valid bool
|
||||||
|
}
|
||||||
|
|
||||||
|
var testDoubles = []testDoubleToken{
|
||||||
|
{providerName: "test0", token: "foo", valid: true},
|
||||||
|
{providerName: "test1", token: "", valid: false},
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetAccessToken(t *testing.T) {
|
||||||
|
for _, testObject := range testDoubles {
|
||||||
|
envName := fmt.Sprintf("%s_ACCESS_TOKEN", strings.ToUpper(testObject.providerName))
|
||||||
|
if err := os.Setenv(envName, testObject.token); err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := util.GetAccessToken(envName)
|
||||||
|
|
||||||
|
assert.Equal(t, testObject.valid, err == nil)
|
||||||
|
os.Unsetenv(envName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestShouldRetry(t *testing.T) {
|
||||||
|
assert.True(t, util.ShouldRetry(&http.Response{StatusCode: 429}))
|
||||||
|
assert.False(t, util.ShouldRetry(&http.Response{StatusCode: 200}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIsValidResult(t *testing.T) {
|
||||||
|
assert.NoError(t, util.IsValidResult(&http.Response{StatusCode: 200}))
|
||||||
|
assert.NoError(t, util.IsValidResult(&http.Response{StatusCode: 201}))
|
||||||
|
assert.NoError(t, util.IsValidResult(&http.Response{StatusCode: 202}))
|
||||||
|
assert.NoError(t, util.IsValidResult(&http.Response{StatusCode: 204}))
|
||||||
|
|
||||||
|
u, err := url.Parse("https://127.0.0.1")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Error(t, util.IsValidResult(&http.Response{StatusCode: 500, Request: &http.Request{
|
||||||
|
Method: "POST",
|
||||||
|
URL: u,
|
||||||
|
}}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPathEscape(t *testing.T) {
|
||||||
|
assert.Equal(t, "test%2Ftest", util.PathEscape("test/test"))
|
||||||
|
assert.Equal(t, "test", util.PathEscape("test"))
|
||||||
|
assert.Equal(t, "test%2Etest", util.PathEscape("test.test"))
|
||||||
|
}
|
||||||
|
|
||||||
|
type example struct {
|
||||||
|
Test string `json:"test"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDoAndRoundTrip(t *testing.T) {
|
||||||
|
tokenHeader := util.NewAddHeaderTransport(nil, "PRIVATE-TOKEN", "aToken")
|
||||||
|
acceptHeader := util.NewAddHeaderTransport(tokenHeader, "Accept", "application/json")
|
||||||
|
httpClient := &http.Client{
|
||||||
|
Transport: acceptHeader,
|
||||||
|
Timeout: time.Second * 60,
|
||||||
|
}
|
||||||
|
|
||||||
|
testsDoMethod := []struct {
|
||||||
|
statusCode int
|
||||||
|
body string
|
||||||
|
responseBody interface{}
|
||||||
|
responseBodyType interface{}
|
||||||
|
hasError bool
|
||||||
|
path string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
statusCode: 200,
|
||||||
|
body: `{"test" : "hallo"}`,
|
||||||
|
responseBody: &example{
|
||||||
|
Test: "hallo",
|
||||||
|
},
|
||||||
|
responseBodyType: &example{},
|
||||||
|
hasError: false,
|
||||||
|
path: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
statusCode: 400,
|
||||||
|
body: `{"test" : "hallo"}`,
|
||||||
|
responseBody: &example{},
|
||||||
|
responseBodyType: &example{},
|
||||||
|
hasError: false,
|
||||||
|
path: "",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
statusCode: 200,
|
||||||
|
body: `{"test" : "hallo"}`,
|
||||||
|
hasError: true,
|
||||||
|
responseBody: &example{},
|
||||||
|
responseBodyType: &example{},
|
||||||
|
path: "4/broken",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, testOject := range testsDoMethod {
|
||||||
|
testServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
|
log.Infof("Got call from %s %s", req.Method, req.URL.String())
|
||||||
|
|
||||||
|
assert.Equal(t, req.Header.Get("PRIVATE-TOKEN"), "aToken")
|
||||||
|
assert.Equal(t, req.Header.Get("Accept"), "application/json")
|
||||||
|
|
||||||
|
rw.WriteHeader(testOject.statusCode)
|
||||||
|
rw.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
if _, err := rw.Write([]byte(testOject.body)); err != nil {
|
||||||
|
log.Info(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
}))
|
||||||
|
|
||||||
|
defer testServer.Close()
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", testServer.URL+testOject.path, nil)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
resp, err := util.Do(httpClient, req, testOject.responseBodyType)
|
||||||
|
|
||||||
|
assert.Equal(t, testOject.hasError, err != nil)
|
||||||
|
|
||||||
|
if !testOject.hasError {
|
||||||
|
assert.Equal(t, testOject.statusCode, resp.StatusCode)
|
||||||
|
assert.Equal(t, testOject.responseBody, testOject.responseBodyType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,16 +6,17 @@ import (
|
|||||||
|
|
||||||
//ReleaseVersion struct
|
//ReleaseVersion struct
|
||||||
type ReleaseVersion struct {
|
type ReleaseVersion struct {
|
||||||
Last ReleaseVersionEntry
|
Last ReleaseVersionEntry `yaml:"last"`
|
||||||
Next ReleaseVersionEntry
|
Next ReleaseVersionEntry `yaml:"next"`
|
||||||
Branch string
|
Branch string `yaml:"branch"`
|
||||||
Draft bool
|
Commits map[Release][]AnalyzedCommit `yaml:"commits"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//ReleaseVersionEntry struct
|
//ReleaseVersionEntry struct
|
||||||
type ReleaseVersionEntry struct {
|
type ReleaseVersionEntry struct {
|
||||||
Commit string
|
Commit string `yaml:"commit"`
|
||||||
Version *semver.Version
|
VersionString string `yaml:"version"`
|
||||||
|
Version *semver.Version `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//GeneratedChangelog struct
|
//GeneratedChangelog struct
|
||||||
@@ -31,3 +32,36 @@ type ChangelogTemplateConfig struct {
|
|||||||
Hash string
|
Hash string
|
||||||
Version string
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//AnalyzedCommit struct
|
||||||
|
type AnalyzedCommit struct {
|
||||||
|
Commit Commit `yaml:"commit"`
|
||||||
|
ParsedMessage string `yaml:"parsedMessage"`
|
||||||
|
ParsedBreakingChangeMessage string `yaml:"parsedBreakingChangeMessage"`
|
||||||
|
Tag string `yaml:"tag"`
|
||||||
|
TagString string `yaml:"tagString"`
|
||||||
|
Scope Scope `yaml:"scope"`
|
||||||
|
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,..
|
||||||
|
type Scope string
|
||||||
|
|
||||||
|
//Release types, like major
|
||||||
|
type Release string
|
||||||
|
|
||||||
|
// Commit struct
|
||||||
|
type Commit struct {
|
||||||
|
Message string `yaml:"message"`
|
||||||
|
Author string `yaml:"author"`
|
||||||
|
Hash string `yaml:"hash"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,21 +3,49 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"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"`
|
||||||
Template string `yaml:"template,omitempty"`
|
TemplateTitle string `yaml:"title,omitempty"`
|
||||||
TemplatePath string `yaml:"templatePath,omitempty"`
|
TemplatePath string `yaml:"templatePath,omitempty"`
|
||||||
|
ShowBodyAsHeader bool `yaml:"showBodyAsHeader,omitempty"`
|
||||||
|
ShowAuthors bool `yaml:"showAuthors,omitempty"`
|
||||||
|
Docker ChangelogDocker `yaml:"docker,omitempty"`
|
||||||
|
NPM ChangelogNPM `yaml:"npm,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChangelogDocker type struct
|
||||||
|
type ChangelogDocker struct {
|
||||||
|
Latest bool `yaml:"latest"`
|
||||||
|
Repository string `yaml:"repository"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChangelogNPM type struct
|
||||||
|
type ChangelogNPM struct {
|
||||||
|
Repository string `yaml:"repository"`
|
||||||
|
PackageName string `yaml:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asset type struct
|
// Asset type struct
|
||||||
type Asset struct {
|
type Asset struct {
|
||||||
Name string `yaml:"name"`
|
Path string `yaml:"path"`
|
||||||
|
Rename string `yaml:"rename,omitempty"`
|
||||||
|
Name string `yaml:"name,omitempty"` // Deprecated
|
||||||
Compress bool `yaml:"compress"`
|
Compress bool `yaml:"compress"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,18 +55,74 @@ 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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GiteaProvider struct
|
||||||
|
type GiteaProvider struct {
|
||||||
|
Repo string `yaml:"repo"`
|
||||||
|
User string `yaml:"user"`
|
||||||
|
URL string `yaml:"url,omitempty"`
|
||||||
|
AccessToken string
|
||||||
|
TagPrefix *string `yaml:"tagPrefix,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GitLabProvider struct
|
||||||
|
type GitLabProvider struct {
|
||||||
|
Repo string `yaml:"repo"`
|
||||||
|
CustomURL string `yaml:"customUrl,omitempty"`
|
||||||
|
AccessToken string
|
||||||
|
TagPrefix *string `yaml:"tagPrefix,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GitProvider struct
|
||||||
|
type GitProvider struct {
|
||||||
|
Email string `yaml:"email"`
|
||||||
|
Username string `yaml:"user"`
|
||||||
|
Auth string `yaml:"auth"`
|
||||||
|
SSH bool `yaml:"ssh"`
|
||||||
|
TagPrefix *string `yaml:"tagPrefix,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hooks struct
|
||||||
|
type Hooks struct {
|
||||||
|
PreRelease []string `yaml:"preRelease"`
|
||||||
|
PostRelease []string `yaml:"postRelease"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Checksum struct
|
||||||
|
type Checksum struct {
|
||||||
|
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"`
|
||||||
|
GiteaProvider GiteaProvider `yaml:"gitea,omitempty"`
|
||||||
GitHubProvider GitHubProvider `yaml:"github,omitempty"`
|
GitHubProvider GitHubProvider `yaml:"github,omitempty"`
|
||||||
|
GitLabProvider GitLabProvider `yaml:"gitlab,omitempty"`
|
||||||
|
GitProvider GitProvider `yaml:"git,omitempty"`
|
||||||
Assets []Asset `yaml:"assets"`
|
Assets []Asset `yaml:"assets"`
|
||||||
|
Checksum Checksum `yaml:"checksum,omitempty"`
|
||||||
|
Hooks Hooks `yaml:"hooks"`
|
||||||
|
Integrations Integrations `yaml:"integrations"`
|
||||||
ReleaseTitle string `yaml:"title"`
|
ReleaseTitle string `yaml:"title"`
|
||||||
IsPreRelease, IsDraft bool
|
IsPreRelease bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read ReleaseConfig
|
// Read ReleaseConfig
|
||||||
@@ -49,13 +133,31 @@ func Read(configPath string) (*ReleaseConfig, error) {
|
|||||||
return &ReleaseConfig{}, err
|
return &ReleaseConfig{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var releaseConfig ReleaseConfig
|
log.Tracef("Found config %s", string(content))
|
||||||
err = yaml.Unmarshal(content, &releaseConfig)
|
releaseConfig := &ReleaseConfig{}
|
||||||
|
err = yaml.Unmarshal(content, releaseConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &ReleaseConfig{}, err
|
return &ReleaseConfig{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Found config %+v", releaseConfig)
|
org := *releaseConfig
|
||||||
|
|
||||||
return &releaseConfig, nil
|
releaseConfig.Hooks = Hooks{}
|
||||||
|
|
||||||
|
configWithoutHooks, err := yaml.Marshal(releaseConfig)
|
||||||
|
if err != nil {
|
||||||
|
return &ReleaseConfig{}, err
|
||||||
|
}
|
||||||
|
configWithoutHooks = []byte(os.ExpandEnv(string(configWithoutHooks)))
|
||||||
|
releaseConfigWithExpanedEnvs := &ReleaseConfig{}
|
||||||
|
err = yaml.Unmarshal(configWithoutHooks, releaseConfigWithExpanedEnvs)
|
||||||
|
if err != nil {
|
||||||
|
return &ReleaseConfig{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
releaseConfigWithExpanedEnvs.Hooks = org.Hooks
|
||||||
|
|
||||||
|
log.Tracef("Found config %+v", releaseConfigWithExpanedEnvs)
|
||||||
|
|
||||||
|
return releaseConfigWithExpanedEnvs, nil
|
||||||
}
|
}
|
||||||
|
|||||||
106
pkg/config/config_test.go
Normal file
106
pkg/config/config_test.go
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
package config_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"github.com/Nightapes/go-semantic-release/pkg/config"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestReadCacheNotFound(t *testing.T) {
|
||||||
|
|
||||||
|
_, err := config.Read("notfound/dir")
|
||||||
|
assert.Errorf(t, err, "Read non exsiting file")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadCacheInvalidContent(t *testing.T) {
|
||||||
|
|
||||||
|
dir, err := ioutil.TempDir("", "prefix")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
|
completePath := path.Join(path.Dir(dir), ".release.yml")
|
||||||
|
brokenContent := []byte("hello broken\ngo: lang\n")
|
||||||
|
err = ioutil.WriteFile(completePath, brokenContent, 0644)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
_, readError := config.Read(completePath)
|
||||||
|
assert.Errorf(t, readError, "Should give error, when broken content")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWriteAndReadCache(t *testing.T) {
|
||||||
|
|
||||||
|
dir, err := ioutil.TempDir("", "prefix")
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
|
os.Setenv("TEST_CONFIG", "value")
|
||||||
|
defer os.Unsetenv("TEST_CONFIG")
|
||||||
|
|
||||||
|
completePath := path.Join(path.Dir(dir), ".release.yml")
|
||||||
|
content := []byte(`
|
||||||
|
commitFormat: angular
|
||||||
|
title: "go-semantic-release release"
|
||||||
|
branch:
|
||||||
|
master: release
|
||||||
|
rc: rc
|
||||||
|
beta: beta
|
||||||
|
alpha: alpha
|
||||||
|
add_git_releases: alpha
|
||||||
|
changelog:
|
||||||
|
printAll: false
|
||||||
|
template: ""
|
||||||
|
templatePath: '${TEST_CONFIG}'
|
||||||
|
release: 'github'
|
||||||
|
hooks:
|
||||||
|
preRelease:
|
||||||
|
- "Test hook ${RELEASE_VERSION}"
|
||||||
|
assets:
|
||||||
|
- name: ./build/go-semantic-release
|
||||||
|
compress: false
|
||||||
|
github:
|
||||||
|
repo: "go-semantic-release"
|
||||||
|
user: "nightapes"
|
||||||
|
customUrl: ""
|
||||||
|
`)
|
||||||
|
err = ioutil.WriteFile(completePath, content, 0644)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
result, readError := config.Read(completePath)
|
||||||
|
assert.NoErrorf(t, readError, "Should read file")
|
||||||
|
|
||||||
|
assert.EqualValues(t, &config.ReleaseConfig{
|
||||||
|
CommitFormat: "angular",
|
||||||
|
Branch: map[string]string{"add_git_releases": "alpha", "alpha": "alpha", "beta": "beta", "master": "release", "rc": "rc"},
|
||||||
|
Changelog: config.ChangelogConfig{
|
||||||
|
PrintAll: false,
|
||||||
|
TemplateTitle: "",
|
||||||
|
TemplatePath: "value"},
|
||||||
|
Release: "github",
|
||||||
|
GitHubProvider: config.GitHubProvider{
|
||||||
|
Repo: "go-semantic-release",
|
||||||
|
User: "nightapes",
|
||||||
|
CustomURL: "",
|
||||||
|
AccessToken: ""},
|
||||||
|
Hooks: config.Hooks{
|
||||||
|
PreRelease: []string{
|
||||||
|
"Test hook ${RELEASE_VERSION}",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Assets: []config.Asset{
|
||||||
|
{
|
||||||
|
Name: "./build/go-semantic-release",
|
||||||
|
Compress: false}},
|
||||||
|
ReleaseTitle: "go-semantic-release release",
|
||||||
|
IsPreRelease: false,
|
||||||
|
Analyzer: config.AnalyzerConfig{TokenSeparators: []string{}},
|
||||||
|
}, result)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
package semanticrelease
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Masterminds/semver"
|
|
||||||
"github.com/Nightapes/go-semantic-release/internal/cache"
|
|
||||||
"github.com/Nightapes/go-semantic-release/internal/shared"
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (s *SemanticRelease) incPrerelease(preReleaseType string, version semver.Version) semver.Version {
|
|
||||||
defaultPrerelease := preReleaseType + ".0"
|
|
||||||
if version.Prerelease() == "" || !strings.HasPrefix(version.Prerelease(), preReleaseType) {
|
|
||||||
version, _ = version.SetPrerelease(defaultPrerelease)
|
|
||||||
} else {
|
|
||||||
parts := strings.Split(version.Prerelease(), ".")
|
|
||||||
if len(parts) == 2 {
|
|
||||||
i, err := strconv.Atoi(parts[1])
|
|
||||||
if err != nil {
|
|
||||||
version, _ = version.SetPrerelease(defaultPrerelease)
|
|
||||||
log.Warnf("Could not parse release tag %s, use version %s", version.Prerelease(), version.String())
|
|
||||||
} else {
|
|
||||||
version, _ = version.SetPrerelease(preReleaseType + "." + strconv.Itoa((i + 1)))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
version, _ = version.SetPrerelease(defaultPrerelease)
|
|
||||||
log.Warnf("Could not parse release tag %s, use version %s", version.Prerelease(), version.String())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return version
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SemanticRelease) saveToCache(releaseVersion shared.ReleaseVersion) error {
|
|
||||||
|
|
||||||
toCache := cache.ReleaseVersion{
|
|
||||||
Next: cache.ReleaseVersionEntry{
|
|
||||||
Commit: releaseVersion.Next.Commit,
|
|
||||||
Version: releaseVersion.Next.Version.String(),
|
|
||||||
},
|
|
||||||
Last: cache.ReleaseVersionEntry{
|
|
||||||
Commit: releaseVersion.Last.Commit,
|
|
||||||
Version: releaseVersion.Last.Version.String(),
|
|
||||||
},
|
|
||||||
Branch: releaseVersion.Branch,
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Debugf("Save %s with hash %s to cache", releaseVersion.Next.Version.String(), releaseVersion.Next.Commit)
|
|
||||||
return cache.Write(s.repository, toCache)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SemanticRelease) readFromCache(currentHash string) (*shared.ReleaseVersion, error) {
|
|
||||||
content, err := cache.Read(s.repository)
|
|
||||||
|
|
||||||
if err == nil && content.Next.Commit == currentHash {
|
|
||||||
|
|
||||||
nextVersion, err := semver.NewVersion(content.Next.Version)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
lastVersion, err := semver.NewVersion(content.Last.Version)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
releaseVersion := &shared.ReleaseVersion{
|
|
||||||
Next: shared.ReleaseVersionEntry{
|
|
||||||
Commit: content.Next.Commit,
|
|
||||||
Version: nextVersion,
|
|
||||||
},
|
|
||||||
Last: shared.ReleaseVersionEntry{
|
|
||||||
Commit: content.Last.Commit,
|
|
||||||
Version: lastVersion,
|
|
||||||
},
|
|
||||||
Branch: content.Branch,
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Infof("Found cache, will return cached version %s", content.Next.Version)
|
|
||||||
return releaseVersion, nil
|
|
||||||
|
|
||||||
}
|
|
||||||
log.Debugf("Mismatch git and version file %s - %s", content.Next.Commit, currentHash)
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
@@ -2,134 +2,143 @@ package semanticrelease
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"github.com/go-git/go-git/v5/plumbing"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"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/cache"
|
||||||
|
"github.com/Nightapes/go-semantic-release/internal/calculator"
|
||||||
"github.com/Nightapes/go-semantic-release/internal/changelog"
|
"github.com/Nightapes/go-semantic-release/internal/changelog"
|
||||||
"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/Nightapes/go-semantic-release/internal/hooks"
|
||||||
"github.com/Nightapes/go-semantic-release/internal/releaser"
|
"github.com/Nightapes/go-semantic-release/internal/releaser"
|
||||||
"github.com/Nightapes/go-semantic-release/internal/releaser/util"
|
|
||||||
"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
|
||||||
releaser releaser.Releaser
|
releaser releaser.Releaser
|
||||||
|
assets *assets.Set
|
||||||
repository string
|
repository string
|
||||||
|
checkConfig bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// New SemanticRelease struct
|
// New SemanticRelease struct
|
||||||
func New(c *config.ReleaseConfig, repository string) (*SemanticRelease, error) {
|
func New(c *config.ReleaseConfig, repository string, checkConfig bool) (*SemanticRelease, error) {
|
||||||
util, err := gitutil.New(repository)
|
util, err := gitutil.New(repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
releaser, err := releaser.New(c).GetReleaser()
|
if !checkConfig {
|
||||||
|
log.Infof("Ignore config checks!. No guarantee to run without issues")
|
||||||
|
}
|
||||||
|
|
||||||
|
assets := assets.New(repository, c.Checksum.Algorithm)
|
||||||
|
|
||||||
|
releaser, err := releaser.New(c, util).GetReleaser(checkConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &SemanticRelease{
|
return &SemanticRelease{
|
||||||
config: c,
|
config: c,
|
||||||
gitutil: util,
|
gitUtil: util,
|
||||||
releaser: releaser,
|
releaser: releaser,
|
||||||
analyzer: analyzer,
|
analyzer: analyzer,
|
||||||
repository: repository,
|
repository: repository,
|
||||||
|
assets: assets,
|
||||||
|
checkConfig: checkConfig,
|
||||||
|
calculator: calculator.New(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCIProvider result with ci config
|
||||||
|
func (s *SemanticRelease) GetCIProvider() (*ci.ProviderConfig, error) {
|
||||||
|
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(force bool) (*shared.ReleaseVersion, error) {
|
func (s *SemanticRelease) GetNextVersion(provider *ci.ProviderConfig, force bool, from string) (*shared.ReleaseVersion, error) {
|
||||||
provider, err := ci.GetCIProvider(s.gitutil)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
fakeVersion, _ := semver.NewVersion("0.0.0-fake.0")
|
|
||||||
log.Warnf("Will not calculate version, set fake version. Could not find CI Provider, if running locally, set env CI=true")
|
|
||||||
return &shared.ReleaseVersion{
|
|
||||||
Next: shared.ReleaseVersionEntry{
|
|
||||||
Commit: "",
|
|
||||||
Version: fakeVersion,
|
|
||||||
},
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
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 := s.readFromCache(provider.Commit)
|
releaseVersion, err := cache.Read(s.repository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if releaseVersion != nil {
|
if releaseVersion.Next.Commit == provider.Commit && releaseVersion != nil {
|
||||||
return releaseVersion, nil
|
return releaseVersion, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lastVersion, lastVersionHash, err := s.gitutil.GetLastVersion()
|
var lastVersion *semver.Version
|
||||||
|
var lastVersionHash *plumbing.Reference
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if from == "" {
|
||||||
|
lastVersion, lastVersionHash, err = s.gitUtil.GetLastVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
lastVersion, lastVersionHash, err = s.gitUtil.GetVersion(from)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var newVersion semver.Version
|
|
||||||
firstRelease := false
|
firstRelease := false
|
||||||
|
|
||||||
if lastVersion == nil {
|
if lastVersion == nil {
|
||||||
defaultVersion, _ := semver.NewVersion("1.0.0")
|
lastVersion, _ = semver.NewVersion("1.0.0")
|
||||||
newVersion = *defaultVersion
|
log.Infof("This is the first release, will set version to %s", lastVersion.String())
|
||||||
lastVersion = defaultVersion
|
|
||||||
firstRelease = true
|
firstRelease = true
|
||||||
} else {
|
|
||||||
newVersion = *lastVersion
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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))
|
||||||
|
|
||||||
a, err := analyzer.New(s.config.CommitFormat, s.config.Changelog)
|
analyzedCommits := s.analyzer.Analyze(commits)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
var newVersion semver.Version
|
||||||
}
|
foundBranchConfig := false
|
||||||
result := a.Analyze(commits)
|
|
||||||
isDraft := false
|
|
||||||
for branch, releaseType := range s.config.Branch {
|
for branch, releaseType := range s.config.Branch {
|
||||||
if provider.Branch == branch || strings.HasPrefix(provider.Branch, branch) {
|
if provider.Branch == branch {
|
||||||
log.Debugf("Found branch config for branch %s with release type %s", provider.Branch, releaseType)
|
log.Debugf("Found branch config for branch %s with release type %s", provider.Branch, releaseType)
|
||||||
switch releaseType {
|
newVersion = s.calculator.CalculateNewVersion(analyzedCommits, lastVersion, releaseType, firstRelease)
|
||||||
case "beta", "alpha":
|
foundBranchConfig = true
|
||||||
isDraft = true
|
break
|
||||||
newVersion = s.incPrerelease(releaseType, newVersion)
|
|
||||||
case "rc":
|
|
||||||
newVersion = s.incPrerelease(releaseType, newVersion)
|
|
||||||
case "release":
|
|
||||||
if !firstRelease {
|
|
||||||
if len(result["major"]) > 0 {
|
|
||||||
newVersion = newVersion.IncMajor()
|
|
||||||
} else if len(result["minor"]) > 0 {
|
|
||||||
newVersion = newVersion.IncMinor()
|
|
||||||
} else if len(result["patch"]) > 0 {
|
|
||||||
newVersion = newVersion.IncPatch()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !foundBranchConfig {
|
||||||
|
log.Warnf("No branch config found for branch %s, will return last known version", provider.Branch)
|
||||||
|
newVersion = *lastVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
releaseVersion := shared.ReleaseVersion{
|
releaseVersion := shared.ReleaseVersion{
|
||||||
@@ -138,15 +147,22 @@ func (s *SemanticRelease) GetNextVersion(force bool) (*shared.ReleaseVersion, er
|
|||||||
Version: &newVersion,
|
Version: &newVersion,
|
||||||
},
|
},
|
||||||
Last: shared.ReleaseVersionEntry{
|
Last: shared.ReleaseVersionEntry{
|
||||||
Commit: lastVersionHash,
|
Commit: "",
|
||||||
Version: lastVersion,
|
Version: lastVersion,
|
||||||
},
|
},
|
||||||
Branch: provider.Branch,
|
Branch: provider.Branch,
|
||||||
Draft: isDraft,
|
Commits: analyzedCommits,
|
||||||
|
}
|
||||||
|
if lastVersionHash != nil {
|
||||||
|
releaseVersion.Last.Commit = lastVersionHash.Hash().String()
|
||||||
|
}
|
||||||
|
|
||||||
|
if firstRelease {
|
||||||
|
releaseVersion.Last.Version, _ = semver.NewVersion("0.0.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("New version %s -> %s", lastVersion.String(), newVersion.String())
|
log.Infof("New version %s -> %s", lastVersion.String(), newVersion.String())
|
||||||
err = s.saveToCache(releaseVersion)
|
err = cache.Write(s.repository, releaseVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -154,20 +170,13 @@ func (s *SemanticRelease) GetNextVersion(force bool) (*shared.ReleaseVersion, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetVersion for git repository
|
// SetVersion for git repository
|
||||||
func (s *SemanticRelease) SetVersion(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
|
||||||
}
|
}
|
||||||
|
|
||||||
provider, err := ci.GetCIProvider(s.gitutil)
|
lastVersion, lastVersionHash, err := s.gitUtil.GetLastVersion()
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("will not set version. Could not find CI Provider, if running locally, set env CI=true")
|
|
||||||
}
|
|
||||||
|
|
||||||
lastVersion, lastVersionHash, err := s.gitutil.GetLastVersion()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -175,13 +184,13 @@ func (s *SemanticRelease) SetVersion(version string) error {
|
|||||||
lastVersion, _ = semver.NewVersion("1.0.0")
|
lastVersion, _ = semver.NewVersion("1.0.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
return s.saveToCache(shared.ReleaseVersion{
|
return cache.Write(s.repository, shared.ReleaseVersion{
|
||||||
Next: shared.ReleaseVersionEntry{
|
Next: shared.ReleaseVersionEntry{
|
||||||
Commit: provider.Commit,
|
Commit: provider.Commit,
|
||||||
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,
|
||||||
@@ -190,77 +199,158 @@ func (s *SemanticRelease) SetVersion(version string) error {
|
|||||||
|
|
||||||
// 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) {
|
||||||
commits, err := s.gitutil.GetCommits(releaseVersion.Last.Commit)
|
c := changelog.New(s.config, s.analyzer.GetRules(), time.Now())
|
||||||
if err != nil {
|
return c.GenerateChangelog(shared.ChangelogTemplateConfig{
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
result := s.analyzer.Analyze(commits)
|
|
||||||
|
|
||||||
log.Debugf("Found %d commits till last release", len(commits))
|
|
||||||
|
|
||||||
c := changelog.New(s.config, s.analyzer.GetRules())
|
|
||||||
return c.GenerateChanglog(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()),
|
||||||
}, result)
|
}, 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Release pusblish release to provider
|
if bytesToMB(info.Size()) >= float64(maxChangelogFileSize) {
|
||||||
func (s *SemanticRelease) Release(force bool) error {
|
err := moveExistingChangelogFile(file)
|
||||||
|
|
||||||
provider, err := ci.GetCIProvider(s.gitutil)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Will not perform a new release. Could not find CI Provider")
|
return err
|
||||||
return nil
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
|
func (s *SemanticRelease) Release(provider *ci.ProviderConfig, force bool) error {
|
||||||
if provider.IsPR {
|
if provider.IsPR {
|
||||||
log.Debugf("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
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, ok := s.config.Branch[provider.Branch]; !ok {
|
if _, ok := s.config.Branch[provider.Branch]; !ok {
|
||||||
log.Debugf("Will not perform a new release. Current %s branch is not configured in release config", provider.Branch)
|
log.Infof("Will not perform a new release. Current %s branch is not configured in release config", provider.Branch)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
releaseVersion, err := s.GetNextVersion(force)
|
if err := s.assets.Add(s.config.Assets...); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
generatedChanglog, err := s.GetChangelog(releaseVersion)
|
if releaseVersion.Next.Version.Equal(releaseVersion.Last.Version) {
|
||||||
|
log.Infof("No new version, no release needed %s <> %s", releaseVersion.Next.Version.String(), releaseVersion.Last.Version.String())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
generatedChangelog, err := s.GetChangelog(releaseVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Could not get changelog")
|
log.Debugf("Could not get changelog")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
releaser, err := releaser.New(s.config).GetReleaser()
|
integrations := integrations.New(&s.config.Integrations, releaseVersion)
|
||||||
if err != nil {
|
if err := integrations.Run(); err != nil {
|
||||||
|
log.Debugf("Error during integrations run")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = releaser.ValidateConfig()
|
hook := hooks.New(s.config, releaseVersion)
|
||||||
if err != nil {
|
if err := hook.PreRelease(); err != nil {
|
||||||
|
log.Debugf("Error during pre release hook")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = releaser.CreateRelease(releaseVersion, generatedChanglog); err != nil {
|
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 {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = releaser.UploadAssets(s.repository, s.config.Assets); err != nil {
|
if err := hook.PostRelease(); err != nil {
|
||||||
|
log.Debugf("Error during post release hook")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,12 +359,21 @@ func (s *SemanticRelease) Release(force bool) error {
|
|||||||
|
|
||||||
// ZipFiles zip files configured in release config
|
// ZipFiles zip files configured in release config
|
||||||
func (s *SemanticRelease) ZipFiles() error {
|
func (s *SemanticRelease) ZipFiles() error {
|
||||||
for _, file := range s.config.Assets {
|
assets := assets.New(s.repository, "")
|
||||||
if file.Compress {
|
|
||||||
if _, err := util.PrepareAssets(s.repository, s.config.Assets); err != nil {
|
if err := assets.Add(s.config.Assets...); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := assets.GenerateChecksum(); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, asset := range assets.All() {
|
||||||
|
path, err := asset.GetPath()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
log.Infof("File %s under %s is zipped %t", asset.GetName(), path, asset.IsCompressed())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
83
pkg/semanticrelease/semantic-release_test.go
Normal file
83
pkg/semanticrelease/semantic-release_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
85
scripts/commit-filter-check.sh
Executable file
85
scripts/commit-filter-check.sh
Executable file
@@ -0,0 +1,85 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
commit_message_check (){
|
||||||
|
# Get the current branch and apply it to a variable
|
||||||
|
currentbranch=`git branch | grep \* | cut -d ' ' -f2`
|
||||||
|
|
||||||
|
# Gets the commits for the current branch and outputs to file
|
||||||
|
git log $currentbranch --pretty=format:"%H" --not master > shafile.txt
|
||||||
|
|
||||||
|
# loops through the file an gets the message
|
||||||
|
for i in `cat ./shafile.txt`;
|
||||||
|
do
|
||||||
|
# gets the git commit message based on the sha
|
||||||
|
gitmessage=`git log --format=%B -n 1 "$i"`
|
||||||
|
|
||||||
|
####################### TEST STRINGS comment out line 13 to use #########################################
|
||||||
|
#gitmessage="feat sdasdsadsaas (AEROGEAR-asdsada)"
|
||||||
|
#gitmessage="feat(some txt): some txt (AEROGEAR-****)"
|
||||||
|
#gitmessage="docs(some txt): some txt (AEROGEAR-1234)"
|
||||||
|
#gitmessage="fix(some txt): some txt (AEROGEAR-5678)"
|
||||||
|
#########################################################################################################
|
||||||
|
|
||||||
|
# Checks gitmessage for string feat, fix, docs and breaking, if the messagecheck var is empty if fails
|
||||||
|
messagecheck=`echo $gitmessage | grep -w "chore\|feat\|fix\|docs\|breaking"`
|
||||||
|
if [ -z "$messagecheck" ]
|
||||||
|
then
|
||||||
|
echo "Your commit message must begin with one of the following"
|
||||||
|
echo " feat(feature-name)"
|
||||||
|
echo " fix(fix-name)"
|
||||||
|
echo " docs(docs-change)"
|
||||||
|
echo " "
|
||||||
|
fi
|
||||||
|
if [ ${PerformProjectCheck} == "true" ]; then
|
||||||
|
#check the gitmessage for the Jira number
|
||||||
|
messagecheck=`echo $gitmessage | grep "(${ProjectID}-"`
|
||||||
|
if [ -z "$messagecheck" ]
|
||||||
|
then
|
||||||
|
echo "Your commit message must end with the following"
|
||||||
|
echo " (${ProjectID}-****)"
|
||||||
|
echo "Where **** is the Jira number"
|
||||||
|
echo " "
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
messagecheck=`echo $gitmessage | grep ": "`
|
||||||
|
if [ -z "$messagecheck" ]
|
||||||
|
then
|
||||||
|
echo "Your commit message has a formatting error please take note of special characters '():' position and use in the example below"
|
||||||
|
echo " type(some txt): some txt (${ProjectID}-****)"
|
||||||
|
echo "Where 'type' is fix, feat, docs or breaking and **** is the Jira number"
|
||||||
|
echo " "
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${PerformProjectCheck} == "true" ]; then
|
||||||
|
# All checks run at the same time by pipeing from one grep to another
|
||||||
|
messagecheck=`echo $gitmessage | grep -w "chore\|feat\|fix\|docs\|breaking" | grep "(${ProjectID}-" | grep ": "`
|
||||||
|
else
|
||||||
|
# All checks run at the same time by pipeing from one grep to another
|
||||||
|
messagecheck=`echo $gitmessage | grep -w "chore\|feat\|fix\|docs\|breaking" | grep ": "`
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# check to see if the messagecheck var is empty
|
||||||
|
if [ -z "$messagecheck" ]
|
||||||
|
then
|
||||||
|
echo "The commit message with sha: '$i' failed "
|
||||||
|
echo "Please review the following :"
|
||||||
|
echo " "
|
||||||
|
echo $gitmessage
|
||||||
|
echo " "
|
||||||
|
rm shafile.txt >/dev/null 2>&1
|
||||||
|
set -o errexit
|
||||||
|
else
|
||||||
|
echo "$messagecheck"
|
||||||
|
echo "'$i' commit message passed"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
rm shafile.txt >/dev/null 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ProjectID="NA" # Set to your Jira Project ID if want to track references to tickets.
|
||||||
|
PerformProjectCheck="false" # Set true if ProjectID is set and you want to ensure Jira ref is included on commit.
|
||||||
|
# Calling the function
|
||||||
|
commit_message_check
|
||||||
20
vendor/code.gitea.io/sdk/gitea/LICENSE
generated
vendored
Normal file
20
vendor/code.gitea.io/sdk/gitea/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
Copyright (c) 2016 The Gitea Authors
|
||||||
|
Copyright (c) 2014 The Gogs Authors
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
47
vendor/code.gitea.io/sdk/gitea/admin_cron.go
generated
vendored
Normal file
47
vendor/code.gitea.io/sdk/gitea/admin_cron.go
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// CronTask represents a Cron task
|
||||||
|
type CronTask struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Schedule string `json:"schedule"`
|
||||||
|
Next time.Time `json:"next"`
|
||||||
|
Prev time.Time `json:"prev"`
|
||||||
|
ExecTimes int64 `json:"exec_times"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListCronTaskOptions list options for ListCronTasks
|
||||||
|
type ListCronTaskOptions struct {
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListCronTasks list available cron tasks
|
||||||
|
func (c *Client) ListCronTasks(opt ListCronTaskOptions) ([]*CronTask, *Response, error) {
|
||||||
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_13_0); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
opt.setDefaults()
|
||||||
|
ct := make([]*CronTask, 0, opt.PageSize)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/admin/cron?%s", opt.getURLQuery().Encode()), jsonHeader, nil, &ct)
|
||||||
|
return ct, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunCronTasks run a cron task
|
||||||
|
func (c *Client) RunCronTasks(task string) (*Response, error) {
|
||||||
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_13_0); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := escapeValidatePathSegments(&task); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("POST", fmt.Sprintf("/admin/cron/%s", task), jsonHeader, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
39
vendor/code.gitea.io/sdk/gitea/admin_org.go
generated
vendored
Normal file
39
vendor/code.gitea.io/sdk/gitea/admin_org.go
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
// Copyright 2015 The Gogs Authors. All rights reserved.
|
||||||
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AdminListOrgsOptions options for listing admin's organizations
|
||||||
|
type AdminListOrgsOptions struct {
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminListOrgs lists all orgs
|
||||||
|
func (c *Client) AdminListOrgs(opt AdminListOrgsOptions) ([]*Organization, *Response, error) {
|
||||||
|
opt.setDefaults()
|
||||||
|
orgs := make([]*Organization, 0, opt.PageSize)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/admin/orgs?%s", opt.getURLQuery().Encode()), nil, nil, &orgs)
|
||||||
|
return orgs, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminCreateOrg create an organization
|
||||||
|
func (c *Client) AdminCreateOrg(user string, opt CreateOrgOption) (*Organization, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
org := new(Organization)
|
||||||
|
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/orgs", user), jsonHeader, bytes.NewReader(body), org)
|
||||||
|
return org, resp, err
|
||||||
|
}
|
||||||
25
vendor/code.gitea.io/sdk/gitea/admin_repo.go
generated
vendored
Normal file
25
vendor/code.gitea.io/sdk/gitea/admin_repo.go
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// Copyright 2015 The Gogs Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AdminCreateRepo create a repo
|
||||||
|
func (c *Client) AdminCreateRepo(user string, opt CreateRepoOption) (*Repository, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
repo := new(Repository)
|
||||||
|
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/repos", user), jsonHeader, bytes.NewReader(body), repo)
|
||||||
|
return repo, resp, err
|
||||||
|
}
|
||||||
130
vendor/code.gitea.io/sdk/gitea/admin_user.go
generated
vendored
Normal file
130
vendor/code.gitea.io/sdk/gitea/admin_user.go
generated
vendored
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
// Copyright 2015 The Gogs Authors. All rights reserved.
|
||||||
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AdminListUsersOptions options for listing admin users
|
||||||
|
type AdminListUsersOptions struct {
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminListUsers lists all users
|
||||||
|
func (c *Client) AdminListUsers(opt AdminListUsersOptions) ([]*User, *Response, error) {
|
||||||
|
opt.setDefaults()
|
||||||
|
users := make([]*User, 0, opt.PageSize)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/admin/users?%s", opt.getURLQuery().Encode()), nil, nil, &users)
|
||||||
|
return users, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateUserOption create user options
|
||||||
|
type CreateUserOption struct {
|
||||||
|
SourceID int64 `json:"source_id"`
|
||||||
|
LoginName string `json:"login_name"`
|
||||||
|
Username string `json:"username"`
|
||||||
|
FullName string `json:"full_name"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
Password string `json:"password"`
|
||||||
|
MustChangePassword *bool `json:"must_change_password"`
|
||||||
|
SendNotify bool `json:"send_notify"`
|
||||||
|
Visibility *VisibleType `json:"visibility"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the CreateUserOption struct
|
||||||
|
func (opt CreateUserOption) Validate() error {
|
||||||
|
if len(opt.Email) == 0 {
|
||||||
|
return fmt.Errorf("email is empty")
|
||||||
|
}
|
||||||
|
if len(opt.Username) == 0 {
|
||||||
|
return fmt.Errorf("username is empty")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminCreateUser create a user
|
||||||
|
func (c *Client) AdminCreateUser(opt CreateUserOption) (*User, *Response, error) {
|
||||||
|
if err := opt.Validate(); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
user := new(User)
|
||||||
|
resp, err := c.getParsedResponse("POST", "/admin/users", jsonHeader, bytes.NewReader(body), user)
|
||||||
|
return user, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditUserOption edit user options
|
||||||
|
type EditUserOption struct {
|
||||||
|
SourceID int64 `json:"source_id"`
|
||||||
|
LoginName string `json:"login_name"`
|
||||||
|
Email *string `json:"email"`
|
||||||
|
FullName *string `json:"full_name"`
|
||||||
|
Password string `json:"password"`
|
||||||
|
Description *string `json:"description"`
|
||||||
|
MustChangePassword *bool `json:"must_change_password"`
|
||||||
|
Website *string `json:"website"`
|
||||||
|
Location *string `json:"location"`
|
||||||
|
Active *bool `json:"active"`
|
||||||
|
Admin *bool `json:"admin"`
|
||||||
|
AllowGitHook *bool `json:"allow_git_hook"`
|
||||||
|
AllowImportLocal *bool `json:"allow_import_local"`
|
||||||
|
MaxRepoCreation *int `json:"max_repo_creation"`
|
||||||
|
ProhibitLogin *bool `json:"prohibit_login"`
|
||||||
|
AllowCreateOrganization *bool `json:"allow_create_organization"`
|
||||||
|
Restricted *bool `json:"restricted"`
|
||||||
|
Visibility *VisibleType `json:"visibility"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminEditUser modify user informations
|
||||||
|
func (c *Client) AdminEditUser(user string, opt EditUserOption) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("PATCH", fmt.Sprintf("/admin/users/%s", user), jsonHeader, bytes.NewReader(body))
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminDeleteUser delete one user according name
|
||||||
|
func (c *Client) AdminDeleteUser(user string) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s", user), nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminCreateUserPublicKey adds a public key for the user
|
||||||
|
func (c *Client) AdminCreateUserPublicKey(user string, opt CreateKeyOption) (*PublicKey, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
key := new(PublicKey)
|
||||||
|
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/admin/users/%s/keys", user), jsonHeader, bytes.NewReader(body), key)
|
||||||
|
return key, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// AdminDeleteUserPublicKey deletes a user's public key
|
||||||
|
func (c *Client) AdminDeleteUserPublicKey(user string, keyID int) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/admin/users/%s/keys/%d", user, keyID), nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
38
vendor/code.gitea.io/sdk/gitea/agent.go
generated
vendored
Normal file
38
vendor/code.gitea.io/sdk/gitea/agent.go
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build !windows
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/ssh/agent"
|
||||||
|
)
|
||||||
|
|
||||||
|
// hasAgent returns true if the ssh agent is available
|
||||||
|
func hasAgent() bool {
|
||||||
|
if _, err := os.Stat(os.Getenv("SSH_AUTH_SOCK")); err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAgent returns a ssh agent
|
||||||
|
func GetAgent() (agent.Agent, error) {
|
||||||
|
if !hasAgent() {
|
||||||
|
return nil, fmt.Errorf("no ssh agent available")
|
||||||
|
}
|
||||||
|
|
||||||
|
sshAgent, err := net.Dial("unix", os.Getenv("SSH_AUTH_SOCK"))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return agent.NewClient(sshAgent), nil
|
||||||
|
}
|
||||||
28
vendor/code.gitea.io/sdk/gitea/agent_windows.go
generated
vendored
Normal file
28
vendor/code.gitea.io/sdk/gitea/agent_windows.go
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
//go:build windows
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/davidmz/go-pageant"
|
||||||
|
"golang.org/x/crypto/ssh/agent"
|
||||||
|
)
|
||||||
|
|
||||||
|
// hasAgent returns true if pageant is available
|
||||||
|
func hasAgent() bool {
|
||||||
|
return pageant.Available()
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAgent returns a ssh agent
|
||||||
|
func GetAgent() (agent.Agent, error) {
|
||||||
|
if !hasAgent() {
|
||||||
|
return nil, fmt.Errorf("no pageant available")
|
||||||
|
}
|
||||||
|
|
||||||
|
return pageant.New(), nil
|
||||||
|
}
|
||||||
111
vendor/code.gitea.io/sdk/gitea/attachment.go
generated
vendored
Normal file
111
vendor/code.gitea.io/sdk/gitea/attachment.go
generated
vendored
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea // import "code.gitea.io/sdk/gitea"
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"mime/multipart"
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Attachment a generic attachment
|
||||||
|
type Attachment struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
DownloadCount int64 `json:"download_count"`
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
UUID string `json:"uuid"`
|
||||||
|
DownloadURL string `json:"browser_download_url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListReleaseAttachmentsOptions options for listing release's attachments
|
||||||
|
type ListReleaseAttachmentsOptions struct {
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListReleaseAttachments list release's attachments
|
||||||
|
func (c *Client) ListReleaseAttachments(user, repo string, release int64, opt ListReleaseAttachmentsOptions) ([]*Attachment, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
opt.setDefaults()
|
||||||
|
attachments := make([]*Attachment, 0, opt.PageSize)
|
||||||
|
resp, err := c.getParsedResponse("GET",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/releases/%d/assets?%s", user, repo, release, opt.getURLQuery().Encode()),
|
||||||
|
nil, nil, &attachments)
|
||||||
|
return attachments, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetReleaseAttachment returns the requested attachment
|
||||||
|
func (c *Client) GetReleaseAttachment(user, repo string, release, id int64) (*Attachment, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
a := new(Attachment)
|
||||||
|
resp, err := c.getParsedResponse("GET",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, id),
|
||||||
|
nil, nil, &a)
|
||||||
|
return a, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateReleaseAttachment creates an attachment for the given release
|
||||||
|
func (c *Client) CreateReleaseAttachment(user, repo string, release int64, file io.Reader, filename string) (*Attachment, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
// Write file to body
|
||||||
|
body := new(bytes.Buffer)
|
||||||
|
writer := multipart.NewWriter(body)
|
||||||
|
part, err := writer.CreateFormFile("attachment", filename)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = io.Copy(part, file); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if err = writer.Close(); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send request
|
||||||
|
attachment := new(Attachment)
|
||||||
|
resp, err := c.getParsedResponse("POST",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/releases/%d/assets", user, repo, release),
|
||||||
|
http.Header{"Content-Type": {writer.FormDataContentType()}}, body, &attachment)
|
||||||
|
return attachment, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditAttachmentOptions options for editing attachments
|
||||||
|
type EditAttachmentOptions struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditReleaseAttachment updates the given attachment with the given options
|
||||||
|
func (c *Client) EditReleaseAttachment(user, repo string, release, attachment int64, form EditAttachmentOptions) (*Attachment, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&form)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
attach := new(Attachment)
|
||||||
|
resp, err := c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, attachment), jsonHeader, bytes.NewReader(body), attach)
|
||||||
|
return attach, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteReleaseAttachment deletes the given attachment including the uploaded file
|
||||||
|
func (c *Client) DeleteReleaseAttachment(user, repo string, release, id int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/releases/%d/assets/%d", user, repo, release, id), nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
499
vendor/code.gitea.io/sdk/gitea/client.go
generated
vendored
Normal file
499
vendor/code.gitea.io/sdk/gitea/client.go
generated
vendored
Normal file
@@ -0,0 +1,499 @@
|
|||||||
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||||
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/hashicorp/go-version"
|
||||||
|
)
|
||||||
|
|
||||||
|
var jsonHeader = http.Header{"content-type": []string{"application/json"}}
|
||||||
|
|
||||||
|
// Version return the library version
|
||||||
|
func Version() string {
|
||||||
|
return "0.16.0"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client represents a thread-safe Gitea API client.
|
||||||
|
type Client struct {
|
||||||
|
url string
|
||||||
|
accessToken string
|
||||||
|
username string
|
||||||
|
password string
|
||||||
|
otp string
|
||||||
|
sudo string
|
||||||
|
userAgent string
|
||||||
|
debug bool
|
||||||
|
httpsigner *HTTPSign
|
||||||
|
client *http.Client
|
||||||
|
ctx context.Context
|
||||||
|
mutex sync.RWMutex
|
||||||
|
serverVersion *version.Version
|
||||||
|
getVersionOnce sync.Once
|
||||||
|
ignoreVersion bool // only set by SetGiteaVersion so don't need a mutex lock
|
||||||
|
}
|
||||||
|
|
||||||
|
// Response represents the gitea response
|
||||||
|
type Response struct {
|
||||||
|
*http.Response
|
||||||
|
|
||||||
|
FirstPage int
|
||||||
|
PrevPage int
|
||||||
|
NextPage int
|
||||||
|
LastPage int
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClientOption are functions used to init a new client
|
||||||
|
type ClientOption func(*Client) error
|
||||||
|
|
||||||
|
// NewClient initializes and returns a API client.
|
||||||
|
// Usage of all gitea.Client methods is concurrency-safe.
|
||||||
|
func NewClient(url string, options ...ClientOption) (*Client, error) {
|
||||||
|
client := &Client{
|
||||||
|
url: strings.TrimSuffix(url, "/"),
|
||||||
|
client: &http.Client{},
|
||||||
|
ctx: context.Background(),
|
||||||
|
}
|
||||||
|
for _, opt := range options {
|
||||||
|
if err := opt(client); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := client.checkServerVersionGreaterThanOrEqual(version1_11_0); err != nil {
|
||||||
|
if errors.Is(err, &ErrUnknownVersion{}) {
|
||||||
|
return client, err
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewClientWithHTTP creates an API client with a custom http client
|
||||||
|
// Deprecated use SetHTTPClient option
|
||||||
|
func NewClientWithHTTP(url string, httpClient *http.Client) *Client {
|
||||||
|
client, _ := NewClient(url, SetHTTPClient(httpClient))
|
||||||
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetHTTPClient is an option for NewClient to set custom http client
|
||||||
|
func SetHTTPClient(httpClient *http.Client) ClientOption {
|
||||||
|
return func(client *Client) error {
|
||||||
|
client.SetHTTPClient(httpClient)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetHTTPClient replaces default http.Client with user given one.
|
||||||
|
func (c *Client) SetHTTPClient(client *http.Client) {
|
||||||
|
c.mutex.Lock()
|
||||||
|
c.client = client
|
||||||
|
c.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetToken is an option for NewClient to set token
|
||||||
|
func SetToken(token string) ClientOption {
|
||||||
|
return func(client *Client) error {
|
||||||
|
client.mutex.Lock()
|
||||||
|
client.accessToken = token
|
||||||
|
client.mutex.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBasicAuth is an option for NewClient to set username and password
|
||||||
|
func SetBasicAuth(username, password string) ClientOption {
|
||||||
|
return func(client *Client) error {
|
||||||
|
client.SetBasicAuth(username, password)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UseSSHCert is an option for NewClient to enable SSH certificate authentication via HTTPSign
|
||||||
|
// If you want to auth against the ssh-agent you'll need to set a principal, if you want to
|
||||||
|
// use a file on disk you'll need to specify sshKey.
|
||||||
|
// If you have an encrypted sshKey you'll need to also set the passphrase.
|
||||||
|
func UseSSHCert(principal, sshKey, passphrase string) ClientOption {
|
||||||
|
return func(client *Client) error {
|
||||||
|
if err := client.checkServerVersionGreaterThanOrEqual(version1_17_0); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
client.mutex.Lock()
|
||||||
|
defer client.mutex.Unlock()
|
||||||
|
|
||||||
|
var err error
|
||||||
|
client.httpsigner, err = NewHTTPSignWithCert(principal, sshKey, passphrase)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UseSSHPubkey is an option for NewClient to enable SSH pubkey authentication via HTTPSign
|
||||||
|
// If you want to auth against the ssh-agent you'll need to set a fingerprint, if you want to
|
||||||
|
// use a file on disk you'll need to specify sshKey.
|
||||||
|
// If you have an encrypted sshKey you'll need to also set the passphrase.
|
||||||
|
func UseSSHPubkey(fingerprint, sshKey, passphrase string) ClientOption {
|
||||||
|
return func(client *Client) error {
|
||||||
|
if err := client.checkServerVersionGreaterThanOrEqual(version1_17_0); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
client.mutex.Lock()
|
||||||
|
defer client.mutex.Unlock()
|
||||||
|
|
||||||
|
var err error
|
||||||
|
client.httpsigner, err = NewHTTPSignWithPubkey(fingerprint, sshKey, passphrase)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetBasicAuth sets username and password
|
||||||
|
func (c *Client) SetBasicAuth(username, password string) {
|
||||||
|
c.mutex.Lock()
|
||||||
|
c.username, c.password = username, password
|
||||||
|
c.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOTP is an option for NewClient to set OTP for 2FA
|
||||||
|
func SetOTP(otp string) ClientOption {
|
||||||
|
return func(client *Client) error {
|
||||||
|
client.SetOTP(otp)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetOTP sets OTP for 2FA
|
||||||
|
func (c *Client) SetOTP(otp string) {
|
||||||
|
c.mutex.Lock()
|
||||||
|
c.otp = otp
|
||||||
|
c.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContext is an option for NewClient to set the default context
|
||||||
|
func SetContext(ctx context.Context) ClientOption {
|
||||||
|
return func(client *Client) error {
|
||||||
|
client.SetContext(ctx)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetContext set default context witch is used for http requests
|
||||||
|
func (c *Client) SetContext(ctx context.Context) {
|
||||||
|
c.mutex.Lock()
|
||||||
|
c.ctx = ctx
|
||||||
|
c.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSudo is an option for NewClient to set sudo header
|
||||||
|
func SetSudo(sudo string) ClientOption {
|
||||||
|
return func(client *Client) error {
|
||||||
|
client.SetSudo(sudo)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSudo sets username to impersonate.
|
||||||
|
func (c *Client) SetSudo(sudo string) {
|
||||||
|
c.mutex.Lock()
|
||||||
|
c.sudo = sudo
|
||||||
|
c.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserAgent is an option for NewClient to set user-agent header
|
||||||
|
func SetUserAgent(userAgent string) ClientOption {
|
||||||
|
return func(client *Client) error {
|
||||||
|
client.SetUserAgent(userAgent)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetUserAgent sets the user-agent to send with every request.
|
||||||
|
func (c *Client) SetUserAgent(userAgent string) {
|
||||||
|
c.mutex.Lock()
|
||||||
|
c.userAgent = userAgent
|
||||||
|
c.mutex.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetDebugMode is an option for NewClient to enable debug mode
|
||||||
|
func SetDebugMode() ClientOption {
|
||||||
|
return func(client *Client) error {
|
||||||
|
client.mutex.Lock()
|
||||||
|
client.debug = true
|
||||||
|
client.mutex.Unlock()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newResponse(r *http.Response) *Response {
|
||||||
|
response := &Response{Response: r}
|
||||||
|
response.parseLinkHeader()
|
||||||
|
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Response) parseLinkHeader() {
|
||||||
|
link := r.Header.Get("Link")
|
||||||
|
if link == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
links := strings.Split(link, ",")
|
||||||
|
for _, l := range links {
|
||||||
|
u, param, ok := strings.Cut(l, ";")
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
u = strings.Trim(u, " <>")
|
||||||
|
|
||||||
|
key, value, ok := strings.Cut(strings.TrimSpace(param), "=")
|
||||||
|
if !ok || key != "rel" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
value = strings.Trim(value, "\"")
|
||||||
|
|
||||||
|
parsed, err := url.Parse(u)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
page := parsed.Query().Get("page")
|
||||||
|
if page == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
switch value {
|
||||||
|
case "first":
|
||||||
|
r.FirstPage, _ = strconv.Atoi(page)
|
||||||
|
case "prev":
|
||||||
|
r.PrevPage, _ = strconv.Atoi(page)
|
||||||
|
case "next":
|
||||||
|
r.NextPage, _ = strconv.Atoi(page)
|
||||||
|
case "last":
|
||||||
|
r.LastPage, _ = strconv.Atoi(page)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) getWebResponse(method, path string, body io.Reader) ([]byte, *Response, error) {
|
||||||
|
c.mutex.RLock()
|
||||||
|
debug := c.debug
|
||||||
|
if debug {
|
||||||
|
fmt.Printf("%s: %s\nBody: %v\n", method, c.url+path, body)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequestWithContext(c.ctx, method, c.url+path, body)
|
||||||
|
|
||||||
|
client := c.client // client ref can change from this point on so safe it
|
||||||
|
c.mutex.RUnlock()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
data, err := io.ReadAll(resp.Body)
|
||||||
|
if debug {
|
||||||
|
fmt.Printf("Response: %v\n\n", resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, newResponse(resp), err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) doRequest(method, path string, header http.Header, body io.Reader) (*Response, error) {
|
||||||
|
c.mutex.RLock()
|
||||||
|
debug := c.debug
|
||||||
|
if debug {
|
||||||
|
var bodyStr string
|
||||||
|
if body != nil {
|
||||||
|
bs, _ := io.ReadAll(body)
|
||||||
|
body = bytes.NewReader(bs)
|
||||||
|
bodyStr = string(bs)
|
||||||
|
}
|
||||||
|
fmt.Printf("%s: %s\nHeader: %v\nBody: %s\n", method, c.url+"/api/v1"+path, header, bodyStr)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequestWithContext(c.ctx, method, c.url+"/api/v1"+path, body)
|
||||||
|
if err != nil {
|
||||||
|
c.mutex.RUnlock()
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(c.accessToken) != 0 {
|
||||||
|
req.Header.Set("Authorization", "token "+c.accessToken)
|
||||||
|
}
|
||||||
|
if len(c.otp) != 0 {
|
||||||
|
req.Header.Set("X-GITEA-OTP", c.otp)
|
||||||
|
}
|
||||||
|
if len(c.username) != 0 {
|
||||||
|
req.SetBasicAuth(c.username, c.password)
|
||||||
|
}
|
||||||
|
if len(c.sudo) != 0 {
|
||||||
|
req.Header.Set("Sudo", c.sudo)
|
||||||
|
}
|
||||||
|
if len(c.userAgent) != 0 {
|
||||||
|
req.Header.Set("User-Agent", c.userAgent)
|
||||||
|
}
|
||||||
|
|
||||||
|
client := c.client // client ref can change from this point on so safe it
|
||||||
|
c.mutex.RUnlock()
|
||||||
|
|
||||||
|
for k, v := range header {
|
||||||
|
req.Header[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.httpsigner != nil {
|
||||||
|
err = c.SignRequest(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if debug {
|
||||||
|
fmt.Printf("Response: %v\n\n", resp)
|
||||||
|
}
|
||||||
|
|
||||||
|
return newResponse(resp), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Converts a response for a HTTP status code indicating an error condition
|
||||||
|
// (non-2XX) to a well-known error value and response body. For non-problematic
|
||||||
|
// (2XX) status codes nil will be returned. Note that on a non-2XX response, the
|
||||||
|
// response body stream will have been read and, hence, is closed on return.
|
||||||
|
func statusCodeToErr(resp *Response) (body []byte, err error) {
|
||||||
|
// no error
|
||||||
|
if resp.StatusCode/100 == 2 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// error: body will be read for details
|
||||||
|
//
|
||||||
|
defer resp.Body.Close()
|
||||||
|
data, err := io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("body read on HTTP error %d: %v", resp.StatusCode, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to unmarshal and get an error message
|
||||||
|
errMap := make(map[string]interface{})
|
||||||
|
if err = json.Unmarshal(data, &errMap); err != nil {
|
||||||
|
// when the JSON can't be parsed, data was probably empty or a
|
||||||
|
// plain string, so we try to return a helpful error anyway
|
||||||
|
path := resp.Request.URL.Path
|
||||||
|
method := resp.Request.Method
|
||||||
|
header := resp.Request.Header
|
||||||
|
return data, fmt.Errorf("Unknown API Error: %d\nRequest: '%s' with '%s' method '%s' header and '%s' body", resp.StatusCode, path, method, header, string(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
if msg, ok := errMap["message"]; ok {
|
||||||
|
return data, fmt.Errorf("%v", msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no error message, at least give status and data
|
||||||
|
return data, fmt.Errorf("%s: %s", resp.Status, string(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) getResponseReader(method, path string, header http.Header, body io.Reader) (io.ReadCloser, *Response, error) {
|
||||||
|
resp, err := c.doRequest(method, path, header, body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for errors
|
||||||
|
data, err := statusCodeToErr(resp)
|
||||||
|
if err != nil {
|
||||||
|
return io.NopCloser(bytes.NewReader(data)), resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp.Body, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) getResponse(method, path string, header http.Header, body io.Reader) ([]byte, *Response, error) {
|
||||||
|
resp, err := c.doRequest(method, path, header, body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// check for errors
|
||||||
|
data, err := statusCodeToErr(resp)
|
||||||
|
if err != nil {
|
||||||
|
return data, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// success (2XX), read body
|
||||||
|
data, err = io.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return nil, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return data, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) getParsedResponse(method, path string, header http.Header, body io.Reader, obj interface{}) (*Response, error) {
|
||||||
|
data, resp, err := c.getResponse(method, path, header, body)
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
return resp, json.Unmarshal(data, obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) getStatusCode(method, path string, header http.Header, body io.Reader) (int, *Response, error) {
|
||||||
|
resp, err := c.doRequest(method, path, header, body)
|
||||||
|
if err != nil {
|
||||||
|
return -1, resp, err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
return resp.StatusCode, resp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// pathEscapeSegments escapes segments of a path while not escaping forward slash
|
||||||
|
func pathEscapeSegments(path string) string {
|
||||||
|
slice := strings.Split(path, "/")
|
||||||
|
for index := range slice {
|
||||||
|
slice[index] = url.PathEscape(slice[index])
|
||||||
|
}
|
||||||
|
escapedPath := strings.Join(slice, "/")
|
||||||
|
return escapedPath
|
||||||
|
}
|
||||||
|
|
||||||
|
// escapeValidatePathSegments is a help function to validate and encode url path segments
|
||||||
|
func escapeValidatePathSegments(seg ...*string) error {
|
||||||
|
for i := range seg {
|
||||||
|
if seg[i] == nil || len(*seg[i]) == 0 {
|
||||||
|
return fmt.Errorf("path segment [%d] is empty", i)
|
||||||
|
}
|
||||||
|
*seg[i] = url.PathEscape(*seg[i])
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
9
vendor/code.gitea.io/sdk/gitea/doc.go
generated
vendored
Normal file
9
vendor/code.gitea.io/sdk/gitea/doc.go
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Copyright 2016 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// Package gitea implements a client for the Gitea API.
|
||||||
|
// The version corresponds to the highest supported version
|
||||||
|
// of the gitea API, but backwards-compatibility is mostly
|
||||||
|
// given.
|
||||||
|
package gitea // import "code.gitea.io/sdk/gitea"
|
||||||
51
vendor/code.gitea.io/sdk/gitea/fork.go
generated
vendored
Normal file
51
vendor/code.gitea.io/sdk/gitea/fork.go
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
// Copyright 2016 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ListForksOptions options for listing repository's forks
|
||||||
|
type ListForksOptions struct {
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListForks list a repository's forks
|
||||||
|
func (c *Client) ListForks(user, repo string, opt ListForksOptions) ([]*Repository, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
opt.setDefaults()
|
||||||
|
forks := make([]*Repository, opt.PageSize)
|
||||||
|
resp, err := c.getParsedResponse("GET",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/forks?%s", user, repo, opt.getURLQuery().Encode()),
|
||||||
|
nil, nil, &forks)
|
||||||
|
return forks, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateForkOption options for creating a fork
|
||||||
|
type CreateForkOption struct {
|
||||||
|
// organization name, if forking into an organization
|
||||||
|
Organization *string `json:"organization"`
|
||||||
|
// name of the forked repository
|
||||||
|
Name *string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateFork create a fork of a repository
|
||||||
|
func (c *Client) CreateFork(user, repo string, form CreateForkOption) (*Repository, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(form)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
fork := new(Repository)
|
||||||
|
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/forks", user, repo), jsonHeader, bytes.NewReader(body), &fork)
|
||||||
|
return fork, resp, err
|
||||||
|
}
|
||||||
28
vendor/code.gitea.io/sdk/gitea/git_blob.go
generated
vendored
Normal file
28
vendor/code.gitea.io/sdk/gitea/git_blob.go
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GitBlobResponse represents a git blob
|
||||||
|
type GitBlobResponse struct {
|
||||||
|
Content string `json:"content"`
|
||||||
|
Encoding string `json:"encoding"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
SHA string `json:"sha"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetBlob get the blob of a repository file
|
||||||
|
func (c *Client) GetBlob(user, repo, sha string) (*GitBlobResponse, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo, &sha); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
blob := new(GitBlobResponse)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/git/blobs/%s", user, repo, sha), nil, nil, blob)
|
||||||
|
return blob, resp, err
|
||||||
|
}
|
||||||
71
vendor/code.gitea.io/sdk/gitea/git_hook.go
generated
vendored
Normal file
71
vendor/code.gitea.io/sdk/gitea/git_hook.go
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GitHook represents a Git repository hook
|
||||||
|
type GitHook struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
IsActive bool `json:"is_active"`
|
||||||
|
Content string `json:"content,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepoGitHooksOptions options for listing repository's githooks
|
||||||
|
type ListRepoGitHooksOptions struct {
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepoGitHooks list all the Git hooks of one repository
|
||||||
|
func (c *Client) ListRepoGitHooks(user, repo string, opt ListRepoGitHooksOptions) ([]*GitHook, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
opt.setDefaults()
|
||||||
|
hooks := make([]*GitHook, 0, opt.PageSize)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks/git?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, &hooks)
|
||||||
|
return hooks, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRepoGitHook get a Git hook of a repository
|
||||||
|
func (c *Client) GetRepoGitHook(user, repo, id string) (*GitHook, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo, &id); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
h := new(GitHook)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks/git/%s", user, repo, id), nil, nil, h)
|
||||||
|
return h, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditGitHookOption options when modifying one Git hook
|
||||||
|
type EditGitHookOption struct {
|
||||||
|
Content string `json:"content"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditRepoGitHook modify one Git hook of a repository
|
||||||
|
func (c *Client) EditRepoGitHook(user, repo, id string, opt EditGitHookOption) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo, &id); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("PATCH", fmt.Sprintf("/repos/%s/%s/hooks/git/%s", user, repo, id), jsonHeader, bytes.NewReader(body))
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteRepoGitHook delete one Git hook from a repository
|
||||||
|
func (c *Client) DeleteRepoGitHook(user, repo, id string) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo, &id); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/hooks/git/%s", user, repo, id), nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
20
vendor/code.gitea.io/sdk/gitea/helper.go
generated
vendored
Normal file
20
vendor/code.gitea.io/sdk/gitea/helper.go
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
// OptionalBool convert a bool to a bool reference
|
||||||
|
func OptionalBool(v bool) *bool {
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
||||||
|
// OptionalString convert a string to a string reference
|
||||||
|
func OptionalString(v string) *string {
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
||||||
|
// OptionalInt64 convert a int64 to a int64 reference
|
||||||
|
func OptionalInt64(v int64) *int64 {
|
||||||
|
return &v
|
||||||
|
}
|
||||||
196
vendor/code.gitea.io/sdk/gitea/hook.go
generated
vendored
Normal file
196
vendor/code.gitea.io/sdk/gitea/hook.go
generated
vendored
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||||
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Hook a hook is a web hook when one repository changed
|
||||||
|
type Hook struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
URL string `json:"-"`
|
||||||
|
Config map[string]string `json:"config"`
|
||||||
|
Events []string `json:"events"`
|
||||||
|
Active bool `json:"active"`
|
||||||
|
Updated time.Time `json:"updated_at"`
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// HookType represent all webhook types gitea currently offer
|
||||||
|
type HookType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// HookTypeDingtalk webhook that dingtalk understand
|
||||||
|
HookTypeDingtalk HookType = "dingtalk"
|
||||||
|
// HookTypeDiscord webhook that discord understand
|
||||||
|
HookTypeDiscord HookType = "discord"
|
||||||
|
// HookTypeGitea webhook that gitea understand
|
||||||
|
HookTypeGitea HookType = "gitea"
|
||||||
|
// HookTypeGogs webhook that gogs understand
|
||||||
|
HookTypeGogs HookType = "gogs"
|
||||||
|
// HookTypeMsteams webhook that msteams understand
|
||||||
|
HookTypeMsteams HookType = "msteams"
|
||||||
|
// HookTypeSlack webhook that slack understand
|
||||||
|
HookTypeSlack HookType = "slack"
|
||||||
|
// HookTypeTelegram webhook that telegram understand
|
||||||
|
HookTypeTelegram HookType = "telegram"
|
||||||
|
// HookTypeFeishu webhook that feishu understand
|
||||||
|
HookTypeFeishu HookType = "feishu"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ListHooksOptions options for listing hooks
|
||||||
|
type ListHooksOptions struct {
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListOrgHooks list all the hooks of one organization
|
||||||
|
func (c *Client) ListOrgHooks(org string, opt ListHooksOptions) ([]*Hook, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&org); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
opt.setDefaults()
|
||||||
|
hooks := make([]*Hook, 0, opt.PageSize)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/hooks?%s", org, opt.getURLQuery().Encode()), nil, nil, &hooks)
|
||||||
|
return hooks, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepoHooks list all the hooks of one repository
|
||||||
|
func (c *Client) ListRepoHooks(user, repo string, opt ListHooksOptions) ([]*Hook, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
opt.setDefaults()
|
||||||
|
hooks := make([]*Hook, 0, opt.PageSize)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks?%s", user, repo, opt.getURLQuery().Encode()), nil, nil, &hooks)
|
||||||
|
return hooks, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOrgHook get a hook of an organization
|
||||||
|
func (c *Client) GetOrgHook(org string, id int64) (*Hook, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&org); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
h := new(Hook)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/orgs/%s/hooks/%d", org, id), nil, nil, h)
|
||||||
|
return h, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRepoHook get a hook of a repository
|
||||||
|
func (c *Client) GetRepoHook(user, repo string, id int64) (*Hook, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
h := new(Hook)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), nil, nil, h)
|
||||||
|
return h, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateHookOption options when create a hook
|
||||||
|
type CreateHookOption struct {
|
||||||
|
Type HookType `json:"type"`
|
||||||
|
Config map[string]string `json:"config"`
|
||||||
|
Events []string `json:"events"`
|
||||||
|
BranchFilter string `json:"branch_filter"`
|
||||||
|
Active bool `json:"active"`
|
||||||
|
AuthorizationHeader string `json:"authorization_header"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the CreateHookOption struct
|
||||||
|
func (opt CreateHookOption) Validate() error {
|
||||||
|
if len(opt.Type) == 0 {
|
||||||
|
return fmt.Errorf("hook type needed")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateOrgHook create one hook for an organization, with options
|
||||||
|
func (c *Client) CreateOrgHook(org string, opt CreateHookOption) (*Hook, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&org); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if err := opt.Validate(); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
h := new(Hook)
|
||||||
|
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/orgs/%s/hooks", org), jsonHeader, bytes.NewReader(body), h)
|
||||||
|
return h, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateRepoHook create one hook for a repository, with options
|
||||||
|
func (c *Client) CreateRepoHook(user, repo string, opt CreateHookOption) (*Hook, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
h := new(Hook)
|
||||||
|
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/hooks", user, repo), jsonHeader, bytes.NewReader(body), h)
|
||||||
|
return h, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditHookOption options when modify one hook
|
||||||
|
type EditHookOption struct {
|
||||||
|
Config map[string]string `json:"config"`
|
||||||
|
Events []string `json:"events"`
|
||||||
|
BranchFilter string `json:"branch_filter"`
|
||||||
|
Active *bool `json:"active"`
|
||||||
|
AuthorizationHeader string `json:"authorization_header"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditOrgHook modify one hook of an organization, with hook id and options
|
||||||
|
func (c *Client) EditOrgHook(org string, id int64, opt EditHookOption) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&org); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("PATCH", fmt.Sprintf("/orgs/%s/hooks/%d", org, id), jsonHeader, bytes.NewReader(body))
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditRepoHook modify one hook of a repository, with hook id and options
|
||||||
|
func (c *Client) EditRepoHook(user, repo string, id int64, opt EditHookOption) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("PATCH", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), jsonHeader, bytes.NewReader(body))
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteOrgHook delete one hook from an organization, with hook id
|
||||||
|
func (c *Client) DeleteOrgHook(org string, id int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&org); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/orgs/%s/hooks/%d", org, id), nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteRepoHook delete one hook from a repository, with hook id
|
||||||
|
func (c *Client) DeleteRepoHook(user, repo string, id int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/hooks/%d", user, repo, id), nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
59
vendor/code.gitea.io/sdk/gitea/hook_validate.go
generated
vendored
Normal file
59
vendor/code.gitea.io/sdk/gitea/hook_validate.go
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"crypto/hmac"
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/hex"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// VerifyWebhookSignature verifies that a payload matches the X-Gitea-Signature based on a secret
|
||||||
|
func VerifyWebhookSignature(secret, expected string, payload []byte) (bool, error) {
|
||||||
|
hash := hmac.New(sha256.New, []byte(secret))
|
||||||
|
if _, err := hash.Write(payload); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
expectedSum, err := hex.DecodeString(expected)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return hmac.Equal(hash.Sum(nil), expectedSum), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifyWebhookSignatureMiddleware is a http.Handler for verifying X-Gitea-Signature on incoming webhooks
|
||||||
|
func VerifyWebhookSignatureMiddleware(secret string) func(http.Handler) http.Handler {
|
||||||
|
return func(next http.Handler) http.Handler {
|
||||||
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var b bytes.Buffer
|
||||||
|
if _, err := io.Copy(&b, r.Body); err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := r.Header.Get("X-Gitea-Signature")
|
||||||
|
if expected == "" {
|
||||||
|
http.Error(w, "no signature found", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ok, err := VerifyWebhookSignature(secret, expected, b.Bytes())
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !ok {
|
||||||
|
http.Error(w, "invalid payload", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Body = io.NopCloser(&b)
|
||||||
|
next.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
253
vendor/code.gitea.io/sdk/gitea/httpsign.go
generated
vendored
Normal file
253
vendor/code.gitea.io/sdk/gitea/httpsign.go
generated
vendored
Normal file
@@ -0,0 +1,253 @@
|
|||||||
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto"
|
||||||
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-fed/httpsig"
|
||||||
|
"golang.org/x/crypto/ssh"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HTTPSign contains the signer used for signing requests
|
||||||
|
type HTTPSign struct {
|
||||||
|
ssh.Signer
|
||||||
|
cert bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTPSignConfig contains the configuration for creating a HTTPSign
|
||||||
|
type HTTPSignConfig struct {
|
||||||
|
fingerprint string
|
||||||
|
principal string
|
||||||
|
pubkey bool
|
||||||
|
cert bool
|
||||||
|
sshKey string
|
||||||
|
passphrase string
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewHTTPSignWithPubkey can be used to create a HTTPSign with a public key
|
||||||
|
// if no fingerprint is specified it returns the first public key found
|
||||||
|
func NewHTTPSignWithPubkey(fingerprint, sshKey, passphrase string) (*HTTPSign, error) {
|
||||||
|
return newHTTPSign(&HTTPSignConfig{
|
||||||
|
fingerprint: fingerprint,
|
||||||
|
pubkey: true,
|
||||||
|
sshKey: sshKey,
|
||||||
|
passphrase: passphrase,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewHTTPSignWithCert can be used to create a HTTPSign with a certificate
|
||||||
|
// if no principal is specified it returns the first certificate found
|
||||||
|
func NewHTTPSignWithCert(principal, sshKey, passphrase string) (*HTTPSign, error) {
|
||||||
|
return newHTTPSign(&HTTPSignConfig{
|
||||||
|
principal: principal,
|
||||||
|
cert: true,
|
||||||
|
sshKey: sshKey,
|
||||||
|
passphrase: passphrase,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewHTTPSign returns a new HTTPSign
|
||||||
|
// It will check the ssh-agent or a local file is config.sshKey is set.
|
||||||
|
// Depending on the configuration it will either use a certificate or a public key
|
||||||
|
func newHTTPSign(config *HTTPSignConfig) (*HTTPSign, error) {
|
||||||
|
var signer ssh.Signer
|
||||||
|
|
||||||
|
if config.sshKey != "" {
|
||||||
|
priv, err := os.ReadFile(config.sshKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.passphrase == "" {
|
||||||
|
signer, err = ssh.ParsePrivateKey(priv)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
signer, err = ssh.ParsePrivateKeyWithPassphrase(priv, []byte(config.passphrase))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.cert {
|
||||||
|
certbytes, err := os.ReadFile(config.sshKey + "-cert.pub")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
pub, _, _, _, err := ssh.ParseAuthorizedKey(certbytes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
cert, ok := pub.(*ssh.Certificate)
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("failed to parse certificate")
|
||||||
|
}
|
||||||
|
|
||||||
|
signer, err = ssh.NewCertSigner(cert, signer)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if no sshKey is specified, check if we have a ssh-agent and use it
|
||||||
|
agent, err := GetAgent()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
signers, err := agent.Signers()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(signers) == 0 {
|
||||||
|
return nil, fmt.Errorf("no signers found")
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.cert {
|
||||||
|
signer = findCertSigner(signers, config.principal)
|
||||||
|
if signer == nil {
|
||||||
|
return nil, fmt.Errorf("no certificate found for %s", config.principal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.pubkey {
|
||||||
|
signer = findPubkeySigner(signers, config.fingerprint)
|
||||||
|
if signer == nil {
|
||||||
|
return nil, fmt.Errorf("no public key found for %s", config.fingerprint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &HTTPSign{
|
||||||
|
Signer: signer,
|
||||||
|
cert: config.cert,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SignRequest signs a HTTP request
|
||||||
|
func (c *Client) SignRequest(r *http.Request) error {
|
||||||
|
var contents []byte
|
||||||
|
|
||||||
|
headersToSign := []string{httpsig.RequestTarget, "(created)", "(expires)"}
|
||||||
|
|
||||||
|
if c.httpsigner.cert {
|
||||||
|
// add our certificate to the headers to sign
|
||||||
|
pubkey, _ := ssh.ParsePublicKey(c.httpsigner.Signer.PublicKey().Marshal())
|
||||||
|
if cert, ok := pubkey.(*ssh.Certificate); ok {
|
||||||
|
certString := base64.RawStdEncoding.EncodeToString(cert.Marshal())
|
||||||
|
r.Header.Add("x-ssh-certificate", certString)
|
||||||
|
|
||||||
|
headersToSign = append(headersToSign, "x-ssh-certificate")
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("no ssh certificate found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we have a body, the Digest header will be added and we'll include this also in
|
||||||
|
// our signature.
|
||||||
|
if r.Body != nil {
|
||||||
|
body, err := r.GetBody()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("getBody() failed: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
contents, err = io.ReadAll(body)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed reading body: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
headersToSign = append(headersToSign, "Digest")
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a signer for the request and headers, the signature will be valid for 10 seconds
|
||||||
|
signer, _, err := httpsig.NewSSHSigner(c.httpsigner.Signer, httpsig.DigestSha512, headersToSign, httpsig.Signature, 10)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("httpsig.NewSSHSigner failed: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// sign the request, use the fingerprint if we don't have a certificate
|
||||||
|
keyID := "gitea"
|
||||||
|
if !c.httpsigner.cert {
|
||||||
|
keyID = ssh.FingerprintSHA256(c.httpsigner.Signer.PublicKey())
|
||||||
|
}
|
||||||
|
|
||||||
|
err = signer.SignRequest(keyID, r, contents)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("httpsig.Signrequest failed: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// findCertSigner returns the Signer containing a valid certificate
|
||||||
|
// if no principal is specified it returns the first certificate found
|
||||||
|
func findCertSigner(sshsigners []ssh.Signer, principal string) ssh.Signer {
|
||||||
|
for _, s := range sshsigners {
|
||||||
|
// Check if the key is a certificate
|
||||||
|
if !strings.Contains(s.PublicKey().Type(), "cert-v01@openssh.com") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert the ssh.Signer to a ssh.Certificate
|
||||||
|
mpubkey, _ := ssh.ParsePublicKey(s.PublicKey().Marshal())
|
||||||
|
cryptopub := mpubkey.(crypto.PublicKey)
|
||||||
|
cert := cryptopub.(*ssh.Certificate)
|
||||||
|
t := time.Unix(int64(cert.ValidBefore), 0)
|
||||||
|
|
||||||
|
// make sure the certificate is at least 10 seconds valid
|
||||||
|
if time.Until(t) <= time.Second*10 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if principal == "" {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, p := range cert.ValidPrincipals {
|
||||||
|
if p == principal {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// findPubkeySigner returns the Signer containing a valid public key
|
||||||
|
// if no fingerprint is specified it returns the first public key found
|
||||||
|
func findPubkeySigner(sshsigners []ssh.Signer, fingerprint string) ssh.Signer {
|
||||||
|
for _, s := range sshsigners {
|
||||||
|
// Check if the key is a certificate
|
||||||
|
if strings.Contains(s.PublicKey().Type(), "cert-v01@openssh.com") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if fingerprint == "" {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.TrimSpace(string(ssh.MarshalAuthorizedKey(s.PublicKey()))) == fingerprint {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
if ssh.FingerprintSHA256(s.PublicKey()) == fingerprint {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
309
vendor/code.gitea.io/sdk/gitea/issue.go
generated
vendored
Normal file
309
vendor/code.gitea.io/sdk/gitea/issue.go
generated
vendored
Normal file
@@ -0,0 +1,309 @@
|
|||||||
|
// Copyright 2016 The Gogs Authors. All rights reserved.
|
||||||
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PullRequestMeta PR info if an issue is a PR
|
||||||
|
type PullRequestMeta struct {
|
||||||
|
HasMerged bool `json:"merged"`
|
||||||
|
Merged *time.Time `json:"merged_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// RepositoryMeta basic repository information
|
||||||
|
type RepositoryMeta struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Owner string `json:"owner"`
|
||||||
|
FullName string `json:"full_name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Issue represents an issue in a repository
|
||||||
|
type Issue struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
HTMLURL string `json:"html_url"`
|
||||||
|
Index int64 `json:"number"`
|
||||||
|
Poster *User `json:"user"`
|
||||||
|
OriginalAuthor string `json:"original_author"`
|
||||||
|
OriginalAuthorID int64 `json:"original_author_id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Body string `json:"body"`
|
||||||
|
Ref string `json:"ref"`
|
||||||
|
Labels []*Label `json:"labels"`
|
||||||
|
Milestone *Milestone `json:"milestone"`
|
||||||
|
Assignees []*User `json:"assignees"`
|
||||||
|
// Whether the issue is open or closed
|
||||||
|
State StateType `json:"state"`
|
||||||
|
IsLocked bool `json:"is_locked"`
|
||||||
|
Comments int `json:"comments"`
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
Updated time.Time `json:"updated_at"`
|
||||||
|
Closed *time.Time `json:"closed_at"`
|
||||||
|
Deadline *time.Time `json:"due_date"`
|
||||||
|
PullRequest *PullRequestMeta `json:"pull_request"`
|
||||||
|
Repository *RepositoryMeta `json:"repository"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListIssueOption list issue options
|
||||||
|
type ListIssueOption struct {
|
||||||
|
ListOptions
|
||||||
|
State StateType
|
||||||
|
Type IssueType
|
||||||
|
Labels []string
|
||||||
|
Milestones []string
|
||||||
|
KeyWord string
|
||||||
|
Since time.Time
|
||||||
|
Before time.Time
|
||||||
|
// filter by created by username
|
||||||
|
CreatedBy string
|
||||||
|
// filter by assigned to username
|
||||||
|
AssignedBy string
|
||||||
|
// filter by username mentioned
|
||||||
|
MentionedBy string
|
||||||
|
// filter by owner (only works on ListIssues on User)
|
||||||
|
Owner string
|
||||||
|
// filter by team (requires organization owner parameter to be provided and only works on ListIssues on User)
|
||||||
|
Team string
|
||||||
|
}
|
||||||
|
|
||||||
|
// StateType issue state type
|
||||||
|
type StateType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// StateOpen pr/issue is opend
|
||||||
|
StateOpen StateType = "open"
|
||||||
|
// StateClosed pr/issue is closed
|
||||||
|
StateClosed StateType = "closed"
|
||||||
|
// StateAll is all
|
||||||
|
StateAll StateType = "all"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IssueType is issue a pull or only an issue
|
||||||
|
type IssueType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// IssueTypeAll pr and issue
|
||||||
|
IssueTypeAll IssueType = ""
|
||||||
|
// IssueTypeIssue only issues
|
||||||
|
IssueTypeIssue IssueType = "issues"
|
||||||
|
// IssueTypePull only pulls
|
||||||
|
IssueTypePull IssueType = "pulls"
|
||||||
|
)
|
||||||
|
|
||||||
|
// QueryEncode turns options into querystring argument
|
||||||
|
func (opt *ListIssueOption) QueryEncode() string {
|
||||||
|
query := opt.getURLQuery()
|
||||||
|
|
||||||
|
if len(opt.State) > 0 {
|
||||||
|
query.Add("state", string(opt.State))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(opt.Labels) > 0 {
|
||||||
|
query.Add("labels", strings.Join(opt.Labels, ","))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(opt.KeyWord) > 0 {
|
||||||
|
query.Add("q", opt.KeyWord)
|
||||||
|
}
|
||||||
|
|
||||||
|
query.Add("type", string(opt.Type))
|
||||||
|
|
||||||
|
if len(opt.Milestones) > 0 {
|
||||||
|
query.Add("milestones", strings.Join(opt.Milestones, ","))
|
||||||
|
}
|
||||||
|
|
||||||
|
if !opt.Since.IsZero() {
|
||||||
|
query.Add("since", opt.Since.Format(time.RFC3339))
|
||||||
|
}
|
||||||
|
if !opt.Before.IsZero() {
|
||||||
|
query.Add("before", opt.Before.Format(time.RFC3339))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(opt.CreatedBy) > 0 {
|
||||||
|
query.Add("created_by", opt.CreatedBy)
|
||||||
|
}
|
||||||
|
if len(opt.AssignedBy) > 0 {
|
||||||
|
query.Add("assigned_by", opt.AssignedBy)
|
||||||
|
}
|
||||||
|
if len(opt.MentionedBy) > 0 {
|
||||||
|
query.Add("mentioned_by", opt.MentionedBy)
|
||||||
|
}
|
||||||
|
if len(opt.Owner) > 0 {
|
||||||
|
query.Add("owner", opt.Owner)
|
||||||
|
}
|
||||||
|
if len(opt.Team) > 0 {
|
||||||
|
query.Add("team", opt.MentionedBy)
|
||||||
|
}
|
||||||
|
|
||||||
|
return query.Encode()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListIssues returns all issues assigned the authenticated user
|
||||||
|
func (c *Client) ListIssues(opt ListIssueOption) ([]*Issue, *Response, error) {
|
||||||
|
opt.setDefaults()
|
||||||
|
issues := make([]*Issue, 0, opt.PageSize)
|
||||||
|
|
||||||
|
link, _ := url.Parse("/repos/issues/search")
|
||||||
|
link.RawQuery = opt.QueryEncode()
|
||||||
|
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &issues)
|
||||||
|
if e := c.checkServerVersionGreaterThanOrEqual(version1_12_0); e != nil {
|
||||||
|
for i := 0; i < len(issues); i++ {
|
||||||
|
if issues[i].Repository != nil {
|
||||||
|
issues[i].Repository.Owner = strings.Split(issues[i].Repository.FullName, "/")[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := range issues {
|
||||||
|
c.issueBackwardsCompatibility(issues[i])
|
||||||
|
}
|
||||||
|
return issues, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepoIssues returns all issues for a given repository
|
||||||
|
func (c *Client) ListRepoIssues(owner, repo string, opt ListIssueOption) ([]*Issue, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
opt.setDefaults()
|
||||||
|
issues := make([]*Issue, 0, opt.PageSize)
|
||||||
|
|
||||||
|
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/issues", owner, repo))
|
||||||
|
link.RawQuery = opt.QueryEncode()
|
||||||
|
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, &issues)
|
||||||
|
if e := c.checkServerVersionGreaterThanOrEqual(version1_12_0); e != nil {
|
||||||
|
for i := 0; i < len(issues); i++ {
|
||||||
|
if issues[i].Repository != nil {
|
||||||
|
issues[i].Repository.Owner = strings.Split(issues[i].Repository.FullName, "/")[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i := range issues {
|
||||||
|
c.issueBackwardsCompatibility(issues[i])
|
||||||
|
}
|
||||||
|
return issues, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetIssue returns a single issue for a given repository
|
||||||
|
func (c *Client) GetIssue(owner, repo string, index int64) (*Issue, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
issue := new(Issue)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index), nil, nil, issue)
|
||||||
|
if e := c.checkServerVersionGreaterThanOrEqual(version1_12_0); e != nil && issue.Repository != nil {
|
||||||
|
issue.Repository.Owner = strings.Split(issue.Repository.FullName, "/")[0]
|
||||||
|
}
|
||||||
|
c.issueBackwardsCompatibility(issue)
|
||||||
|
return issue, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateIssueOption options to create one issue
|
||||||
|
type CreateIssueOption struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Body string `json:"body"`
|
||||||
|
Ref string `json:"ref"`
|
||||||
|
Assignees []string `json:"assignees"`
|
||||||
|
Deadline *time.Time `json:"due_date"`
|
||||||
|
// milestone id
|
||||||
|
Milestone int64 `json:"milestone"`
|
||||||
|
// list of label ids
|
||||||
|
Labels []int64 `json:"labels"`
|
||||||
|
Closed bool `json:"closed"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the CreateIssueOption struct
|
||||||
|
func (opt CreateIssueOption) Validate() error {
|
||||||
|
if len(strings.TrimSpace(opt.Title)) == 0 {
|
||||||
|
return fmt.Errorf("title is empty")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateIssue create a new issue for a given repository
|
||||||
|
func (c *Client) CreateIssue(owner, repo string, opt CreateIssueOption) (*Issue, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if err := opt.Validate(); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
issue := new(Issue)
|
||||||
|
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues", owner, repo),
|
||||||
|
jsonHeader, bytes.NewReader(body), issue)
|
||||||
|
c.issueBackwardsCompatibility(issue)
|
||||||
|
return issue, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditIssueOption options for editing an issue
|
||||||
|
type EditIssueOption struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Body *string `json:"body"`
|
||||||
|
Ref *string `json:"ref"`
|
||||||
|
Assignees []string `json:"assignees"`
|
||||||
|
Milestone *int64 `json:"milestone"`
|
||||||
|
State *StateType `json:"state"`
|
||||||
|
Deadline *time.Time `json:"due_date"`
|
||||||
|
RemoveDeadline *bool `json:"unset_due_date"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the EditIssueOption struct
|
||||||
|
func (opt EditIssueOption) Validate() error {
|
||||||
|
if len(opt.Title) != 0 && len(strings.TrimSpace(opt.Title)) == 0 {
|
||||||
|
return fmt.Errorf("title is empty")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditIssue modify an existing issue for a given repository
|
||||||
|
func (c *Client) EditIssue(owner, repo string, index int64, opt EditIssueOption) (*Issue, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if err := opt.Validate(); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
issue := new(Issue)
|
||||||
|
resp, err := c.getParsedResponse("PATCH",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/issues/%d", owner, repo, index),
|
||||||
|
jsonHeader, bytes.NewReader(body), issue)
|
||||||
|
c.issueBackwardsCompatibility(issue)
|
||||||
|
return issue, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteIssue delete a issue from a repository
|
||||||
|
func (c *Client) DeleteIssue(user, repo string, id int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&user, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/issues/%d", user, repo, id),
|
||||||
|
nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) issueBackwardsCompatibility(issue *Issue) {
|
||||||
|
if c.checkServerVersionGreaterThanOrEqual(version1_12_0) != nil {
|
||||||
|
c.mutex.RLock()
|
||||||
|
issue.HTMLURL = fmt.Sprintf("%s/%s/issues/%d", c.url, issue.Repository.FullName, issue.Index)
|
||||||
|
c.mutex.RUnlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
154
vendor/code.gitea.io/sdk/gitea/issue_comment.go
generated
vendored
Normal file
154
vendor/code.gitea.io/sdk/gitea/issue_comment.go
generated
vendored
Normal file
@@ -0,0 +1,154 @@
|
|||||||
|
// Copyright 2016 The Gogs Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Comment represents a comment on a commit or issue
|
||||||
|
type Comment struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
HTMLURL string `json:"html_url"`
|
||||||
|
PRURL string `json:"pull_request_url"`
|
||||||
|
IssueURL string `json:"issue_url"`
|
||||||
|
Poster *User `json:"user"`
|
||||||
|
OriginalAuthor string `json:"original_author"`
|
||||||
|
OriginalAuthorID int64 `json:"original_author_id"`
|
||||||
|
Body string `json:"body"`
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
Updated time.Time `json:"updated_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListIssueCommentOptions list comment options
|
||||||
|
type ListIssueCommentOptions struct {
|
||||||
|
ListOptions
|
||||||
|
Since time.Time
|
||||||
|
Before time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryEncode turns options into querystring argument
|
||||||
|
func (opt *ListIssueCommentOptions) QueryEncode() string {
|
||||||
|
query := opt.getURLQuery()
|
||||||
|
if !opt.Since.IsZero() {
|
||||||
|
query.Add("since", opt.Since.Format(time.RFC3339))
|
||||||
|
}
|
||||||
|
if !opt.Before.IsZero() {
|
||||||
|
query.Add("before", opt.Before.Format(time.RFC3339))
|
||||||
|
}
|
||||||
|
return query.Encode()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListIssueComments list comments on an issue.
|
||||||
|
func (c *Client) ListIssueComments(owner, repo string, index int64, opt ListIssueCommentOptions) ([]*Comment, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
opt.setDefaults()
|
||||||
|
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index))
|
||||||
|
link.RawQuery = opt.QueryEncode()
|
||||||
|
comments := make([]*Comment, 0, opt.PageSize)
|
||||||
|
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &comments)
|
||||||
|
return comments, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepoIssueComments list comments for a given repo.
|
||||||
|
func (c *Client) ListRepoIssueComments(owner, repo string, opt ListIssueCommentOptions) ([]*Comment, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
opt.setDefaults()
|
||||||
|
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/issues/comments", owner, repo))
|
||||||
|
link.RawQuery = opt.QueryEncode()
|
||||||
|
comments := make([]*Comment, 0, opt.PageSize)
|
||||||
|
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &comments)
|
||||||
|
return comments, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetIssueComment get a comment for a given repo by id.
|
||||||
|
func (c *Client) GetIssueComment(owner, repo string, id int64) (*Comment, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
comment := new(Comment)
|
||||||
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != nil {
|
||||||
|
return comment, nil, err
|
||||||
|
}
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments/%d", owner, repo, id), nil, nil, &comment)
|
||||||
|
return comment, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateIssueCommentOption options for creating a comment on an issue
|
||||||
|
type CreateIssueCommentOption struct {
|
||||||
|
Body string `json:"body"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the CreateIssueCommentOption struct
|
||||||
|
func (opt CreateIssueCommentOption) Validate() error {
|
||||||
|
if len(opt.Body) == 0 {
|
||||||
|
return fmt.Errorf("body is empty")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateIssueComment create comment on an issue.
|
||||||
|
func (c *Client) CreateIssueComment(owner, repo string, index int64, opt CreateIssueCommentOption) (*Comment, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if err := opt.Validate(); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
comment := new(Comment)
|
||||||
|
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/comments", owner, repo, index), jsonHeader, bytes.NewReader(body), comment)
|
||||||
|
return comment, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditIssueCommentOption options for editing a comment
|
||||||
|
type EditIssueCommentOption struct {
|
||||||
|
Body string `json:"body"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the EditIssueCommentOption struct
|
||||||
|
func (opt EditIssueCommentOption) Validate() error {
|
||||||
|
if len(opt.Body) == 0 {
|
||||||
|
return fmt.Errorf("body is empty")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditIssueComment edits an issue comment.
|
||||||
|
func (c *Client) EditIssueComment(owner, repo string, commentID int64, opt EditIssueCommentOption) (*Comment, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if err := opt.Validate(); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
comment := new(Comment)
|
||||||
|
resp, err := c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/issues/comments/%d", owner, repo, commentID), jsonHeader, bytes.NewReader(body), comment)
|
||||||
|
return comment, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteIssueComment deletes an issue comment.
|
||||||
|
func (c *Client) DeleteIssueComment(owner, repo string, commentID int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/comments/%d", owner, repo, commentID), nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
211
vendor/code.gitea.io/sdk/gitea/issue_label.go
generated
vendored
Normal file
211
vendor/code.gitea.io/sdk/gitea/issue_label.go
generated
vendored
Normal file
@@ -0,0 +1,211 @@
|
|||||||
|
// Copyright 2016 The Gogs Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Label a label to an issue or a pr
|
||||||
|
type Label struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
// example: 00aabb
|
||||||
|
Color string `json:"color"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListLabelsOptions options for listing repository's labels
|
||||||
|
type ListLabelsOptions struct {
|
||||||
|
ListOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepoLabels list labels of one repository
|
||||||
|
func (c *Client) ListRepoLabels(owner, repo string, opt ListLabelsOptions) ([]*Label, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
opt.setDefaults()
|
||||||
|
labels := make([]*Label, 0, opt.PageSize)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels?%s", owner, repo, opt.getURLQuery().Encode()), nil, nil, &labels)
|
||||||
|
return labels, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetRepoLabel get one label of repository by repo it
|
||||||
|
func (c *Client) GetRepoLabel(owner, repo string, id int64) (*Label, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
label := new(Label)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil, label)
|
||||||
|
return label, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateLabelOption options for creating a label
|
||||||
|
type CreateLabelOption struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
// example: #00aabb
|
||||||
|
Color string `json:"color"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the CreateLabelOption struct
|
||||||
|
func (opt CreateLabelOption) Validate() error {
|
||||||
|
aw, err := regexp.MatchString("^#?[0-9,a-f,A-F]{6}$", opt.Color)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !aw {
|
||||||
|
return fmt.Errorf("invalid color format")
|
||||||
|
}
|
||||||
|
if len(strings.TrimSpace(opt.Name)) == 0 {
|
||||||
|
return fmt.Errorf("empty name not allowed")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateLabel create one label of repository
|
||||||
|
func (c *Client) CreateLabel(owner, repo string, opt CreateLabelOption) (*Label, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if err := opt.Validate(); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if len(opt.Color) == 6 {
|
||||||
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != nil {
|
||||||
|
opt.Color = "#" + opt.Color
|
||||||
|
}
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
label := new(Label)
|
||||||
|
resp, err := c.getParsedResponse("POST",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/labels", owner, repo),
|
||||||
|
jsonHeader, bytes.NewReader(body), label)
|
||||||
|
return label, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditLabelOption options for editing a label
|
||||||
|
type EditLabelOption struct {
|
||||||
|
Name *string `json:"name"`
|
||||||
|
Color *string `json:"color"`
|
||||||
|
Description *string `json:"description"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the EditLabelOption struct
|
||||||
|
func (opt EditLabelOption) Validate() error {
|
||||||
|
if opt.Color != nil {
|
||||||
|
aw, err := regexp.MatchString("^#?[0-9,a-f,A-F]{6}$", *opt.Color)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !aw {
|
||||||
|
return fmt.Errorf("invalid color format")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if opt.Name != nil {
|
||||||
|
if len(strings.TrimSpace(*opt.Name)) == 0 {
|
||||||
|
return fmt.Errorf("empty name not allowed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditLabel modify one label with options
|
||||||
|
func (c *Client) EditLabel(owner, repo string, id int64, opt EditLabelOption) (*Label, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if err := opt.Validate(); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
label := new(Label)
|
||||||
|
resp, err := c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), label)
|
||||||
|
return label, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteLabel delete one label of repository by id
|
||||||
|
func (c *Client) DeleteLabel(owner, repo string, id int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/labels/%d", owner, repo, id), nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetIssueLabels get labels of one issue via issue id
|
||||||
|
func (c *Client) GetIssueLabels(owner, repo string, index int64, opts ListLabelsOptions) ([]*Label, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
labels := make([]*Label, 0, 5)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/labels?%s", owner, repo, index, opts.getURLQuery().Encode()), nil, nil, &labels)
|
||||||
|
return labels, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueLabelsOption a collection of labels
|
||||||
|
type IssueLabelsOption struct {
|
||||||
|
// list of label IDs
|
||||||
|
Labels []int64 `json:"labels"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddIssueLabels add one or more labels to one issue
|
||||||
|
func (c *Client) AddIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
var labels []*Label
|
||||||
|
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
|
||||||
|
return labels, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ReplaceIssueLabels replace old labels of issue with new labels
|
||||||
|
func (c *Client) ReplaceIssueLabels(owner, repo string, index int64, opt IssueLabelsOption) ([]*Label, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
var labels []*Label
|
||||||
|
resp, err := c.getParsedResponse("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), jsonHeader, bytes.NewReader(body), &labels)
|
||||||
|
return labels, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteIssueLabel delete one label of one issue by issue id and label id
|
||||||
|
// TODO: maybe we need delete by label name and issue id
|
||||||
|
func (c *Client) DeleteIssueLabel(owner, repo string, index, label int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels/%d", owner, repo, index, label), nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ClearIssueLabels delete all the labels of one issue.
|
||||||
|
func (c *Client) ClearIssueLabels(owner, repo string, index int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/labels", owner, repo, index), nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
237
vendor/code.gitea.io/sdk/gitea/issue_milestone.go
generated
vendored
Normal file
237
vendor/code.gitea.io/sdk/gitea/issue_milestone.go
generated
vendored
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
// Copyright 2016 The Gogs Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Milestone milestone is a collection of issues on one repository
|
||||||
|
type Milestone struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
State StateType `json:"state"`
|
||||||
|
OpenIssues int `json:"open_issues"`
|
||||||
|
ClosedIssues int `json:"closed_issues"`
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
Updated *time.Time `json:"updated_at"`
|
||||||
|
Closed *time.Time `json:"closed_at"`
|
||||||
|
Deadline *time.Time `json:"due_on"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListMilestoneOption list milestone options
|
||||||
|
type ListMilestoneOption struct {
|
||||||
|
ListOptions
|
||||||
|
// open, closed, all
|
||||||
|
State StateType
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryEncode turns options into querystring argument
|
||||||
|
func (opt *ListMilestoneOption) QueryEncode() string {
|
||||||
|
query := opt.getURLQuery()
|
||||||
|
if opt.State != "" {
|
||||||
|
query.Add("state", string(opt.State))
|
||||||
|
}
|
||||||
|
if len(opt.Name) != 0 {
|
||||||
|
query.Add("name", opt.Name)
|
||||||
|
}
|
||||||
|
return query.Encode()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepoMilestones list all the milestones of one repository
|
||||||
|
func (c *Client) ListRepoMilestones(owner, repo string, opt ListMilestoneOption) ([]*Milestone, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
opt.setDefaults()
|
||||||
|
milestones := make([]*Milestone, 0, opt.PageSize)
|
||||||
|
|
||||||
|
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/milestones", owner, repo))
|
||||||
|
link.RawQuery = opt.QueryEncode()
|
||||||
|
resp, err := c.getParsedResponse("GET", link.String(), nil, nil, &milestones)
|
||||||
|
return milestones, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMilestone get one milestone by repo name and milestone id
|
||||||
|
func (c *Client) GetMilestone(owner, repo string, id int64) (*Milestone, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
milestone := new(Milestone)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil, milestone)
|
||||||
|
return milestone, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMilestoneByName get one milestone by repo and milestone name
|
||||||
|
func (c *Client) GetMilestoneByName(owner, repo, name string) (*Milestone, *Response, error) {
|
||||||
|
if c.checkServerVersionGreaterThanOrEqual(version1_13_0) != nil {
|
||||||
|
// backwards compatibility mode
|
||||||
|
m, resp, err := c.resolveMilestoneByName(owner, repo, name)
|
||||||
|
return m, resp, err
|
||||||
|
}
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo, &name); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
milestone := new(Milestone)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/milestones/%s", owner, repo, name), nil, nil, milestone)
|
||||||
|
return milestone, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateMilestoneOption options for creating a milestone
|
||||||
|
type CreateMilestoneOption struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
State StateType `json:"state"`
|
||||||
|
Deadline *time.Time `json:"due_on"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the CreateMilestoneOption struct
|
||||||
|
func (opt CreateMilestoneOption) Validate() error {
|
||||||
|
if len(strings.TrimSpace(opt.Title)) == 0 {
|
||||||
|
return fmt.Errorf("title is empty")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// CreateMilestone create one milestone with options
|
||||||
|
func (c *Client) CreateMilestone(owner, repo string, opt CreateMilestoneOption) (*Milestone, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if err := opt.Validate(); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
milestone := new(Milestone)
|
||||||
|
resp, err := c.getParsedResponse("POST", fmt.Sprintf("/repos/%s/%s/milestones", owner, repo), jsonHeader, bytes.NewReader(body), milestone)
|
||||||
|
|
||||||
|
// make creating closed milestones need gitea >= v1.13.0
|
||||||
|
// this make it backwards compatible
|
||||||
|
if err == nil && opt.State == StateClosed && milestone.State != StateClosed {
|
||||||
|
closed := StateClosed
|
||||||
|
return c.EditMilestone(owner, repo, milestone.ID, EditMilestoneOption{
|
||||||
|
State: &closed,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return milestone, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditMilestoneOption options for editing a milestone
|
||||||
|
type EditMilestoneOption struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Description *string `json:"description"`
|
||||||
|
State *StateType `json:"state"`
|
||||||
|
Deadline *time.Time `json:"due_on"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the EditMilestoneOption struct
|
||||||
|
func (opt EditMilestoneOption) Validate() error {
|
||||||
|
if len(opt.Title) != 0 && len(strings.TrimSpace(opt.Title)) == 0 {
|
||||||
|
return fmt.Errorf("title is empty")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditMilestone modify milestone with options
|
||||||
|
func (c *Client) EditMilestone(owner, repo string, id int64, opt EditMilestoneOption) (*Milestone, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if err := opt.Validate(); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
milestone := new(Milestone)
|
||||||
|
resp, err := c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), jsonHeader, bytes.NewReader(body), milestone)
|
||||||
|
return milestone, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// EditMilestoneByName modify milestone with options
|
||||||
|
func (c *Client) EditMilestoneByName(owner, repo, name string, opt EditMilestoneOption) (*Milestone, *Response, error) {
|
||||||
|
if c.checkServerVersionGreaterThanOrEqual(version1_13_0) != nil {
|
||||||
|
// backwards compatibility mode
|
||||||
|
m, _, err := c.resolveMilestoneByName(owner, repo, name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
return c.EditMilestone(owner, repo, m.ID, opt)
|
||||||
|
}
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo, &name); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if err := opt.Validate(); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
milestone := new(Milestone)
|
||||||
|
resp, err := c.getParsedResponse("PATCH", fmt.Sprintf("/repos/%s/%s/milestones/%s", owner, repo, name), jsonHeader, bytes.NewReader(body), milestone)
|
||||||
|
return milestone, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteMilestone delete one milestone by id
|
||||||
|
func (c *Client) DeleteMilestone(owner, repo string, id int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/milestones/%d", owner, repo, id), nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteMilestoneByName delete one milestone by name
|
||||||
|
func (c *Client) DeleteMilestoneByName(owner, repo, name string) (*Response, error) {
|
||||||
|
if c.checkServerVersionGreaterThanOrEqual(version1_13_0) != nil {
|
||||||
|
// backwards compatibility mode
|
||||||
|
m, _, err := c.resolveMilestoneByName(owner, repo, name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return c.DeleteMilestone(owner, repo, m.ID)
|
||||||
|
}
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo, &name); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/milestones/%s", owner, repo, name), nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// resolveMilestoneByName is a fallback method to find milestone id by name
|
||||||
|
func (c *Client) resolveMilestoneByName(owner, repo, name string) (*Milestone, *Response, error) {
|
||||||
|
for i := 1; ; i++ {
|
||||||
|
miles, resp, err := c.ListRepoMilestones(owner, repo, ListMilestoneOption{
|
||||||
|
ListOptions: ListOptions{
|
||||||
|
Page: i,
|
||||||
|
},
|
||||||
|
State: "all",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if len(miles) == 0 {
|
||||||
|
return nil, nil, fmt.Errorf("milestone '%s' do not exist", name)
|
||||||
|
}
|
||||||
|
for _, m := range miles {
|
||||||
|
if strings.EqualFold(strings.TrimSpace(m.Title), strings.TrimSpace(name)) {
|
||||||
|
return m, resp, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
104
vendor/code.gitea.io/sdk/gitea/issue_reaction.go
generated
vendored
Normal file
104
vendor/code.gitea.io/sdk/gitea/issue_reaction.go
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Reaction contain one reaction
|
||||||
|
type Reaction struct {
|
||||||
|
User *User `json:"user"`
|
||||||
|
Reaction string `json:"content"`
|
||||||
|
Created time.Time `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetIssueReactions get a list reactions of an issue
|
||||||
|
func (c *Client) GetIssueReactions(owner, repo string, index int64) ([]*Reaction, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
reactions := make([]*Reaction, 0, 10)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/reactions", owner, repo, index), nil, nil, &reactions)
|
||||||
|
return reactions, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetIssueCommentReactions get a list of reactions from a comment of an issue
|
||||||
|
func (c *Client) GetIssueCommentReactions(owner, repo string, commentID int64) ([]*Reaction, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
reactions := make([]*Reaction, 0, 10)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/comments/%d/reactions", owner, repo, commentID), nil, nil, &reactions)
|
||||||
|
return reactions, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// editReactionOption contain the reaction type
|
||||||
|
type editReactionOption struct {
|
||||||
|
Reaction string `json:"content"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostIssueReaction add a reaction to an issue
|
||||||
|
func (c *Client) PostIssueReaction(owner, repo string, index int64, reaction string) (*Reaction, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
reactionResponse := new(Reaction)
|
||||||
|
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
resp, err := c.getParsedResponse("POST",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/issues/%d/reactions", owner, repo, index),
|
||||||
|
jsonHeader, bytes.NewReader(body), reactionResponse)
|
||||||
|
return reactionResponse, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteIssueReaction remove a reaction from an issue
|
||||||
|
func (c *Client) DeleteIssueReaction(owner, repo string, index int64, reaction string) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/reactions", owner, repo, index), jsonHeader, bytes.NewReader(body))
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostIssueCommentReaction add a reaction to a comment of an issue
|
||||||
|
func (c *Client) PostIssueCommentReaction(owner, repo string, commentID int64, reaction string) (*Reaction, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
reactionResponse := new(Reaction)
|
||||||
|
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
resp, err := c.getParsedResponse("POST",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/issues/comments/%d/reactions", owner, repo, commentID),
|
||||||
|
jsonHeader, bytes.NewReader(body), reactionResponse)
|
||||||
|
return reactionResponse, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteIssueCommentReaction remove a reaction from a comment of an issue
|
||||||
|
func (c *Client) DeleteIssueCommentReaction(owner, repo string, commentID int64, reaction string) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&editReactionOption{Reaction: reaction})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/issues/comments/%d/reactions", owner, repo, commentID),
|
||||||
|
jsonHeader, bytes.NewReader(body))
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
57
vendor/code.gitea.io/sdk/gitea/issue_stopwatch.go
generated
vendored
Normal file
57
vendor/code.gitea.io/sdk/gitea/issue_stopwatch.go
generated
vendored
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// StopWatch represents a running stopwatch of an issue / pr
|
||||||
|
type StopWatch struct {
|
||||||
|
Created time.Time `json:"created"`
|
||||||
|
Seconds int64 `json:"seconds"`
|
||||||
|
Duration string `json:"duration"`
|
||||||
|
IssueIndex int64 `json:"issue_index"`
|
||||||
|
IssueTitle string `json:"issue_title"`
|
||||||
|
RepoOwnerName string `json:"repo_owner_name"`
|
||||||
|
RepoName string `json:"repo_name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMyStopwatches list all stopwatches
|
||||||
|
func (c *Client) GetMyStopwatches() ([]*StopWatch, *Response, error) {
|
||||||
|
stopwatches := make([]*StopWatch, 0, 1)
|
||||||
|
resp, err := c.getParsedResponse("GET", "/user/stopwatches", nil, nil, &stopwatches)
|
||||||
|
return stopwatches, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteIssueStopwatch delete / cancel a specific stopwatch
|
||||||
|
func (c *Client) DeleteIssueStopwatch(owner, repo string, index int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/stopwatch/delete", owner, repo, index), nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// StartIssueStopWatch starts a stopwatch for an existing issue for a given
|
||||||
|
// repository
|
||||||
|
func (c *Client) StartIssueStopWatch(owner, repo string, index int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/stopwatch/start", owner, repo, index), nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// StopIssueStopWatch stops an existing stopwatch for an issue in a given
|
||||||
|
// repository
|
||||||
|
func (c *Client) StopIssueStopWatch(owner, repo string, index int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("POST", fmt.Sprintf("/repos/%s/%s/issues/%d/stopwatch/stop", owner, repo, index), nil, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
87
vendor/code.gitea.io/sdk/gitea/issue_subscription.go
generated
vendored
Normal file
87
vendor/code.gitea.io/sdk/gitea/issue_subscription.go
generated
vendored
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetIssueSubscribers get list of users who subscribed on an issue
|
||||||
|
func (c *Client) GetIssueSubscribers(owner, repo string, index int64) ([]*User, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
subscribers := make([]*User, 0, 10)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions", owner, repo, index), nil, nil, &subscribers)
|
||||||
|
return subscribers, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddIssueSubscription Subscribe user to issue
|
||||||
|
func (c *Client) AddIssueSubscription(owner, repo string, index int64, user string) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo, &user); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
status, resp, err := c.getStatusCode("PUT", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions/%s", owner, repo, index, user), nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
if status == http.StatusCreated {
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
if status == http.StatusOK {
|
||||||
|
return resp, fmt.Errorf("already subscribed")
|
||||||
|
}
|
||||||
|
return resp, fmt.Errorf("unexpected Status: %d", status)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteIssueSubscription unsubscribe user from issue
|
||||||
|
func (c *Client) DeleteIssueSubscription(owner, repo string, index int64, user string) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo, &user); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
status, resp, err := c.getStatusCode("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions/%s", owner, repo, index, user), nil, nil)
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
if status == http.StatusCreated {
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
if status == http.StatusOK {
|
||||||
|
return resp, fmt.Errorf("already unsubscribed")
|
||||||
|
}
|
||||||
|
return resp, fmt.Errorf("unexpected Status: %d", status)
|
||||||
|
}
|
||||||
|
|
||||||
|
// CheckIssueSubscription check if current user is subscribed to an issue
|
||||||
|
func (c *Client) CheckIssueSubscription(owner, repo string, index int64) (*WatchInfo, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if err := c.checkServerVersionGreaterThanOrEqual(version1_12_0); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
wi := new(WatchInfo)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issues/%d/subscriptions/check", owner, repo, index), nil, nil, wi)
|
||||||
|
return wi, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueSubscribe subscribe current user to an issue
|
||||||
|
func (c *Client) IssueSubscribe(owner, repo string, index int64) (*Response, error) {
|
||||||
|
u, _, err := c.GetMyUserInfo()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return c.AddIssueSubscription(owner, repo, index, u.UserName)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueUnSubscribe unsubscribe current user from an issue
|
||||||
|
func (c *Client) IssueUnSubscribe(owner, repo string, index int64) (*Response, error) {
|
||||||
|
u, _, err := c.GetMyUserInfo()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return c.DeleteIssueSubscription(owner, repo, index, u.UserName)
|
||||||
|
}
|
||||||
97
vendor/code.gitea.io/sdk/gitea/issue_template.go
generated
vendored
Normal file
97
vendor/code.gitea.io/sdk/gitea/issue_template.go
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// IssueTemplate provides metadata and content on an issue template.
|
||||||
|
// There are two types of issue templates: .Markdown- and .Form-based.
|
||||||
|
type IssueTemplate struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
About string `json:"about"`
|
||||||
|
Filename string `json:"file_name"`
|
||||||
|
IssueTitle string `json:"title"`
|
||||||
|
IssueLabels []string `json:"labels"`
|
||||||
|
IssueRef string `json:"ref"`
|
||||||
|
// If non-nil, this is a form-based template
|
||||||
|
Form []IssueFormElement `json:"body"`
|
||||||
|
// Should only be used when .Form is nil.
|
||||||
|
MarkdownContent string `json:"content"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueFormElement describes a part of a IssueTemplate form
|
||||||
|
type IssueFormElement struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
Type IssueFormElementType `json:"type"`
|
||||||
|
Attributes IssueFormElementAttributes `json:"attributes"`
|
||||||
|
Validations IssueFormElementValidations `json:"validations"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueFormElementAttributes contains the combined set of attributes available on all element types.
|
||||||
|
type IssueFormElementAttributes struct {
|
||||||
|
// required for all element types.
|
||||||
|
// A brief description of the expected user input, which is also displayed in the form.
|
||||||
|
Label string `json:"label"`
|
||||||
|
// required for element types "dropdown", "checkboxes"
|
||||||
|
// for dropdown, contains the available options
|
||||||
|
Options []string `json:"options"`
|
||||||
|
// for element types "markdown", "textarea", "input"
|
||||||
|
// Text that is pre-filled in the input
|
||||||
|
Value string `json:"value"`
|
||||||
|
// for element types "textarea", "input", "dropdown", "checkboxes"
|
||||||
|
// A description of the text area to provide context or guidance, which is displayed in the form.
|
||||||
|
Description string `json:"description"`
|
||||||
|
// for element types "textarea", "input"
|
||||||
|
// A semi-opaque placeholder that renders in the text area when empty.
|
||||||
|
Placeholder string `json:"placeholder"`
|
||||||
|
// for element types "textarea"
|
||||||
|
// A language specifier. If set, the input is rendered as codeblock with syntax highlighting.
|
||||||
|
SyntaxHighlighting string `json:"render"`
|
||||||
|
// for element types "dropdown"
|
||||||
|
Multiple bool `json:"multiple"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueFormElementValidations contains the combined set of validations available on all element types.
|
||||||
|
type IssueFormElementValidations struct {
|
||||||
|
// for all element types
|
||||||
|
Required bool `json:"required"`
|
||||||
|
// for element types "input"
|
||||||
|
IsNumber bool `json:"is_number"`
|
||||||
|
// for element types "input"
|
||||||
|
Regex string `json:"regex"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// IssueFormElementType is an enum
|
||||||
|
type IssueFormElementType string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// IssueFormElementMarkdown is markdown rendered to the form for context, but omitted in the resulting issue
|
||||||
|
IssueFormElementMarkdown IssueFormElementType = "markdown"
|
||||||
|
// IssueFormElementTextarea is a multi line input
|
||||||
|
IssueFormElementTextarea IssueFormElementType = "textarea"
|
||||||
|
// IssueFormElementInput is a single line input
|
||||||
|
IssueFormElementInput IssueFormElementType = "input"
|
||||||
|
// IssueFormElementDropdown is a select form
|
||||||
|
IssueFormElementDropdown IssueFormElementType = "dropdown"
|
||||||
|
// IssueFormElementCheckboxes are a multi checkbox input
|
||||||
|
IssueFormElementCheckboxes IssueFormElementType = "checkboxes"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetIssueTemplates lists all issue templates of the repository
|
||||||
|
func (c *Client) GetIssueTemplates(owner, repo string) ([]*IssueTemplate, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
templates := new([]*IssueTemplate)
|
||||||
|
resp, err := c.getParsedResponse("GET", fmt.Sprintf("/repos/%s/%s/issue_templates", owner, repo), nil, nil, templates)
|
||||||
|
return *templates, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsForm tells if this template is a form instead of a markdown-based template.
|
||||||
|
func (t IssueTemplate) IsForm() bool {
|
||||||
|
return t.Form != nil
|
||||||
|
}
|
||||||
142
vendor/code.gitea.io/sdk/gitea/issue_tracked_time.go
generated
vendored
Normal file
142
vendor/code.gitea.io/sdk/gitea/issue_tracked_time.go
generated
vendored
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TrackedTime worked time for an issue / pr
|
||||||
|
type TrackedTime struct {
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
Created time.Time `json:"created"`
|
||||||
|
// Time in seconds
|
||||||
|
Time int64 `json:"time"`
|
||||||
|
// deprecated (only for backwards compatibility)
|
||||||
|
UserID int64 `json:"user_id"`
|
||||||
|
UserName string `json:"user_name"`
|
||||||
|
// deprecated (only for backwards compatibility)
|
||||||
|
IssueID int64 `json:"issue_id"`
|
||||||
|
Issue *Issue `json:"issue"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListTrackedTimesOptions options for listing repository's tracked times
|
||||||
|
type ListTrackedTimesOptions struct {
|
||||||
|
ListOptions
|
||||||
|
Since time.Time
|
||||||
|
Before time.Time
|
||||||
|
// User filter is only used by ListRepoTrackedTimes !!!
|
||||||
|
User string
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryEncode turns options into querystring argument
|
||||||
|
func (opt *ListTrackedTimesOptions) QueryEncode() string {
|
||||||
|
query := opt.getURLQuery()
|
||||||
|
|
||||||
|
if !opt.Since.IsZero() {
|
||||||
|
query.Add("since", opt.Since.Format(time.RFC3339))
|
||||||
|
}
|
||||||
|
if !opt.Before.IsZero() {
|
||||||
|
query.Add("before", opt.Before.Format(time.RFC3339))
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(opt.User) != 0 {
|
||||||
|
query.Add("user", opt.User)
|
||||||
|
}
|
||||||
|
|
||||||
|
return query.Encode()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListRepoTrackedTimes list tracked times of a repository
|
||||||
|
func (c *Client) ListRepoTrackedTimes(owner, repo string, opt ListTrackedTimesOptions) ([]*TrackedTime, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/times", owner, repo))
|
||||||
|
opt.setDefaults()
|
||||||
|
link.RawQuery = opt.QueryEncode()
|
||||||
|
times := make([]*TrackedTime, 0, opt.PageSize)
|
||||||
|
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, ×)
|
||||||
|
return times, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMyTrackedTimes list tracked times of the current user
|
||||||
|
func (c *Client) GetMyTrackedTimes() ([]*TrackedTime, *Response, error) {
|
||||||
|
times := make([]*TrackedTime, 0, 10)
|
||||||
|
resp, err := c.getParsedResponse("GET", "/user/times", jsonHeader, nil, ×)
|
||||||
|
return times, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddTimeOption options for adding time to an issue
|
||||||
|
type AddTimeOption struct {
|
||||||
|
// time in seconds
|
||||||
|
Time int64 `json:"time"`
|
||||||
|
// optional
|
||||||
|
Created time.Time `json:"created"`
|
||||||
|
// optional
|
||||||
|
User string `json:"user_name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the AddTimeOption struct
|
||||||
|
func (opt AddTimeOption) Validate() error {
|
||||||
|
if opt.Time == 0 {
|
||||||
|
return fmt.Errorf("no time to add")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddTime adds time to issue with the given index
|
||||||
|
func (c *Client) AddTime(owner, repo string, index int64, opt AddTimeOption) (*TrackedTime, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
if err := opt.Validate(); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
body, err := json.Marshal(&opt)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
t := new(TrackedTime)
|
||||||
|
resp, err := c.getParsedResponse("POST",
|
||||||
|
fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index),
|
||||||
|
jsonHeader, bytes.NewReader(body), t)
|
||||||
|
return t, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ListIssueTrackedTimes list tracked times of a single issue for a given repository
|
||||||
|
func (c *Client) ListIssueTrackedTimes(owner, repo string, index int64, opt ListTrackedTimesOptions) ([]*TrackedTime, *Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
link, _ := url.Parse(fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index))
|
||||||
|
opt.setDefaults()
|
||||||
|
link.RawQuery = opt.QueryEncode()
|
||||||
|
times := make([]*TrackedTime, 0, opt.PageSize)
|
||||||
|
resp, err := c.getParsedResponse("GET", link.String(), jsonHeader, nil, ×)
|
||||||
|
return times, resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetIssueTime reset tracked time of a single issue for a given repository
|
||||||
|
func (c *Client) ResetIssueTime(owner, repo string, index int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/times", owner, repo, index), jsonHeader, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DeleteTime delete a specific tracked time by id of a single issue for a given repository
|
||||||
|
func (c *Client) DeleteTime(owner, repo string, index, timeID int64) (*Response, error) {
|
||||||
|
if err := escapeValidatePathSegments(&owner, &repo); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, resp, err := c.getResponse("DELETE", fmt.Sprintf("/repos/%s/%s/issues/%d/times/%d", owner, repo, index, timeID), jsonHeader, nil)
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
40
vendor/code.gitea.io/sdk/gitea/list_options.go
generated
vendored
Normal file
40
vendor/code.gitea.io/sdk/gitea/list_options.go
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package gitea
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ListOptions options for using Gitea's API pagination
|
||||||
|
type ListOptions struct {
|
||||||
|
// Setting Page to -1 disables pagination on endpoints that support it.
|
||||||
|
// Page numbering starts at 1.
|
||||||
|
Page int
|
||||||
|
// The default value depends on the server config DEFAULT_PAGING_NUM
|
||||||
|
// The highest valid value depends on the server config MAX_RESPONSE_ITEMS
|
||||||
|
PageSize int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o ListOptions) getURLQuery() url.Values {
|
||||||
|
query := make(url.Values)
|
||||||
|
query.Add("page", fmt.Sprintf("%d", o.Page))
|
||||||
|
query.Add("limit", fmt.Sprintf("%d", o.PageSize))
|
||||||
|
|
||||||
|
return query
|
||||||
|
}
|
||||||
|
|
||||||
|
// setDefaults applies default pagination options.
|
||||||
|
// If .Page is set to -1, it will disable pagination.
|
||||||
|
// WARNING: This function is not idempotent, make sure to never call this method twice!
|
||||||
|
func (o *ListOptions) setDefaults() {
|
||||||
|
if o.Page < 0 {
|
||||||
|
o.Page, o.PageSize = 0, 0
|
||||||
|
return
|
||||||
|
} else if o.Page == 0 {
|
||||||
|
o.Page = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user