diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..a0717e4 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.go text eol=lf \ No newline at end of file diff --git a/.github/workflows/develop.yaml b/.github/workflows/develop.yaml index 0e2d267..af8f33f 100644 --- a/.github/workflows/develop.yaml +++ b/.github/workflows/develop.yaml @@ -38,8 +38,6 @@ jobs: cd vendor/libgit2 mkdir build && cd build cmake .. - make - sudo make install cd ../../.. make install-static cd $GOPATH @@ -135,8 +133,6 @@ jobs: cd vendor/libgit2 mkdir build && cd build cmake .. - make - sudo make install cd ../../.. make install-static cd $GOPATH diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..ea81db0 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,52 @@ +name: Reviewdog +on: + push: + branches: + - develop + - master + pull_request: + branches: + - develop + - master +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + env: + GOPATH: ${{ github.workspace }} + GO111MODULE: auto + steps: + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.15.x + - uses: actions/checkout@v2 + with: + path: ./src/github.com/${{ github.repository }} + submodules: true + - name: Install apt dependecies + run: | + sudo apt-get install libgit2-dev libssh2-1-dev libssl-dev cmake + - name: Install go dependencies + run: | + go get -d github.com/Masterminds/sprig + - name: Install git2go + run: | + go get -d github.com/libgit2/git2go + cd $GOPATH/src/github.com/libgit2/git2go + git submodule update --init # get libgit2 + cd vendor/libgit2 + mkdir build && cd build + cmake .. + cd ../../.. + make install-static + go get -v -d github.com/kilpkonn/gtm-enhanced + - name: golangci-lint + uses: reviewdog/action-golangci-lint@v1 + with: + # Can pass --config flag to change golangci-lint behavior and target + # directory. + tool_name: Reviewdog + reporter: github-pr-check + golangci_lint_flags: "--config=.golangci.yml" + workdir: src/github.com/kilpkonn/gtm-enhanced \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 5514d7b..ecb7854 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -40,8 +40,6 @@ jobs: cd vendor/libgit2 mkdir build && cd build cmake .. - make - sudo make install cd ../../.. make install-static cd $GOPATH @@ -186,8 +184,6 @@ jobs: cd vendor/libgit2 mkdir build && cd build cmake .. - make - sudo make install cd ../../.. make install-static cd $GOPATH diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..46969fd --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,142 @@ +linters-settings: + depguard: + list-type: blacklist + packages: + # logging is allowed only by logutils.Log, logrus + # is allowed to use only in logutils package + - github.com/sirupsen/logrus + packages-with-error-message: + - github.com/sirupsen/logrus: "logging is allowed only by logutils.Log" + dupl: + threshold: 100 + funlen: + lines: 180 + statements: 80 + gci: + local-prefixes: github.com/golangci/golangci-lint + goconst: + min-len: 2 + min-occurrences: 3 + gocritic: + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + disabled-checks: + - dupImport # https://github.com/go-critic/go-critic/issues/845 + - ifElseChain + - octalLiteral + - whyNoLint + - wrapperFunc + gocyclo: + min-complexity: 18 + goimports: + local-prefixes: github.com/golangci/golangci-lint + golint: + min-confidence: 0 + gomnd: + settings: + mnd: + # don't include the "operation" and "assign" + checks: argument,case,condition,return + govet: + check-shadowing: true + settings: + printf: + funcs: + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + lll: + line-length: 100 + maligned: + suggest-new: true + misspell: + locale: US + nolintlint: + allow-leading-space: true # don't require machine-readable nolint directives (i.e. with no leading space) + allow-unused: false # report any unused nolint directives + require-explanation: false # don't require an explanation for nolint directives + require-specific: false # don't require nolint directives to be specific about which linter is being skipped + +linters: + # please, do not use `enable-all`: it's deprecated and will be removed soon. + # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint + disable-all: true + enable: + - bodyclose + - deadcode + - depguard + - dogsled + - dupl + - errcheck + - exhaustive + - funlen + - gochecknoinits + - goconst + - gocritic + - gocyclo + - gofmt + - goimports + - golint + - gomnd + - goprintffuncname + - gosec + - gosimple + - govet + - ineffassign + - interfacer + - lll + - misspell + - nakedret + - noctx + - nolintlint + - rowserrcheck + - scopelint + - staticcheck + - structcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - varcheck + - whitespace + + # don't enable: + # - asciicheck + # - gochecknoglobals + # - gocognit + # - godot + # - godox + # - goerr113 + # - maligned + # - nestif + # - prealloc + # - testpackage + # - wsl + +issues: + # Excluding configuration per-path, per-linter, per-text and per-source + exclude-rules: + - path: _test\.go + linters: + - gomnd + - dupl + - funlen + - lll + + # https://github.com/go-critic/go-critic/issues/926 + - linters: + - gocritic + text: "unnecessaryDefer:" + + +run: + # default concurrency is a available CPU number + concurrency: 4 + # timeout for analysis, e.g. 30s, 5m, default is 1m + deadline: 4m \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 754b8a2..0000000 --- a/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -language: go - -os: - - linux - - osx - -go: - - "1.10" - -before_install: - - make git2go - - go get github.com/mattn/goveralls - -before_deploy: - - go build -v --tags static -ldflags "-X main.Version=${TRAVIS_TAG}" - - v=$(${PWD}/gtm verify "${TRAVIS_TAG}"); echo "$v"; if [ ! "$v" == "true" ]; then exit 1; fi - - tar -zcf gtm.${TRAVIS_TAG}.${TRAVIS_OS_NAME}.tar.gz gtm - - shasum -a 256 gtm.${TRAVIS_TAG}.${TRAVIS_OS_NAME}.tar.gz > gtm.${TRAVIS_TAG}.${TRAVIS_OS_NAME}.checksum.txt - -script: - - go get -d ./... - - $HOME/gopath/bin/goveralls -v -flags=--tags=static -service=travis-ci - -deploy: - provider: releases - api_key: - secure: ESUJSNG50G0iQM8iRsfdwpcH/UBH0dhAn7PhqF1F1uAfR6NeQSZwGDWumgwf3G7CX5GcfFu6PbNXlUo8+q7u12TgQ1ZoQ38vBgfLJUvwuoYPSfU2TttX9RdPSJiCCtM+UQsqDY1l7vjLOsYV3OaR9GpO21ttxaSGX3+AoAgfh24SWaLiwSNK6SEyO4B4gzJcvXdt4D31vBXfFaQ33kSP+WcbYov+R1OI/MeyHbesrmFgFwzo+CX+baIHd9FFy6iR/EMpK9YKoSOa5obMx3eINuwYFYXDxz7/kWX7CtAoChySodAbKLHGO3IY1vAvrDaaSclGgSGfK/J69KurO+RvH/4NZh1KhAgUhEXk62KxYtjS/Dr2g8G8ucXQ6nGa77QWXjWSPbwjJWF4CUMPFiRramqcS6O19v61MgRcawAQ/gxkx0XLYXSDz8RlM+rrt7ZJoJ6JSSoMhS089E46nTMroqlQWGoBFKXxIBq76mn3Qh/4TyOcFp6b8Bb224aaIrR7Teg9Pv9fTkzoO85mlhQfigdJ5PAUo6LLR0njBsY4PatTATcuW94vRmtbUaOLKiH81n7fE6NTA9gHPGB7650q4SjG0TSk45yNvDFo7hdcE2Hv7HY5+1ZmJtXE6NpmxjohDYIjcPL6tYunJgsSitzr3Ewwkb8eJVt+GHVHyqRbrcg= - file: - - "gtm.${TRAVIS_TAG}.${TRAVIS_OS_NAME}.tar.gz" - - "gtm.${TRAVIS_TAG}.${TRAVIS_OS_NAME}.checksum.txt" - skip_cleanup: true - overwrite: true - on: - tags: true - repo: git-time-metric/gtm diff --git a/Makefile b/Makefile deleted file mode 100644 index 946485c..0000000 --- a/Makefile +++ /dev/null @@ -1,90 +0,0 @@ -BINARY = bin/gtm -VERSION = 0.0.0-dev -COMMIT = $(shell git show -s --format='%h' HEAD) -LDFLAGS = -ldflags "-X main.Version=$(VERSION)-$(COMMIT)" -GIT2GO_VERSION = v27 -GIT2GO_PATH = $(GOPATH)/src/github.com/libgit2/git2go -LIBGIT2_PATH = $(GIT2GO_PATH)/vendor/libgit2 -PKGS = $(shell go list ./... | grep -v vendor) -BUILD_TAGS = static - -build: - go build --tags '$(BUILD_TAGS)' $(LDFLAGS) -o $(BINARY) - -debug: BUILD_TAGS += debug -debug: build - -profile: BUILD_TAGS += profile -profile: build - -debug-profile: BUILD_TAGS += debug profile -debug-profile: build - -test: - @go test $(TEST_OPTIONS) --tags '$(BUILD_TAGS)' $(PKGS) | grep --colour -E "FAIL|$$" - -test-verbose: TEST_OPTIONS += -v -test-verbose: test - -lint: - -@$(call color_echo, 4, "\nGo Vet"); \ - go vet --all --tags '$(BUILD_TAGS)' $(PKGS) - -@$(call color_echo, 4, "\nError Check"); \ - errcheck -ignoretests -tags '$(BUILD_TAGS)' $(PKGS) - -@$(call color_echo, 4, "\nIneffectual Assign"); \ - ineffassign ./ - -@$(call color_echo, 4, "\nStatic Check"); \ - staticcheck --tests=false --tags '$(BUILD_TAGS)' $(PKGS) - -@$(call color_echo, 4, "\nGo Simple"); \ - gosimple --tests=false --tags '$(BUILD_TAGS)' $(PKGS) - -@$(call color_echo, 4, "\nUnused"); \ - unused --tests=false --tags '$(BUILD_TAGS)' $(PKGS) - -@$(call color_echo, 4, "\nGo Lint"); \ - golint $(PKGS) - -@$(call color_echo, 4, "\nGo Format"); \ - go fmt $(PKGS) - -@$(call color_echo, 4, "\nLicense Check"); \ - ag --go -L license . |grep -v vendor/ - -install: - go install --tags '$(BUILD_TAGS)' $(LDFLAGS) - -clean: - go clean - rm bin/* - -git2go-install: - [[ -d $(GIT2GO_PATH) ]] || git clone https://github.com/libgit2/git2go.git $(GIT2GO_PATH) && \ - cd ${GIT2GO_PATH} && \ - git pull && \ - git checkout -qf $(GIT2GO_VERSION) && \ - git submodule update --init - -git2go: git2go-install - cd $(LIBGIT2_PATH) && \ - mkdir -p install/lib && \ - mkdir -p build && \ - cd build && \ - cmake -DTHREADSAFE=ON \ - -DBUILD_CLAR=OFF \ - -DBUILD_SHARED_LIBS=OFF \ - -DCMAKE_C_FLAGS=-fPIC \ - -DUSE_SSH=OFF \ - -DCURL=OFF \ - -DUSE_HTTPS=OFF \ - -DUSE_BUNDLED_ZLIB=ON \ - -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ - -DCMAKE_INSTALL_PREFIX=../install \ - .. && \ - cmake --build . - -git2go-clean: - [[ -d $(GIT2GO_PATH) ]] && rm -rf $(GIT2GO_PATH) - -define color_echo - @tput setaf $1 - @echo $2 - @tput sgr0 -endef - -.PHONY: build test vet fmt install clean git2go-install git2go-build all-tags profile debug diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 62ac80d..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,40 +0,0 @@ -version: "{build}" - -os: Visual Studio 2015 - -clone_folder: c:\gopath\src\github.com\git-time-metric\gtm - -skip_branch_with_pr: true - -environment: - GOVERSION: 1.9.7 - GOPATH: c:\gopath - PROJ_DIR: /c/gopath/src/github.com/git-time-metric/gtm - -install: - - rmdir c:\go /s /q - - appveyor DownloadFile https://storage.googleapis.com/golang/go%GOVERSION%.windows-amd64.msi - - msiexec /i go%GOVERSION%.windows-amd64.msi /q - - go version - - go env - -build_script: - - c:\msys64\usr\bin\bash -lc "cd ${PROJ_DIR} && make git2go-install" - - c:\msys64\usr\bin\bash -lc "/c/gopath/src/github.com/kilpkonn/gtm-enhanced/script/appveyor-build.sh" - -artifacts: - - path: gtm.$(appveyor_repo_tag_name).windows.tar.gz - name: gtm.zip - - - path: 'gtm.developer-build-*.windows.tar.gz' - name: gtm-developer.tar.gz - -deploy: - description: '' - provider: GitHub - auth_token: - secure: O47of1Osqbk2qkk1Vn228XXF/YDwev5j5YHyNPzEPJR1pxuqwPaqlvsFDVUYQoiu - artifact: gtm.zip - force_update: true - on: - appveyor_repo_tag: true diff --git a/script/appveyor-build.sh b/script/appveyor-build.sh deleted file mode 100755 index 34f7568..0000000 --- a/script/appveyor-build.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash - -set -ex - -export PATH=/c/msys64/mingw64/bin:/c/msys64/usr/bin:/c/Go/bin:/c/gopath/go/bin:$PATH - -GIT2GO_PATH="${GOPATH}/src/github.com/libgit2/git2go" -LIBGIT2_BUILD="${GIT2GO_PATH}/vendor/libgit2/build" -mkdir -p "${LIBGIT2_BUILD}" -cd "${LIBGIT2_BUILD}" -FLAGS="-lws2_32" -export CGO_LDFLAGS="${LIBGIT2_BUILD}/libgit2.a -L${LIBGIT2_BUILD} ${FLAGS}" - -cmake -DTHREADSAFE=ON \ - -DBUILD_CLAR=OFF \ - -DBUILD_SHARED_LIBS=OFF \ - -DCMAKE_C_FLAGS=-fPIC \ - -DCMAKE_BUILD_TYPE="RelWithDebInfo" \ - -DCMAKE_INSTALL_PREFIX=../install \ - -DWINHTTP=OFF \ - -DUSE_BUNDLED_ZLIB=ON \ - -DUSE_HTTPS=OFF \ - -DUSE_SSH=OFF \ - -DCURL=OFF \ - -G "MSYS Makefiles" \ - .. && -cmake --build . - -cd "${GOPATH}/src/github.com/git-time-metric/gtm" -go get -d ./... -go test --tags static $(go list ./... | grep -v vendor) -if [[ "${APPVEYOR_REPO_TAG}" = true ]]; then - version=${APPVEYOR_REPO_TAG_NAME} - go build -v --tags static -ldflags "-X main.Version=${version}" - - # make sure version is set correctly - v="$(${GOPATH}/src/github.com/kilpkonn/gtm-enhanced/gtm.exe verify ${version})" - if [ ! "$v" == "true" ]; then - exit 1 - fi - - tar -zcf "gtm.${APPVEYOR_REPO_TAG_NAME}.windows.tar.gz" gtm.exe -else - version='0.0.0-dev' - go build -v --tags static -ldflags "-X main.Version=${version}" - - # make sure version is set correctly - v="$(${GOPATH}/src/github.com/kilpkonn/gtm-enhanced/gtm.exe verify ${version})" - if [ ! "$v" == "true" ]; then - exit 1 - fi - - tar -zcf "gtm.developer-build-${version}.windows.tar.gz" gtm.exe -fi diff --git a/util/date_test.go b/util/date_test.go index 163bdc9..9168a23 100644 --- a/util/date_test.go +++ b/util/date_test.go @@ -5,24 +5,12 @@ package util import ( - "fmt" "testing" "time" "github.com/jinzhu/now" ) -func printDates() { - fmt.Printf("%+10s %s\n", "Today", TodayRange()) - fmt.Printf("%+10s %s\n", "Yesterday", YesterdayRange()) - fmt.Printf("%+10s %s\n", "ThisWeek", ThisWeekRange()) - fmt.Printf("%+10s %s\n", "LastWeek", LastWeekRange()) - fmt.Printf("%+10s %s\n", "ThisMonth", ThisMonthRange()) - fmt.Printf("%+10s %s\n", "LastMonth", LastMonthRange()) - fmt.Printf("%+10s %s\n", "ThisYear", ThisYearRange()) - fmt.Printf("%+10s %s\n", "LastYear", LastYearRange()) -} - func TestDateRanges(t *testing.T) { tm, err := time.Parse("2006-Jan-02", "2015-Jul-01") if err != nil {