Skip to content

Commit

Permalink
Strip redundant package name from automated use case name (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop authored Sep 8, 2021
1 parent 5c4080c commit fe22fff
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 25 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/cloc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This script is provided by github.com/bool64/dev.
name: cloc
on:
pull_request:
jobs:
cloc:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
path: pr
- name: Checkout base code
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.base.sha }}
path: base
- name: Count Lines Of Code
id: loc
run: |
curl -OL https://github.com/vearutop/sccdiff/releases/download/v1.0.1/linux_amd64.tar.gz && tar xf linux_amd64.tar.gz
OUTPUT=$(cd pr && ../sccdiff -basedir ../base)
OUTPUT="${OUTPUT//'%'/'%25'}"
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
echo "::set-output name=diff::$OUTPUT"
- name: Comment Code Lines
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: LOC
message: |
### Lines Of Code
${{ steps.loc.outputs.diff }}
5 changes: 3 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This script is provided by github.com/bool64/dev.
name: lint
on:
push:
Expand All @@ -14,10 +15,10 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/[email protected].1
uses: golangci/[email protected].2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.38.0
version: v1.41.1

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/gorelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This script is provided by github.com/bool64/dev.
name: gorelease
on:
pull_request:
env:
GO111MODULE: "on"
jobs:
gorelease:
strategy:
matrix:
go-version: [ 1.17.x ]
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Gorelease cache
uses: actions/cache@v2
with:
path: |
~/go/bin/gorelease
key: ${{ runner.os }}-gorelease
- name: Gorelease
id: gorelease
run: |
test -e ~/go/bin/gorelease || go install golang.org/x/exp/cmd/gorelease@latest
OUTPUT=$(gorelease || exit 0)
OUTPUT="${OUTPUT//'%'/'%25'}"
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
echo "::set-output name=report::$OUTPUT"
- name: Comment Report
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
header: gorelease
message: |
### API Changes
<pre>
${{ steps.gorelease.outputs.report }}
</pre>
16 changes: 8 additions & 8 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This script is provided by github.com/bool64/dev.
name: test-unit
on:
push:
Expand All @@ -12,7 +13,7 @@ jobs:
test:
strategy:
matrix:
go-version: [ 1.12.x, 1.13.x, 1.14.x, 1.15.x, 1.16.x ]
go-version: [ 1.13.x, 1.14.x, 1.15.x, 1.16.x, 1.17.x ]
runs-on: ubuntu-latest
steps:
- name: Install Go
Expand All @@ -34,25 +35,24 @@ jobs:
restore-keys: |
${{ runner.os }}-go-cache
- name: Restore base test coverage
if: matrix.go-version == '1.16.x'
if: matrix.go-version == '1.17.x'
uses: actions/cache@v2
with:
path: |
unit-base.txt
# Use base sha for PR or new commit hash for master/main push in test result key.
key: ${{ runner.os }}-unit-test-coverage-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
- name: Checkout base code
if: matrix.go-version == '1.16.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
if: matrix.go-version == '1.17.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.base.sha }}
path: __base
- name: Run test for base code
if: matrix.go-version == '1.16.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
if: matrix.go-version == '1.17.x' && env.RUN_BASE_COVERAGE == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && github.event.pull_request.base.sha != ''
run: |
cd __base
make test-unit
go tool cover -func=./unit.coverprofile | sed -e 's/.go:[0-9]*:\t/.go\t/g' | sed -e 's/\t\t*/\t/g' > ../unit-base.txt
make | grep test-unit && (make test-unit && go tool cover -func=./unit.coverprofile | sed -e 's/.go:[0-9]*:\t/.go\t/g' | sed -e 's/\t\t*/\t/g' > ../unit-base.txt) || echo "No test-unit in base"
- name: Test
id: test
run: |
Expand All @@ -69,7 +69,7 @@ jobs:
if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }}
run: cp unit.txt unit-base.txt
- name: Comment Test Coverage
if: matrix.go-version == '1.16.x'
if: matrix.go-version == '1.17.x'
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -85,7 +85,7 @@ jobs:
</details>
- name: Upload code coverage
if: matrix.go-version == '1.16.x'
if: matrix.go-version == '1.17.x'
uses: codecov/codecov-action@v1
with:
file: ./unit.coverprofile
Expand Down
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/.idea
/coverage.txt
/unit.coverprofile
/*.coverprofile
/.vscode
/bench-*.txt
/vendor
5 changes: 4 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ linters:
- paralleltest
- forbidigo
- exhaustivestruct
- interfacer
- interfacer # deprecated
- forcetypeassert
- scopelint # deprecated
- ifshort # too many false positives
- golint # deprecated

issues:
exclude-use-default: false
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#GOLANGCI_LINT_VERSION := "v1.38.0" # Optional configuration to pinpoint golangci-lint version.
#GOLANGCI_LINT_VERSION := "v1.41.1" # Optional configuration to pinpoint golangci-lint version.

# The head of Makefile determines location of dev-go to include standard targets.
GO ?= go
Expand Down Expand Up @@ -32,5 +32,7 @@ endif
-include $(DEVGO_PATH)/makefiles/test-unit.mk
-include $(DEVGO_PATH)/makefiles/reset-ci.mk

# Add your custom targets here.

## Run tests
test: test-unit
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/swaggest/usecase
go 1.12

require (
github.com/bool64/dev v0.1.25
github.com/bool64/dev v0.1.41
github.com/stretchr/testify v1.4.0
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/bool64/dev v0.1.25 h1:iSfcaS1FP6F2TlMI1daAvqk6PYl23XDf6oZu7WRXB8Y=
github.com/bool64/dev v0.1.25/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU=
github.com/bool64/dev v0.1.41 h1:L554LCQZc3d7mtcdPUgDbSrCVbr48/30zgu0VuC/FTA=
github.com/bool64/dev v0.1.41/go.mod h1:cTHiTDNc8EewrQPy3p1obNilpMpdmlUesDkFTF2zRWU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
5 changes: 5 additions & 0 deletions interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type Info struct {
var (
_ HasTags = Info{}
_ HasTitle = Info{}
_ HasName = Info{}
_ HasDescription = Info{}
_ HasIsDeprecated = Info{}
_ HasExpectedErrors = Info{}
Expand Down Expand Up @@ -184,6 +185,10 @@ func NewIOI(input, output interface{}, interact Interact) IOInteractor {

u.name, u.title = callerFunc()

u.name = strings.TrimPrefix(u.name, "internal/")
u.name = strings.TrimPrefix(u.name, "usecase.")
u.name = strings.TrimPrefix(u.name, "./main.")

return u
}

Expand Down
19 changes: 11 additions & 8 deletions wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ type Middleware interface {
type ErrorCatcher func(ctx context.Context, input interface{}, err error)

// Wrap implements Middleware.
func (e ErrorCatcher) Wrap(interactor Interactor) Interactor {
return Interact(func(ctx context.Context, input, output interface{}) error {
err := interactor.Interact(ctx, input, output)
if err != nil {
e(ctx, input, err)
}
func (e ErrorCatcher) Wrap(u Interactor) Interactor {
return &wrappedInteractor{
Interactor: Interact(func(ctx context.Context, input, output interface{}) error {
err := u.Interact(ctx, input, output)
if err != nil {
e(ctx, input, err)
}

return err
})
return err
}),
wrapped: u,
}
}

// MiddlewareFunc makes Middleware from function.
Expand Down

0 comments on commit fe22fff

Please sign in to comment.