diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..a34b02a --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,29 @@ +#!/usr/bin/env sh + +set -e + +command_exists() { + command -v "$@" > /dev/null 2>&1 +} + +echo Running pre-commit hook + +if ! command_exists task +then + echo "task could not be found - install task before running pre-commit: https://taskfile.dev/installation/" + exit 1 +fi + +# Run pre-commit, this checks if we changed any golang files and runs the checks. +# The files are then git-added +FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep .go | sed 's| |\\ |g') +if [ -n "$FILES" ]; then + if ! task fmt; then + echo "Error running make check - please fix before committing" + echo "if this is a mistake you can skip the checks with 'git commit --no-verify'" + exit 1 + fi + echo "$FILES" | xargs git add +fi + +exit 0 diff --git a/.go-header.txt b/.go-header.txt index 81853f3..416d661 100644 --- a/.go-header.txt +++ b/.go-header.txt @@ -1,5 +1,5 @@ - Copyright 2023, easysoft + Copyright 2024, zentao Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/.golangci.yml b/.golangci.yml index 15ed0cf..dc342ce 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,10 +21,10 @@ linters-settings: misspell: locale: US ignore-words: - - noteable - unused: - # Treat code as a program (not a library) and report unused exported identifiers - check-exported: false + - noteable + + goheader: + template-path: .go-header.txt linters: enable: @@ -33,9 +33,10 @@ linters: - errorlint - exportloopref - goconst - - revive - gosimple - govet + - goheader + - gomnd - ineffassign - megacheck - misspell @@ -45,13 +46,11 @@ linters: - unconvert - unused - whitespace - - goheader disable-all: true fast: false issues: - # Maximum issues count per one linter (set to 0 to disable) - max-issues-per-linter: 0 - - # Maximum count of issues with the same text (set to 0 to disable) - max-same-issues: 0 + exclude-rules: + - linters: + - goheader + text: "Copyright" diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..73278ee --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Package", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${fileDirname}" + } + ] +} diff --git a/OWNERS b/OWNERS index 0e289eb..de07b3d 100644 --- a/OWNERS +++ b/OWNERS @@ -1,6 +1,4 @@ approvers: - ysicing - - zhengyuansheng reviewers: - ysicing - - zhengyuansheng diff --git a/README.md b/README.md index 4f3a034..711b055 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ Zentao API client enabling Go programs to interact with Zentao in a simple and u ## NOTE -基于ZenTao最新开源版本 [`18.3`](https://github.com/quicklyon/zentao-docker), 即将适配最新版本`20.dev` +基于ZenTao最新开源版本 [`18.11`](https://github.com/quicklyon/zentao-docker), 即将适配最新版本`20` ## 支持 @@ -114,9 +114,9 @@ Zentao API client enabling Go programs to interact with Zentao in a simple and u > 推荐本地部署 ```bash -# 部署方式: okteto up -f hack/okteto.yml --deploy -地址: https://zentao-easysoft.cloud.okteto.net -账号: admin/jaege1ugh4ooYip7 +# 部署方式: docker compose -f hack/zentao.yml up -d +地址: https://zentao.demo.qucheng.cc +账号: demo/quickon4You ``` ## TODO diff --git a/Taskfile.yml b/Taskfile.yml index 7b25ee2..c518fde 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,9 +1,9 @@ # https://taskfile.dev -version: '3' +version: "3" vars: - GOPROXY: 'https://goproxy.cn,direct' + GOPROXY: "https://goproxy.cn,direct" GOSUMDB: sum.golang.google.cn tasks: @@ -41,8 +41,25 @@ tasks: - task: gofmt - task: golint + initgithooks: + desc: pre dev init githooks + run: once + cmds: + - git config core.hooksPath .githooks + + dev: + desc: dev + cmds: + - docker compose -f hack/docker-compose.yml up -d + + clean: + desc: clean + cmds: + - docker compose -f hack/docker-compose.yml down -v + fmt: cmds: + - task: initgithooks - task: gomod - task: gencopyright - task: gofmt @@ -50,4 +67,5 @@ tasks: default: cmds: + - task: initgithooks - task: fmt diff --git a/go.mod b/go.mod index ecef8cf..5ccf553 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/easysoft/go-zentao -go 1.21 +go 1.20 require ( github.com/davecgh/go-spew v1.1.1 diff --git a/go.sum b/go.sum index 61a48bc..d06b015 100644 --- a/go.sum +++ b/go.sum @@ -7,13 +7,10 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs 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/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= -github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/pprof v0.0.0-20231229205709-960ae82b1e42 h1:dHLYa5D8/Ta0aLR2XcPsrkpAgGeFs6thhMcQK0oQ0n8= github.com/google/pprof v0.0.0-20231229205709-960ae82b1e42/go.mod h1:czg5+yv1E0ZGTi6S6vVK1mke0fV+FaUhNGcd6VRS9Ik= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -32,7 +29,6 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/onsi/ginkgo/v2 v2.13.2 h1:Bi2gGVkfn6gQcjNjZJVO8Gf0FHzMPf2phUei9tejVMs= github.com/onsi/ginkgo/v2 v2.13.2/go.mod h1:XStQ8QcGwLyF4HdfcZB8SFOS/MWCgDuXMSBe6zrvLgM= github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg= -github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -67,10 +63,8 @@ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA= golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= -google.golang.org/protobuf v1.28.0/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 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/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= diff --git a/hack/docker-compose.yaml b/hack/docker-compose.yaml index 102c9b7..678f9d3 100644 --- a/hack/docker-compose.yaml +++ b/hack/docker-compose.yaml @@ -1,5 +1,5 @@ # -# Copyright 2022, easysoft +# Copyright 2024, Zentao # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,21 +17,23 @@ version: '3.8' services: -# mysql service for zentao - zentao-mysql: - image: bitnami/mysql:8.1 - container_name: zentao-mysql +# db service for zentao + zentao-db: + image: bitnami/mariadb:10.6 + container_name: zentao-db restart: always volumes: - - 'zentao_db:/bitnami/mysql/data' + - 'zentao_db:/bitnami/mariadb' environment: - ALLOW_EMPTY_PASSWORD=yes - - MYSQL_ROOT_PASSWORD=pass4Zentao - - MYSQL_DATABASE=zentao + - MARIADB_ROOT_PASSWORD=pass4Zentao + - MARIADB_DATABASE=zentao + - MARIADB_CHARACTER_SET=utf8mb4 + - MARIADB_COLLATION=utf8mb4_unicode_ci # zentao service zentao: - image: easysoft/zentao:18.7 + image: easysoft/zentao:18.11 container_name: zentao restart: always ports: @@ -39,13 +41,13 @@ services: volumes: - 'zentao_data:/data' depends_on: - - zentao-mysql + - zentao-db environment: - - MYSQL_HOST=zentao-mysql - - MYSQL_PORT=3306 - - MYSQL_USER=root - - MYSQL_PASSWORD=pass4Zentao - - MYSQL_DB=zentao + - ZT_MYSQL_HOST=zentao-db + - ZT_MYSQL_PORT=3306 + - ZT_MYSQL_USER=root + - ZT_MYSQL_PASSWORD=pass4Zentao + - ZT_MYSQL_DB=zentao - EASYSOFT_DEBUG=true - DEBUG=1 - IS_CONTAINER=true diff --git a/hack/okteto.yml b/hack/okteto.yml deleted file mode 100644 index d8f318d..0000000 --- a/hack/okteto.yml +++ /dev/null @@ -1,52 +0,0 @@ -# -# Copyright 2022, easysoft -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -name: hack - -# The build section defines how to build the images of your development environment -# More info: https://www.okteto.com/docs/reference/manifest/#build -# build: -# my-service: -# context: . - - -# The deploy section defines how to deploy your development environment -# More info: https://www.okteto.com/docs/reference/manifest/#deploy -deploy: - compose: - file: docker-compose.yaml - services: - - zentao-mysql - - zentao - -# The dependencies section defines other git repositories to be deployed as part of your development environment -# More info: https://www.okteto.com/docs/reference/manifest/#dependencies -# dependencies: -# - https://github.com/okteto/sample -# The dev section defines how to activate a development container -# More info: https://www.okteto.com/docs/reference/manifest/#dev -# dev: -# sample: -# image: okteto/dev:latest -# command: bash -# workdir: /usr/src/app -# sync: -# - .:/usr/src/app -# environment: -# - name=$USER -# forward: -# - 8080:80 -