From 6f6f11a336aa05ce6d11ca8dd6c9d5ad812b0fd0 Mon Sep 17 00:00:00 2001 From: shipengqi Date: Thu, 7 Mar 2024 13:37:25 +0800 Subject: [PATCH 1/4] WIP(workflow): add workflows and issue, PR templates --- .github/ISSUE_TEMPLATE/bug.yaml | 54 +++++++++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 1 + .github/ISSUE_TEMPLATE/feature.yaml | 38 +++++++++++++ .github/dependabot.yml | 26 +++++++++ .github/labeler.yml | 29 ++++++++++ .github/pull_request_template.md | 11 ++++ .github/workflows/autolabel.yaml | 21 ++++++++ .github/workflows/codeql.yaml | 30 +++++++++++ .github/workflows/depsreview.yaml | 12 +++++ .github/workflows/gitleaks.yaml | 24 +++++++++ .github/workflows/grype.yaml | 26 +++++++++ .github/workflows/lint.yaml | 38 +++++++++++++ .github/workflows/stale.yaml | 22 ++++++++ Makefile | 83 +++++++++++++++++++++++++++++ 14 files changed, 415 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug.yaml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature.yaml create mode 100644 .github/dependabot.yml create mode 100644 .github/labeler.yml create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/autolabel.yaml create mode 100644 .github/workflows/codeql.yaml create mode 100644 .github/workflows/depsreview.yaml create mode 100644 .github/workflows/gitleaks.yaml create mode 100644 .github/workflows/grype.yaml create mode 100644 .github/workflows/lint.yaml create mode 100644 .github/workflows/stale.yaml diff --git a/.github/ISSUE_TEMPLATE/bug.yaml b/.github/ISSUE_TEMPLATE/bug.yaml new file mode 100644 index 0000000..4541592 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug.yaml @@ -0,0 +1,54 @@ +name: Bug Report +description: Tell us about a problem you are experiencing +labels: [bug, triage] +assignees: + - shipengqi +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this bug report! Please fill the form below. + - type: textarea + id: what-happened + attributes: + label: What happened? + description: Also tell us, what did you expect to happen? + validations: + required: true + - type: textarea + id: reproducible + attributes: + label: How can we reproduce this? + description: Please share a public repository that reproduces the issue, or an example config file. + validations: + required: true + - type: textarea + id: commitizen-version + attributes: + label: commitizen version + description: "`commitizen --version` output" + render: bash + validations: + required: true + - type: textarea + id: os + attributes: + label: OS + description: "e.g. from `/etc/os-release`" + render: bash + validations: + required: true + - type: checkboxes + id: search + attributes: + label: Search + options: + - label: I did search for other open and closed issues before opening this + required: true + - type: textarea + id: ctx + attributes: + label: Additional context + description: Anything else you would like to add + validations: + required: false \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..3ba13e0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1 @@ +blank_issues_enabled: false diff --git a/.github/ISSUE_TEMPLATE/feature.yaml b/.github/ISSUE_TEMPLATE/feature.yaml new file mode 100644 index 0000000..89b15c6 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature.yaml @@ -0,0 +1,38 @@ +name: Feature Request +description: Request a new feature and/or enhancement to an existing feature +labels: [enhancement, triage] +assignees: + - shipengqi +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this feature request! Please fill the form below. + - type: textarea + id: is-it-a-problem + attributes: + label: Is your feature request related to a problem? Please describe. + description: A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + validations: + required: true + - type: textarea + id: solution + attributes: + label: Describe the solution you'd like + description: A clear and concise description of what you want to happen. + validations: + required: true + - type: checkboxes + id: search + attributes: + label: Search + options: + - label: I did search for other open and closed issues before opening this + required: true + - type: textarea + id: ctx + attributes: + label: Additional context + description: Anything else you would like to add + validations: + required: false \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..1939824 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,26 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + assignees: + - "shipengqi" + directory: "/" + schedule: + interval: "daily" + time: "08:00" + labels: + - "dependencies" + commit-message: + prefix: "feat" + include: "scope" + - package-ecosystem: "github-actions" + assignees: + - "shipengqi" + directory: "/" + schedule: + interval: "daily" + time: "08:00" + labels: + - "dependencies" + commit-message: + prefix: "chore" + include: "scope" \ No newline at end of file diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 0000000..3a60ece --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,29 @@ +# Works with https://github.com/actions/labeler/ +# Below this line, the keys are labels to be applied, and the values are the file globs to match against. +# Anything in the `design` directory gets the `Design` label. +design: + - design/* + +example: + - example/* + - examples/* + +documentation: + - docs/**/* + - README.md + +dependencies: + - go.mod + - go.sum + +hack: + - hack/* + +unit-tests: + - "pkg/**/*_test.go" + - "cmd/**/*_test.go" + - "config/**/*_test.go" + - "internal/**/*_test.go" + +e2e-tests: + - "test/e2e/**/*" diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..8cd5abc --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,11 @@ +Thank you for contributing to commitizen! + +# Please add a summary of your change + +# Does your change fix a particular issue? + +Fixes #(issue) + +**Check list:** +- [ ] Mark if documentation changes are required. +- [ ] Mark if tests were added or updated to cover the changes. \ No newline at end of file diff --git a/.github/workflows/autolabel.yaml b/.github/workflows/autolabel.yaml new file mode 100644 index 0000000..4fd8996 --- /dev/null +++ b/.github/workflows/autolabel.yaml @@ -0,0 +1,21 @@ +name: "Auto Label" +# pull_request_target means that this will run on pull requests, but in the context of the base repo. +# This should mean PRs from forks are supported. +# Because it includes the `synchronize` parameter, any push of a new commit to the HEAD ref of a pull request +# will trigger this process. + +on: + pull_request_target: + types: [opened, reopened, synchronize, ready_for_review] + +jobs: + # Automatically labels PRs based on file globs in the change. + triage: + runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write + steps: + - uses: actions/labeler@v4 + with: + repo-token: ${{ secrets.PAT }} diff --git a/.github/workflows/codeql.yaml b/.github/workflows/codeql.yaml new file mode 100644 index 0000000..b98894d --- /dev/null +++ b/.github/workflows/codeql.yaml @@ -0,0 +1,30 @@ +name: "codeql" +on: + push: + branches: [ main ] + paths-ignore: + - 'docs/**' + - 'README.md' + pull_request: + branches: [ main ] + paths-ignore: + - 'docs/**' + - 'README.md' +jobs: + analyze: + name: analyze + runs-on: ubuntu-latest + permissions: + security-events: write + actions: read + contents: read + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: stable + # Initializes the CodeQL tools for scanning. + - uses: github/codeql-action/init@v2 + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + - uses: github/codeql-action/autobuild@v2 + - uses: github/codeql-action/analyze@v2 \ No newline at end of file diff --git a/.github/workflows/depsreview.yaml b/.github/workflows/depsreview.yaml new file mode 100644 index 0000000..42d323e --- /dev/null +++ b/.github/workflows/depsreview.yaml @@ -0,0 +1,12 @@ +name: dependency-review +on: [pull_request] +permissions: + contents: read +jobs: + dependency-review: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/dependency-review-action@v3 + with: + allow-licenses: BSD-2-Clause, BSD-3-Clause, MIT, Apache-2.0, MPL-1.0, MPL-1.1, MPL-2.0 \ No newline at end of file diff --git a/.github/workflows/gitleaks.yaml b/.github/workflows/gitleaks.yaml new file mode 100644 index 0000000..ff57fd1 --- /dev/null +++ b/.github/workflows/gitleaks.yaml @@ -0,0 +1,24 @@ +name: gitleaks +on: + push: + branches: ['main'] + tags: ['v*'] + paths-ignore: + - 'docs/**' + - 'README.md' + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' +permissions: + contents: read +jobs: + gitleaks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: gitleaks/gitleaks-action@v2 + env: + GITHUB_TOKEN: ${{ secrets.PAT }} \ No newline at end of file diff --git a/.github/workflows/grype.yaml b/.github/workflows/grype.yaml new file mode 100644 index 0000000..7ff094f --- /dev/null +++ b/.github/workflows/grype.yaml @@ -0,0 +1,26 @@ +name: "grype" +on: + push: + branches: ['main'] + tags: ['v*'] + paths-ignore: + - 'docs/**' + - 'README.md' + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' +jobs: + scan-source: + name: scan-source + runs-on: ubuntu-latest + permissions: + security-events: write + actions: read + contents: read + steps: + - uses: actions/checkout@v3 + - uses: anchore/scan-action@v3 + with: + path: "." + fail-build: true \ No newline at end of file diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..5a4c025 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,38 @@ +name: golangci-lint +on: + push: + tags: + - v* + branches: + - main + paths-ignore: + - 'docs/**' + - 'README.md' + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' +permissions: + contents: read + +jobs: + golangci: + strategy: + matrix: + go: [ '1.20', '1.21' ] + os: [ ubuntu-latest, windows-latest ] + permissions: + contents: read # for actions/checkout to fetch code + pull-requests: read # for golangci/golangci-lint-action to fetch pull requests + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: stable # get the latest stable version from the go-versions repository manifest. + cache: false + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + args: --timeout=10m \ No newline at end of file diff --git a/.github/workflows/stale.yaml b/.github/workflows/stale.yaml new file mode 100644 index 0000000..0c47882 --- /dev/null +++ b/.github/workflows/stale.yaml @@ -0,0 +1,22 @@ +name: Close inactive issues +on: + schedule: + - cron: "30 1 * * *" + +jobs: + close-issues: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - uses: actions/stale@v8 + with: + days-before-issue-stale: 30 + days-before-issue-close: 14 + stale-issue-label: "stale" + stale-issue-message: "This issue is stale because it has been open for 30 days with no activity." + close-issue-message: "This issue was closed because it has been inactive for 14 days since being marked as stale." + days-before-pr-stale: -1 + days-before-pr-close: -1 + repo-token: ${{ secrets.PAT }} \ No newline at end of file diff --git a/Makefile b/Makefile index e69de29..7d591c3 100644 --- a/Makefile +++ b/Makefile @@ -0,0 +1,83 @@ +.PHONY: all +all: modules lint test build + +# ============================================================================== +# Includes + +include hack/include/common.mk # make sure include common.mk at the first include line +include hack/include/tools.mk +include hack/include/go.mk +include hack/include/test.mk +include hack/include/release.mk + +# ============================================================================== +# Usage + +define USAGE_OPTIONS + +Options: + VERSION The version information compiled into binaries. + The default is obtained from gsemver or git. + PUBLISH Whether to publish a release to Github. Default is 0. + This option is available when using: make release + GITHUB_TOKEN Token used to access Github. + This option is available when using: make release + V Set to 1 enable verbose build. Default is 0. + DEBUG Whether to generate debug symbols. Default is 0. +endef +export USAGE_OPTIONS + +# ============================================================================== +# Targets + +## build: build binary file. +.PHONY: build +build: modules + @$(MAKE) go.build + +## changelog: (Deprecated) generate changelogs. +.PHONY: changelog +changelog: + @$(MAKE) release.changelog + +## tag: generate release tag. +.PHONY: tag +tag: + @$(MAKE) release.tag + +## release: release a version. +.PHONY: release +release: + @$(MAKE) release.run + +## modules: add missing and remove unused modules. +.PHONY: modules +modules: + @go mod tidy + +## clean: remove all files that are generated by building. +.PHONY: clean +clean: + @$(MAKE) go.clean + +## lint: Check syntax and styling of go sources. +.PHONY: lint +lint: + @$(MAKE) go.lint + +## test: run unit test and get test coverage. +.PHONY: test +test: + @$(MAKE) test.cover + +## test-e2e: run e2e test. +.PHONY: test-e2e +test-e2e: + @$(MAKE) test.e2e + +## help: show help information. +.PHONY: help +help: Makefile + @echo -e "\nUsage: make ...\n\nTargets:" + @sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' + @echo "$$USAGE_OPTIONS" \ No newline at end of file From 4504ecc6d16f5cdd44e1c98e1e360e983012bbf9 Mon Sep 17 00:00:00 2001 From: shipengqi Date: Thu, 7 Mar 2024 16:57:40 +0800 Subject: [PATCH 2/4] WIP(docs): installation guide --- .github/workflows/e2e.yaml | 1 + .github/workflows/lint.yaml | 2 +- .github/workflows/release.yaml | 1 + .golangci.yaml | 31 ++++++++++ Makefile | 110 +++++++++------------------------ README.md | 26 +++++--- 6 files changed, 82 insertions(+), 89 deletions(-) create mode 100644 .github/workflows/e2e.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .golangci.yaml diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.github/workflows/e2e.yaml @@ -0,0 +1 @@ + diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 5a4c025..a15d0d7 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -19,7 +19,7 @@ jobs: golangci: strategy: matrix: - go: [ '1.20', '1.21' ] + go: [ '1.20', '1.21', '1.22'' ] os: [ ubuntu-latest, windows-latest ] permissions: contents: read # for actions/checkout to fetch code diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1 @@ + diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..8b9e289 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,31 @@ +run: + # Include test files or not. + # Default: true + tests: false + +linters: + disable-all: true + enable: + - misspell + - govet + - staticcheck + - errcheck + - unparam + - ineffassign + - nakedret + - gocyclo + - dupl + - goimports + - revive + - gosec + - gosimple + - typecheck + - unused + +linters-settings: + gofmt: + simplify: true + goimports: + local-prefixes: github.com/shipengqi/commitizen + dupl: + threshold: 600 \ No newline at end of file diff --git a/Makefile b/Makefile index 7d591c3..4aa3ba9 100644 --- a/Makefile +++ b/Makefile @@ -1,83 +1,33 @@ -.PHONY: all -all: modules lint test build - -# ============================================================================== -# Includes - -include hack/include/common.mk # make sure include common.mk at the first include line -include hack/include/tools.mk -include hack/include/go.mk -include hack/include/test.mk -include hack/include/release.mk - -# ============================================================================== -# Usage - -define USAGE_OPTIONS - -Options: - VERSION The version information compiled into binaries. - The default is obtained from gsemver or git. - PUBLISH Whether to publish a release to Github. Default is 0. - This option is available when using: make release - GITHUB_TOKEN Token used to access Github. - This option is available when using: make release - V Set to 1 enable verbose build. Default is 0. - DEBUG Whether to generate debug symbols. Default is 0. -endef -export USAGE_OPTIONS - -# ============================================================================== -# Targets - -## build: build binary file. -.PHONY: build -build: modules - @$(MAKE) go.build - -## changelog: (Deprecated) generate changelogs. -.PHONY: changelog -changelog: - @$(MAKE) release.changelog - -## tag: generate release tag. -.PHONY: tag -tag: - @$(MAKE) release.tag - -## release: release a version. -.PHONY: release -release: - @$(MAKE) release.run - -## modules: add missing and remove unused modules. -.PHONY: modules -modules: - @go mod tidy - -## clean: remove all files that are generated by building. -.PHONY: clean +VERSION := $(shell git describe --abbrev=0) +COMMIT_REVISION := $(shell git log --pretty=%h -1) +REVISION_FLAG := "-X github.com/lintingzhen/commitizen-go/cmd.revision=${COMMIT_REVISION} -X github.com/lintingzhen/commitizen-go/cmd.version=${VERSION}" +TARGET := commitizen-go +GOFILES := $(wildcard *.go) $(wildcard cmd/*.go) $(wildcard git/*.go) $(wildcard commit/*.go) +GOARCH := $(shell go env GOARCH) + +ifeq ($(OS),Windows_NT) + GOOS := windows + COPY := copy +else + COPY := cp + UNAME_S := $(shell uname -s) + ifeq ($(UNAME_S),Linux) + GOOS := linux + else ifeq ($(UNAME_S),Darwin) + GOOS := darwin + endif +endif + +GIT_EXEC_PATH := $(shell git --exec-path) + +all: ${TARGET} +install: + $(COPY) commitizen-go $(GIT_EXEC_PATH)/git-cz clean: - @$(MAKE) go.clean - -## lint: Check syntax and styling of go sources. -.PHONY: lint -lint: - @$(MAKE) go.lint - -## test: run unit test and get test coverage. -.PHONY: test -test: - @$(MAKE) test.cover + rm -rf ${TARGET} + -## test-e2e: run e2e test. -.PHONY: test-e2e -test-e2e: - @$(MAKE) test.e2e +commitizen-go: $(GOFILES) + CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o $@ -ldflags ${REVISION_FLAG} -## help: show help information. -.PHONY: help -help: Makefile - @echo -e "\nUsage: make ...\n\nTargets:" - @sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /' - @echo "$$USAGE_OPTIONS" \ No newline at end of file +.PHONY: all install clean \ No newline at end of file diff --git a/README.md b/README.md index 23329ec..23324cd 100644 --- a/README.md +++ b/README.md @@ -26,30 +26,40 @@ Flags: Use "commitizen [command] --help" for more information about a command. ``` -commit with commitizen: +Commit with commitizen: ``` $ git cz ``` -## Installing commitizen +## Installation ### From the Binary Releases -### From Source +Download the pre-compiled binaries from the [releases page](https://github.com/shipengqi/commitizen/releases) and copy them to the desired location. + +Then initialize this tool to git-core as git-cz: +``` +$ commitizen init +``` + +### Go Install You must have a working Go environment: ``` -$ git clone https://github.com/shipengqi/commitizen.git -$ cd commitizen -$ make && make install +$ go install github.com/shipengqi/commitizen@latest +$ commitizen init ``` -Or: +### From Source + +You must have a working Go environment: ``` -$ make && ./commitizen-go install +$ git clone https://github.com/shipengqi/commitizen.git +$ cd commitizen +$ make && ./commitizen init ``` ## Configuration From 55d7e1d14152940416397d878cc83f9d37f4a0e8 Mon Sep 17 00:00:00 2001 From: shipengqi Date: Thu, 7 Mar 2024 17:16:43 +0800 Subject: [PATCH 3/4] fix(command): add version command --- Makefile | 52 +++++++++++++++++++++-------------------------- cmd/cz/cz.go | 1 + cmd/cz/version.go | 19 +++++++++++++++++ go.mod | 4 ++++ go.sum | 13 +++++++++--- 5 files changed, 57 insertions(+), 32 deletions(-) create mode 100644 cmd/cz/version.go diff --git a/Makefile b/Makefile index 4aa3ba9..df54eaa 100644 --- a/Makefile +++ b/Makefile @@ -1,33 +1,27 @@ -VERSION := $(shell git describe --abbrev=0) -COMMIT_REVISION := $(shell git log --pretty=%h -1) -REVISION_FLAG := "-X github.com/lintingzhen/commitizen-go/cmd.revision=${COMMIT_REVISION} -X github.com/lintingzhen/commitizen-go/cmd.version=${VERSION}" -TARGET := commitizen-go -GOFILES := $(wildcard *.go) $(wildcard cmd/*.go) $(wildcard git/*.go) $(wildcard commit/*.go) -GOARCH := $(shell go env GOARCH) +# The project's root import path +PKG := github.com/shipengqi/commitizen +# set version package +VERSION_PKG=github.com/shipengqi/component-base/version -ifeq ($(OS),Windows_NT) - GOOS := windows - COPY := copy -else - COPY := cp - UNAME_S := $(shell uname -s) - ifeq ($(UNAME_S),Linux) - GOOS := linux - else ifeq ($(UNAME_S),Darwin) - GOOS := darwin - endif +ifeq ($(origin VERSION), undefined) +VERSION := $(shell git describe --tags --always --match='v*') endif -GIT_EXEC_PATH := $(shell git --exec-path) - -all: ${TARGET} -install: - $(COPY) commitizen-go $(GIT_EXEC_PATH)/git-cz -clean: - rm -rf ${TARGET} - - -commitizen-go: $(GOFILES) - CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} go build -o $@ -ldflags ${REVISION_FLAG} +# set git commit and tree state +GIT_COMMIT = $(shell git rev-parse HEAD) +ifneq ($(shell git status --porcelain 2> /dev/null),) + GIT_TREE_STATE ?= dirty +else + GIT_TREE_STATE ?= clean +endif -.PHONY: all install clean \ No newline at end of file +# set ldflags +GO_LDFLAGS += -X $(VERSION_PKG).Version=$(VERSION) \ + -X $(VERSION_PKG).GitCommit=$(GIT_COMMIT) \ + -X $(VERSION_PKG).GitTreeState=$(GIT_TREE_STATE) \ + -X $(VERSION_PKG).BuildDate=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') + +.PHONY: go.build +go.build: + @echo "===========> Building: $(OUTPUT_DIR)/$(BIN)" + @CGO_ENABLED=0 go build -ldflags "$(GO_LDFLAGS)" -o $(OUTPUT_DIR)/$(BIN) ${PKG} \ No newline at end of file diff --git a/cmd/cz/cz.go b/cmd/cz/cz.go index 7f6f637..968ae0a 100644 --- a/cmd/cz/cz.go +++ b/cmd/cz/cz.go @@ -64,6 +64,7 @@ func New() *cobra.Command { o.AddFlags(f) c.AddCommand(NewInitCmd()) + c.AddCommand(NewVersionCmd()) return c } diff --git a/cmd/cz/version.go b/cmd/cz/version.go new file mode 100644 index 0000000..f79f3db --- /dev/null +++ b/cmd/cz/version.go @@ -0,0 +1,19 @@ +package cz + +import ( + "fmt" + + "github.com/shipengqi/component-base/version" + "github.com/spf13/cobra" +) + +func NewVersionCmd() *cobra.Command { + c := &cobra.Command{ + Use: "version", + Short: "Print the version information.", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println(version.Get().String()) + }, + } + return c +} diff --git a/go.mod b/go.mod index f9faace..8c0fe97 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/charmbracelet/bubbles v0.18.0 github.com/charmbracelet/bubbletea v0.25.0 github.com/charmbracelet/lipgloss v0.9.1 + github.com/shipengqi/component-base v0.2.4 github.com/shipengqi/golib v0.2.10 github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 @@ -16,9 +17,12 @@ require ( github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect + github.com/fatih/color v1.16.0 // indirect + github.com/gosuri/uitable v0.0.4 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/kr/text v0.2.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-localereader v0.0.1 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect diff --git a/go.sum b/go.sum index 6d14208..bfb0d0b 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,6 @@ github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= -github.com/charmbracelet/bubbles v0.17.1 h1:0SIyjOnkrsfDo88YvPgAWvZMwXe26TP6drRvmkjyUu4= -github.com/charmbracelet/bubbles v0.17.1/go.mod h1:9HxZWlkCqz2PRwsCbYl7a3KXvGzFaDHpYbSYMJ+nE3o= github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0= github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw= github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt5dywy4TcM= @@ -16,6 +14,10 @@ github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 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/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= +github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= +github.com/gosuri/uitable v0.0.4 h1:IG2xLKRvErL3uhY6e1BylFzG+aJiwQviDDTfOKeKTpY= +github.com/gosuri/uitable v0.0.4/go.mod h1:tKR86bXuXPZazfOTG1FIzvjIdXzd0mo4Vtn16vt0PJo= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= @@ -26,6 +28,9 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0 github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= @@ -44,13 +49,14 @@ github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1n 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/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.6 h1:Sovz9sDSwbOz9tgUy8JpT+KgCkPYJEN/oYzlJiYTNLg= github.com/rivo/uniseg v0.4.6/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f h1:MvTmaQdww/z0Q4wrYjDSCcZ78NoftLQyHBSLW/Cx79Y= github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= +github.com/shipengqi/component-base v0.2.4 h1:P423eqA3EeVE1VZaBo9bmrcwTnz5oMkzsE02kdTTxSg= +github.com/shipengqi/component-base v0.2.4/go.mod h1:uNVw/00SYUlhambc9Vz25oAeE4qd5g9ryZTkkUfizQs= github.com/shipengqi/golib v0.2.10 h1:obnq1jdYYRsA9ja7yUPmH0jqx/3Q0H1gNARSpn/Va2E= github.com/shipengqi/golib v0.2.10/go.mod h1:NZSkI7eecrMMNvVyv0FPvUID8BF9DxMP3V3WZREnXqc= github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= @@ -61,6 +67,7 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= From c4e5c351d819d273af0325826850153fae00cbd3 Mon Sep 17 00:00:00 2001 From: shipengqi Date: Fri, 8 Mar 2024 09:38:04 +0800 Subject: [PATCH 4/4] WIP(doc): update doc for multiple templates --- README.md | 24 ++++++++++++++++++++++++ internal/git/options.go | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 23324cd..8833048 100644 --- a/README.md +++ b/README.md @@ -114,4 +114,28 @@ Commit message `format`: ``` format: "{{.type}}{{with .scope}}({{.}}){{end}}: {{.subject}}{{with .body}}\n\n{{.}}{{end}}{{with .footer}}\n\n{{.}}{{end}}" +``` + +### Multiple Templates + +You can define multiple templates in the `.git-czrc` file, separated by `---`: + +```yaml +name: angular-template +items: + - name: scope + desc: "Scope. Could be anything specifying place of the commit change:" + type: input + # ... +format: "{{.type}}{{with .scope}}({{.}}){{end}}: {{.subject}}{{with .body}}\n\n{{.}}{{end}}{{with .footer}}\n\n{{.}}{{end}}"` + +--- + +name: my-template +items: + - name: scope + desc: "Scope. Could be anything specifying place of the commit change:" + type: input + # ... +format: "{{.type}}{{with .scope}}({{.}}){{end}}: {{.subject}}{{with .body}}\n\n{{.}}{{end}}{{with .footer}}\n\n{{.}}{{end}}"` ``` \ No newline at end of file diff --git a/internal/git/options.go b/internal/git/options.go index 3daf6f1..a97c6f4 100644 --- a/internal/git/options.go +++ b/internal/git/options.go @@ -15,6 +15,6 @@ func NewOptions() *Options { } func (o *Options) AddFlags(f *pflag.FlagSet) { - f.BoolVarP(&o.SignOff, "signoff", "s", o.SignOff, "add a Signed-off-by trailer by the committer at the end of the commit log message.") f.BoolVarP(&o.Add, "add", "a", o.Add, "tell the command to automatically stage files that have been modified and deleted, but new files you have not told Git about are not affected.") + f.BoolVarP(&o.SignOff, "signoff", "s", o.SignOff, "add a Signed-off-by trailer by the committer at the end of the commit log message.") }