diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 0000000..24e8ff2 --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,16 @@ +--- +# codecov: +# require_ci_to_pass: yes + +coverage: + precision: 2 + round: down + range: "50...100" + +comment: + layout: "reach,diff,flags,files,footer" + behavior: default + require_changes: false + +ignore: + - "**/*_mock.go" diff --git a/.github/delete-merged-branch-config.yml b/.github/delete-merged-branch-config.yml new file mode 100644 index 0000000..f43ae39 --- /dev/null +++ b/.github/delete-merged-branch-config.yml @@ -0,0 +1,5 @@ +--- +exclude: + # dependabot auto deletes it's own branches + - dependabot/* +delete_closed_pr: true diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..07bfbe7 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,25 @@ +--- +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + commit-message: + prefix: chore + + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "daily" + commit-message: + prefix: chore + + - package-ecosystem: "gomod" + directory: "examples/go-client/" + schedule: + interval: "daily" + commit-message: + prefix: chore + ignore: + - dependency-name: ".*" diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 0000000..ab3bec5 --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,34 @@ +--- +test/unit: + - changed-files: + - any-glob-to-any-file: "**/*_test.go" + +test/integration: + - changed-files: + - any-glob-to-any-file: "tests/*" + - any-glob-to-any-file: "tests/*/**" + +kind/go: + - changed-files: + - any-glob-to-any-file: "**/*.go" + +kind/python: + - changed-files: + - any-glob-to-any-file: "python/*" + +kind/yaml: + - changed-files: + - any-glob-to-any-file: "**/*.yaml" + - any-glob-to-any-file: "**/*.yml" + +kind/docs: + - changed-files: + - any-glob-to-any-file: "docs/*" + - any-glob-to-any-file: "docs/*/**" + +github/action: + - changed-files: + - any-glob-to-any-file: ".github/**/*.yml" + +next: + - base-branch: 'main' diff --git a/.github/workflows/cleanup.yml b/.github/workflows/cleanup.yml new file mode 100644 index 0000000..594a0cc --- /dev/null +++ b/.github/workflows/cleanup.yml @@ -0,0 +1,15 @@ +--- +name: Cleanup + +on: + pull_request: + types: [closed] + +jobs: + delete-branch: + runs-on: ubuntu-latest + steps: + - name: delete branch + uses: SvanBoxel/delete-merged-branch@main + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml new file mode 100644 index 0000000..25e4df4 --- /dev/null +++ b/.github/workflows/commitlint.yml @@ -0,0 +1,13 @@ +name: Conventional Commits +on: + pull_request: + branches: [ "main" ] +jobs: + build: + name: Conventional Commits + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: webiny/action-conventional-commits@v1.3.0 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/depreview.yml b/.github/workflows/depreview.yml new file mode 100644 index 0000000..39fd5b1 --- /dev/null +++ b/.github/workflows/depreview.yml @@ -0,0 +1,15 @@ +--- +name: 'Dependency Review' +on: [pull_request] + +permissions: + contents: read + +jobs: + dependency-review: + runs-on: ubuntu-latest + steps: + - name: 'Checkout Repository' + uses: actions/checkout@v4 + - name: 'Dependency Review' + uses: actions/dependency-review-action@v4 diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml new file mode 100644 index 0000000..c701f72 --- /dev/null +++ b/.github/workflows/go.yml @@ -0,0 +1,29 @@ +--- +name: Go + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.22' + - name: Install Task + uses: arduino/setup-task@v2 + with: + version: 3.x + repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Test + run: task test + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml new file mode 100644 index 0000000..6457614 --- /dev/null +++ b/.github/workflows/greetings.yml @@ -0,0 +1,21 @@ +--- +name: Greetings + +on: [pull_request, issues] + +jobs: + greeting: + runs-on: ubuntu-latest + steps: + - uses: actions/first-interaction@v1 + if: env.month != 'Oct' + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + issue-message: 'Thank you for your first issue! 😊🕹ī¸' + pr-message: 'Thank you for contributing to this project! 😊🕹ī¸' + - uses: actions/first-interaction@v1 + if: env.month == 'Oct' + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + issue-message: 'Thank you for your first issue! Happy Hacktoberfest!!! 🎃👕🕹ī¸' + pr-message: 'Thank you for contributing to this project. Happy Hacktoberfest!!! 🎃👕🕹ī¸' diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 0000000..d28cf7d --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,13 @@ +--- +name: "Pull Request Labeler" +on: + - pull_request_target + +jobs: + triage: + permissions: + contents: read + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: actions/labeler@v5 diff --git a/.github/workflows/reportcard.yml b/.github/workflows/reportcard.yml new file mode 100644 index 0000000..84f901c --- /dev/null +++ b/.github/workflows/reportcard.yml @@ -0,0 +1,14 @@ +--- +name: Go Report Card + +on: + push: + branches: [ "main" ] + +jobs: + action_goreportcard: + runs-on: ubuntu-latest + name: A job to run go report card + steps: + - name: Go Report Card + uses: creekorful/goreportcard-action@v1.0 diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 0000000..0820267 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,18 @@ +--- +name: Mark stale issues and pull requests + +on: + schedule: + - cron: "30 1 * * *" + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v9 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-issue-message: 'Stale issue message' + stale-pr-message: 'Stale pull request message' + stale-issue-label: 'no-issue-activity' + stale-pr-label: 'no-pr-activity' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac61200 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +__pycache__ +cobertura.xml +cover.out +dist/ +result.xml +.task/ +test/integration/tmp/ diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..661521b --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,30 @@ +# Refer to golangci-lint's example config file for more options and information: +# https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml + +run: + timeout: 5m + modules-download-mode: readonly + +linters: + enable: + - errcheck + - errname + - goimports + - govet + - prealloc + - predeclared + - revive + - staticcheck + +linters-settings: + revive: + rules: + - name: package-comments + disabled: true + +issues: + exclude-use-default: false + max-issues-per-linter: 0 + max-same-issues: 0 + exclude-dirs: + - .asdf diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..71344ac --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,73 @@ +--- +before: + hooks: + - go mod tidy + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - darwin + ldflags: + - -s -w -X {{ .ModulePath }}/cmd.date={{ .CommitDate }} + - -X {{ .ModulePath }}/cmd.commit={{ .Commit }} + - -X {{ .ModulePath }}/cmd.version={{ .Version }} + - -X {{ .ModulePath }}/cmd.builtBy=goreleaser + - -X {{ .ModulePath }}/cmd.treestate={{ .IsGitDirty }} + +archives: + - format: binary +checksum: + name_template: 'checksums.txt' +snapshot: + name_template: "{{ incpatch .Version }}.dev" +changelog: + sort: asc + filters: + exclude: + - '^test:' + - "^chore" + - "merge conflict" + - Merge pull request + - Merge remote-tracking branch + - Merge branch + - go mod tidy + groups: + - title: "Features" + regexp: "^.*?feat:.*$" + order: 0 + - title: "Bug fixes" + regexp: "^.*?fix:.*$" + order: 1 + - title: "Chores" + regexp: "^.*?chore:.*$" + order: 2 + - title: "Docs" + regexp: "^.*?docs:.*$" + order: 3 + - title: "CI" + regexp: "^.*?ci:.*$" + order: 4 + - title: "Build" + regexp: "^.*?build:.*$" + order: 5 + - title: Others + order: 999 +brews: + - repository: + owner: retr0h + name: homebrew-tap + directory: Formula + goarm: "7" + homepage: https://github.com/retr0h/gilt + description: A GIT layering tool + license: MIT + test: | + system "#{bin}/goreleaser -v" + dependencies: + - name: go + type: optional + - name: git +universal_binaries: + - replace: true diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fe4bb51 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2024 John Dewey + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7424939 --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# Git URL Parse + +This project is a golang port of an old project of mine [git-url-parse][], +which was donated to [coala][]. + +It's usefulness may be limited, but I have a [fascination][] with revisiting +old projects. + +[git-url-parse]: https://github.com/coala/git-url-parse +[coala]: https://coala.io/#/home?lang=Python +[fascination]: https://retr0h.github.io/gilt/ + +## License + +The [MIT][] License. + +[MIT]: LICENSE diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 0000000..827bfdd --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,110 @@ +--- +version: "3" + +vars: + GIT_ROOT: + sh: git rev-parse --show-toplevel + MAIN_PACKAGE: main.go + +tasks: + deps: + desc: Install dependencies + cmds: + - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + - go install github.com/princjef/gomarkdoc/cmd/gomarkdoc@latest + - go install golang.org/x/vuln/cmd/govulncheck@latest + - go install github.com/jstemmer/go-junit-report@latest + - go install github.com/segmentio/golines@latest + - go install github.com/golang/mock/mockgen@latest + - go install github.com/boumenot/gocover-cobertura@latest + - go install mvdan.cc/gofumpt@latest + - go install github.com/goreleaser/goreleaser@latest + + deps:check: + desc: Check dependencies needed for development + cmds: + - echo "Dependency check OK" + preconditions: + - sh: "[ '{{OS}}' = 'darwin' ]" + msg: Operating System '{{OS}}' not supported + + - sh: command -v jq + msg: | + 'jq' not found in $PATH + + Suggested action: 'brew install jq' + + mod: + desc: Module maintenance + cmds: + - go mod download + - go mod tidy + + vet: + desc: Report likely mistakes in packages + cmds: + - $(go env GOPATH)/bin/golangci-lint run --config {{ .GIT_ROOT }}/.golangci.yml + + vuln: + desc: Run Go's vulnerability scanner + cmds: + - govulncheck ./... + + run: + desc: Compile and run Go program + cmds: + - go run {{ .MAIN_PACKAGE }} {{.CLI_ARGS}} + + unit: + desc: Test packages + cmds: + - go test -parallel 5 -race -v ./... + + unit:int: + desc: Integration test packages + cmds: + - + + test: + desc: Test all + cmds: + - task: deps + - task: mod + - task: fmt:check + - task: vet + - task: cov + - task: unit:int + + cov: + desc: Generate coverage + env: + # https://github.com/golang/go/issues/65570 + GOEXPERIMENT: nocoverageredesign + cmds: + - go test -race -coverprofile=cover.out -v $(go list ./... | grep -v /mocks) 2>&1 | go-junit-report --set-exit-code > result.xml || (cat result.xml && echo "fail" && exit 1) + - gocover-cobertura < cover.out > cobertura.xml + - go tool cover -func=cover.out + + cov:map: + desc: Generate coverage and show heatmap + cmds: + - task: cov + - go tool cover -html=cover.out + + fmt: + desc: Reformat files whose formatting differs from `go_fmt_command` + cmds: + - gofumpt -l -w . + - golines --base-formatter=gofumpt -w . + + fmt:check: + desc: Check files whose formatting differs from `go_fmt_command` + cmds: + # https://github.com/mvdan/gofumpt/issues/114 + - test -z "$(gofumpt -d -e . | tee /dev/stderr)" + - test -z "$(golines -l --dry-run --base-formatter=gofumpt -w .)" + + build: + desc: Build ARCH compatible binary. + cmds: + - goreleaser release --snapshot --clean diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9030d85 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/retr0h/git-url-parse + +go 1.22 diff --git a/main.go b/main.go new file mode 100644 index 0000000..7772117 --- /dev/null +++ b/main.go @@ -0,0 +1,21 @@ +// Copyright (c) 2024 John Dewey + +// 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. + +package main