diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 935db01..5648bd4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,6 @@ jobs: - run: go version - - name: Run test - run: make + - name: Run tests and build + run: make test build shell: bash diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..6d6cc37 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,23 @@ +name: golangci-lint +on: + push: + tags: + - v* + branches: + - master + - main + pull_request: +permissions: + contents: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/setup-go@v2 + - uses: actions/checkout@v2 + - name: golangci-lint + uses: golangci/golangci-lint-action@v2 + with: + version: latest diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..b7776b6 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,27 @@ +run: + tests: false + +issues: + max-issues-per-linter: 0 + max-same-issues: 0 + +linters: + enable: + - bodyclose + - dupl + - exportloopref + - goconst + - godot + - godox + - goimports + - revive + - goprintffuncname + - gosec + - ifshort + - misspell + - prealloc + - rowserrcheck + - sqlclosecheck + - unconvert + - unparam + - whitespace diff --git a/Makefile b/Makefile index ae1b0d2..8e5854c 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ .PHONY: lint lint: - go vet ./... + golangci-lint run .PHONY: build build: diff --git a/cmd/ogit/main.go b/cmd/ogit/main.go index 1fa9352..438d52b 100644 --- a/cmd/ogit/main.go +++ b/cmd/ogit/main.go @@ -5,6 +5,7 @@ import ( "log" "os" + _ "github.com/mattn/go-sqlite3" "github.com/wmalik/ogit/internal/browser" "github.com/wmalik/ogit/internal/bulkclone" "github.com/wmalik/ogit/internal/clear" @@ -13,7 +14,7 @@ import ( "github.com/urfave/cli/v2" ) -// ldflags populated by goreleaser +// ldflags populated by goreleaser. var ( version = "" commit = "" @@ -149,8 +150,7 @@ func main() { }, } - err := app.Run(os.Args) - if err != nil { + if err := app.Run(os.Args); err != nil { log.Fatal(err) } } diff --git a/go.mod b/go.mod index e7f19bc..9613141 100644 --- a/go.mod +++ b/go.mod @@ -22,8 +22,8 @@ require ( ) require ( - github.com/Microsoft/go-winio v0.4.16 // indirect - github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect + github.com/Microsoft/go-winio v0.5.2 // indirect + github.com/ProtonMail/go-crypto v0.0.0-20220113124808-70ae35bab23f // indirect github.com/acomagu/bufpipe v1.0.3 // indirect github.com/atotto/clipboard v0.1.4 // indirect github.com/containerd/console v1.0.3 // indirect @@ -40,7 +40,7 @@ require ( github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.4 // indirect - github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect + github.com/kevinburke/ssh_config v1.1.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect @@ -52,14 +52,14 @@ require ( github.com/rivo/uniseg v0.2.0 // indirect github.com/russross/blackfriday/v2 v2.0.1 // indirect github.com/sahilm/fuzzy v0.1.0 // indirect - github.com/sergi/go-diff v1.1.0 // indirect + github.com/sergi/go-diff v1.2.0 // indirect github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect - github.com/xanzy/ssh-agent v0.3.0 // indirect - golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect - golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 // indirect - golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect + github.com/xanzy/ssh-agent v0.3.1 // indirect + golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd // indirect + golang.org/x/net v0.0.0-20220225172249-27dd8689420f // indirect + golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf // indirect golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect - golang.org/x/text v0.3.6 // indirect + golang.org/x/text v0.3.7 // indirect golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect google.golang.org/appengine v1.6.6 // indirect google.golang.org/protobuf v1.26.0 // indirect diff --git a/go.sum b/go.sum index 7f002a9..29cb576 100644 --- a/go.sum +++ b/go.sum @@ -34,10 +34,13 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= -github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk= github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= -github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 h1:YoJbenK9C67SkzkDfmQuVln04ygHj3vjZfd9FL+GmQQ= +github.com/Microsoft/go-winio v0.5.0/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpzfwIujj1a84= +github.com/Microsoft/go-winio v0.5.2 h1:a9IhgEQBCUEk6QCdml9CiJGhAws+YwffDHEMp1VMrpA= +github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo= +github.com/ProtonMail/go-crypto v0.0.0-20220113124808-70ae35bab23f h1:J2FzIrXN82q5uyUraeJpLIm7U6PffRwje2ORho5yIik= +github.com/ProtonMail/go-crypto v0.0.0-20220113124808-70ae35bab23f/go.mod h1:z4/9nQmJSSwwds7ejkxaJwO37dru3geImFUdJlaLzQo= github.com/acomagu/bufpipe v1.0.3 h1:fxAGrHZTgQ9w5QqVItgzwj235/uYZYgbXitB+dLupOk= github.com/acomagu/bufpipe v1.0.3/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239 h1:kFOfPq6dUM1hTo4JG6LR5AXSUEsOjtdm0kw0FtQtMJA= @@ -173,8 +176,9 @@ github.com/jinzhu/now v1.1.4 h1:tHnRBy1i5F2Dh8BAFxqFzxKqqvezXrL2OW1TnX+Mlas= github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 h1:DowS9hvgyYSX4TO5NpyC606/Z4SxnNYbT+WX27or6Ck= github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/kevinburke/ssh_config v1.1.0 h1:pH/t1WS9NzT8go394IqZeJTMHVm6Cr6ZJ6AQ+mdNo/o= +github.com/kevinburke/ssh_config v1.1.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= @@ -239,11 +243,13 @@ github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0 github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI= github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= -github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= +github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q= +github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -257,8 +263,9 @@ github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/xanzy/go-gitlab v0.54.3 h1:fPfZ3Jcu5dPc3xyIYtAALZsEgoyKNFNuULD+TdJ7Zvk= github.com/xanzy/go-gitlab v0.54.3/go.mod h1:F0QEXwmqiBUxCgJm8fE9S+1veX4XC9Z4cfaAbqwk4YM= -github.com/xanzy/ssh-agent v0.3.0 h1:wUMzuKtKilRgBAD1sUb8gOwwRr2FGoBVumcjoOACClI= github.com/xanzy/ssh-agent v0.3.0/go.mod h1:3s9xbODqPuuhK9JV1R321M/FlMZSBvE5aY6eAcqrDh0= +github.com/xanzy/ssh-agent v0.3.1 h1:AmzO1SSWxw73zxFZPRwaMN1MohDw8UyHnmuxyceTEGo= +github.com/xanzy/ssh-agent v0.3.1/go.mod h1:QIE4lCeL7nkC25x+yA3LBIYfwCc1TFziCtG7cBAac6w= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -275,8 +282,10 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd h1:XcWmESyNjXJMLahc3mqVQJcgSTDxFxhETVlfk9uGc38= +golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -338,8 +347,10 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k= -golang.org/x/net v0.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= +golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= +golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -373,6 +384,7 @@ golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -401,8 +413,9 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210502180810-71e4cd670f79/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 h1:y/woIyUBFbpQGKS0u1aHF/40WUDnek3fPOyD08H5Vng= -golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf h1:Fm4IcnUL803i92qDlmB0obyHmosDrxZWxJL3gIeNqOw= +golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210422114643-f5beecf764ed/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= @@ -412,8 +425,9 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs= diff --git a/internal/browser/init.go b/internal/browser/init.go index 2da1c8d..258a54f 100644 --- a/internal/browser/init.go +++ b/internal/browser/init.go @@ -2,6 +2,6 @@ package browser import tea "github.com/charmbracelet/bubbletea" -func (m model) Init() tea.Cmd { +func (m Model) Init() tea.Cmd { return nil } diff --git a/internal/browser/model.go b/internal/browser/model.go index 6167d80..4876638 100644 --- a/internal/browser/model.go +++ b/internal/browser/model.go @@ -7,18 +7,16 @@ import ( "github.com/wmalik/ogit/internal/db" "github.com/wmalik/ogit/internal/gitutils" - "github.com/wmalik/ogit/service" "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/list" ) -// The state of browser -type model struct { +// The state of browser. +type Model struct { // the list of repositories list list.Model // list of organisations or users (currently only public users or organisations) - orgs []string // the path on disk where repositories should be cloned storagePath string // A status bar to show useful information e.g. Github API usage @@ -29,20 +27,18 @@ type model struct { spawnShell bool gu *gitutils.GitUtils - rs *service.RepositoryService } -func NewModelWithItems(repos []db.Repository, storagePath string, gu *gitutils.GitUtils) *model { - +func NewModelWithItems(repos []db.Repository, storagePath string, gu *gitutils.GitUtils) *Model { listItems := sortItemsCloned(toItems(repos, storagePath)) - m := list.NewModel(listItems, listItemDelegate(storagePath), 0, 0) + m := list.NewModel(listItems, listItemDelegate(), 0, 0) m.StatusMessageLifetime = time.Second * 60 m.Title = fmt.Sprintf("[ogit] [%s]", storagePath) m.Styles.Title = titleBarStyle m.AdditionalShortHelpKeys = availableKeyBindingsCB m.SetShowStatusBar(false) - return &model{ + return &Model{ list: m, storagePath: storagePath, bottomStatusBar: "-", diff --git a/internal/browser/style.go b/internal/browser/style.go index 268cc80..b8635e1 100644 --- a/internal/browser/style.go +++ b/internal/browser/style.go @@ -9,8 +9,6 @@ var appStyle = lipgloss.NewStyle().Align(lipgloss.Center).PaddingLeft(5).Padding var bottomStatusBarStyle = lipgloss.NewStyle().Height(1).Faint(true) -var spinnerStyle = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#0000ff", Dark: "#000099"}) - var brightStyle = lipgloss.NewStyle(). Foreground(lipgloss.AdaptiveColor{Light: "#1a1a1a", Dark: "#dddddd"}) diff --git a/internal/browser/update.go b/internal/browser/update.go index d155f01..0cd35f2 100644 --- a/internal/browser/update.go +++ b/internal/browser/update.go @@ -13,7 +13,7 @@ import ( tea "github.com/charmbracelet/bubbletea" ) -func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { +func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds := []tea.Cmd{} selected, ok := m.list.SelectedItem().(repoItem) if !ok && len(m.list.VisibleItems()) > 0 { @@ -22,7 +22,7 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { if m.list.FilterState() != list.Filtering { cmds = append(cmds, handleKeyMsg(msg, m, selected)) - cmds = append(cmds, handleMsg(msg, m, selected)) + cmds = append(cmds, handleMsg(msg, m)) } newListModel, cmd := m.list.Update(msg) @@ -31,7 +31,7 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return m, tea.Batch(append(cmds, cmd)...) } -func handleMsg(msg tea.Msg, m *model, selected repoItem) tea.Cmd { +func handleMsg(msg tea.Msg, m *Model) tea.Cmd { cmds := []tea.Cmd{} switch msg := msg.(type) { case tea.WindowSizeMsg: @@ -78,12 +78,11 @@ func handleMsg(msg tea.Msg, m *model, selected repoItem) tea.Cmd { } return nil }) - } return tea.Batch(cmds...) } -func handleKeyMsg(msg tea.Msg, m *model, selected repoItem) tea.Cmd { +func handleKeyMsg(msg tea.Msg, m *Model, selected repoItem) tea.Cmd { cmds := []tea.Cmd{} switch msg := msg.(type) { case tea.KeyMsg: @@ -96,7 +95,7 @@ func handleKeyMsg(msg tea.Msg, m *model, selected repoItem) tea.Cmd { ) } } - rangerCmd := exec.Command("xdg-open", selected.StoragePath()) + rangerCmd := exec.Command("xdg-open", selected.StoragePath()) //nolint:gosec rangerCmd.Stdin = os.Stdin rangerCmd.Stdout = os.Stdout if err := rangerCmd.Run(); err != nil { @@ -116,7 +115,7 @@ func handleKeyMsg(msg tea.Msg, m *model, selected repoItem) tea.Cmd { ) } } - vimCmd := exec.Command("vim", selected.StoragePath()) + vimCmd := exec.Command("vim", selected.StoragePath()) //nolint:gosec vimCmd.Stdin = os.Stdin vimCmd.Stdout = os.Stdout if err := vimCmd.Run(); err != nil { @@ -161,8 +160,8 @@ func handleKeyMsg(msg tea.Msg, m *model, selected repoItem) tea.Cmd { return tea.Batch(cmds...) } -// listItemDelegate configures general behaviour/styling of the list items -func listItemDelegate(storagePath string) list.DefaultDelegate { +// listItemDelegate configures general behaviour/styling of the list items. +func listItemDelegate() list.DefaultDelegate { d := list.NewDefaultDelegate() d.Styles.NormalTitle = d.Styles.NormalTitle.Foreground(dimmedColor) d.Styles.SelectedTitle = d.Styles.SelectedTitle.UnsetForeground().Background(selectedColor) diff --git a/internal/browser/view.go b/internal/browser/view.go index 8898372..4317dc4 100644 --- a/internal/browser/view.go +++ b/internal/browser/view.go @@ -4,7 +4,7 @@ import ( "github.com/charmbracelet/lipgloss" ) -func (m model) View() string { +func (m Model) View() string { return lipgloss.JoinVertical(lipgloss.Left, appStyle.Render(m.list.View()), bottomStatusBarStyle.Render(m.bottomStatusBar), diff --git a/internal/db/db.go b/internal/db/db.go index 9d72ef8..b5e62b0 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -3,7 +3,6 @@ package db import ( "context" - _ "github.com/mattn/go-sqlite3" "gorm.io/driver/sqlite" "gorm.io/gorm" "gorm.io/gorm/clause" diff --git a/internal/gitconfig/gitconfig.go b/internal/gitconfig/gitconfig.go index ef08541..a10c7b2 100644 --- a/internal/gitconfig/gitconfig.go +++ b/internal/gitconfig/gitconfig.go @@ -28,9 +28,8 @@ func defaultGitConfig() *GitConfig { } } -// readGitConfig loads the value of ogit.orgs from ~/.gitconfig +// readGitConfig loads the value of ogit.orgs from ~/.gitconfig. func ReadGitConfig() (*GitConfig, error) { - conf := defaultGitConfig() orgs, err := getOrgs() @@ -61,7 +60,7 @@ func ReadGitConfig() (*GitConfig, error) { if err != nil { return nil, err } - if fetchUserRepos == false { + if !fetchUserRepos { conf.fetchUserRepos = false } @@ -69,7 +68,7 @@ func ReadGitConfig() (*GitConfig, error) { if err != nil { return nil, err } - if useSSHAgent != true { + if !useSSHAgent { conf.useSSHAgent = useSSHAgent } if privKeyPath != "" { diff --git a/internal/gitutils/clone.go b/internal/gitutils/clone.go index a2f2a19..476343e 100644 --- a/internal/gitutils/clone.go +++ b/internal/gitutils/clone.go @@ -15,7 +15,7 @@ import ( "github.com/go-git/go-git/v5/plumbing/transport/ssh" ) -var ErrRepoAlreadyCloned error = errors.New("Repository already cloned") +var ErrRepoAlreadyCloned = errors.New("Repository already cloned") type commitInfo struct { AuthorName string @@ -88,7 +88,7 @@ func (r *Repository) LastCommit() string { // a fully cloned repository. // If an authentication method has been configured, the repository is cloned // using sshURL, otherwise it is cloned using httpsURL. The progress of the -// clone operation is streamed to the progress io.Writer +// clone operation is streamed to the progress io.Writer. func (gu *GitUtils) CloneToDisk(ctx context.Context, httpsURL, sshURL, path string, progress io.Writer) (string, error) { cloneURL := sshURL if gu.cloneOverHTTPS { @@ -147,7 +147,7 @@ func (gu *GitUtils) CloneToDisk(ctx context.Context, httpsURL, sshURL, path stri return repository.String(), nil } -// Cloned checks if a path contains a .git directory +// Cloned checks if a path contains a .git directory. func Cloned(dir string) (bool, error) { if _, err := os.Stat(path.Join(dir, ".git")); err != nil { if errors.Is(err, os.ErrNotExist) { diff --git a/internal/gitutils/read.go b/internal/gitutils/read.go index c904030..e54a3cd 100644 --- a/internal/gitutils/read.go +++ b/internal/gitutils/read.go @@ -33,5 +33,4 @@ func ReadRepository(path string) (*Repository, error) { When: commitObject.Author.When, }, }, nil - } diff --git a/internal/repocommands/url.go b/internal/repocommands/url.go index c2e5bd2..74af1a1 100644 --- a/internal/repocommands/url.go +++ b/internal/repocommands/url.go @@ -14,7 +14,7 @@ import ( type Command int32 -// Various command types supported by HandleURLCommands +// Various command types supported by HandleURLCommands. const ( Pulls Command = iota Web @@ -25,7 +25,7 @@ const ( Settings ) -// HandleURLCommands opens the relevant URL in the web browser +// HandleURLCommands opens the relevant URL in the web browser. func HandleURLCommands(ctx context.Context, command Command) error { repo, err := findRepositoryCWD(ctx) if err != nil { diff --git a/internal/shell/shell.go b/internal/shell/shell.go index 4f1499d..e20a65f 100644 --- a/internal/shell/shell.go +++ b/internal/shell/shell.go @@ -16,7 +16,7 @@ func Spawn(dir string) error { return runProcess(shell, dir, "-i") } -// runProcess starts a process in a certain directory, and waits for it to exit +// runProcess starts a process in a certain directory, and waits for it to exit. func runProcess(name string, dir string, args ...string) error { proc, err := os.StartProcess( name, diff --git a/internal/sync/sync.go b/internal/sync/sync.go index 7a42f43..b76bbf5 100644 --- a/internal/sync/sync.go +++ b/internal/sync/sync.go @@ -14,7 +14,7 @@ import ( ) // Sync fetches the repository metadata from upstream and stores it in the local -// database (on disk) +// database (on disk). func Sync(ctx context.Context, gitConf *gitconfig.GitConfig) error { gitlabClient, err := upstream.NewGitlabClientWithToken(os.Getenv("GITLAB_TOKEN")) if err != nil { @@ -72,5 +72,4 @@ func toDatabaseRepositories(repos *service.Repositories) []db.Repository { } return dbRepos - } diff --git a/mock/http_client_mock.go b/mock/http_client_mock.go index c7478c2..6f59ccc 100644 --- a/mock/http_client_mock.go +++ b/mock/http_client_mock.go @@ -20,19 +20,19 @@ type HTTPClient struct { routesFinalized bool } -// roundTripperMocked is a mocked RoundTripper for mocking responses from external services +// roundTripperMocked is a mocked RoundTripper for mocking responses from external services. type roundTripperMocked struct { mux *mux.Router } -// NewHTTPClient returns an HTTPClient with no routes defined +// NewHTTPClient returns an HTTPClient with no routes defined. func NewHTTPClient() *HTTPClient { return &HTTPClient{ roundTripper: &roundTripperMocked{mux.NewRouter()}, } } -// Client returns the mocked HTTP Client instance +// Client returns the mocked HTTP Client instance. func (hc *HTTPClient) Client() *http.Client { if !hc.routesFinalized { // Register a wildcard route to warn for calls to unknown routes @@ -45,14 +45,14 @@ func (hc *HTTPClient) Client() *http.Client { return &http.Client{Transport: hc.roundTripper} } -// RoundTrip implements the RoundTrip method of RoundTripper for mocking purposes +// RoundTrip implements the RoundTrip method of RoundTripper for mocking purposes. func (rt roundTripperMocked) RoundTrip(r *http.Request) (*http.Response, error) { w := httptest.NewRecorder() rt.mux.ServeHTTP(w, r) return w.Result(), nil } -// Mock registers an HTTP handler for the provided method and path +// Mock registers an HTTP handler for the provided method and path. func (hc *HTTPClient) Mock(method, path string, handler http.HandlerFunc) *HTTPClient { if hc.routesFinalized { panic("http_client: Mock() cannot be called after Client()") diff --git a/service/repository.go b/service/repository.go index 3d0f2b2..d698773 100644 --- a/service/repository.go +++ b/service/repository.go @@ -62,7 +62,6 @@ func (r *RepositoryService) GetRepositoriesByOwners(ctx context.Context, owners res[i].SettingsURL = repo.GetSettingsURL() res[i].HTTPSCloneURL = repo.GetHTTPSCloneURL() res[i].SSHCloneURL = repo.GetSSHCloneURL() - } return &res, nil } diff --git a/upstream/repository_host_github.go b/upstream/repository_host_github.go index 5e43499..fff8be3 100644 --- a/upstream/repository_host_github.go +++ b/upstream/repository_host_github.go @@ -133,7 +133,6 @@ func (c *GithubClient) GetRepositories(ctx context.Context, owners []string, fet if err.Error() != "not found" { return err } - } if len(repos) == 0 { @@ -227,7 +226,7 @@ func (c *GithubClient) getRepositoriesForOrg(ctx context.Context, org string, st return repos, nil } -// setUserInfo fetches the authenticated user's information and stores it +// setUserInfo fetches the authenticated user's information and stores it. func (c *GithubClient) setUserInfo(ctx context.Context) error { user, _, err := c.client.Users.Get(ctx, "") if err != nil { diff --git a/upstream/repository_host_gitlab.go b/upstream/repository_host_gitlab.go index b38a640..2b1102c 100644 --- a/upstream/repository_host_gitlab.go +++ b/upstream/repository_host_gitlab.go @@ -100,7 +100,7 @@ func (c *GitlabClient) GetRepositories(ctx context.Context, groups []string, fet res := HostRepositories{} var m sync.Map - if err := c.setUserInfo(ctx); err != nil { + if err := c.setUserInfo(); err != nil { return nil, err } @@ -108,9 +108,9 @@ func (c *GitlabClient) GetRepositories(ctx context.Context, groups []string, fet var g errgroup.Group if fetchUserRepos { - g.Go(func(ctx context.Context) func() error { + g.Go(func() func() error { return func() error { - userProjects, err := c.getProjectsForAuthUser(ctx, c.userID, c.username) + userProjects, err := c.getProjectsForAuthUser(c.userID, c.username) if err != nil { return err } @@ -118,13 +118,13 @@ func (c *GitlabClient) GetRepositories(ctx context.Context, groups []string, fet m.Store(c.username, userProjects) return nil } - }(ctx)) + }()) } for _, group := range groups { g.Go(func(group string) func() error { return func() error { - repos, err := c.getProjectsForGroup(ctx, group) + repos, err := c.getProjectsForGroup(group) if err != nil { return err } @@ -147,7 +147,7 @@ func (c *GitlabClient) GetRepositories(ctx context.Context, groups []string, fet return res.DeDuplicate(), nil } -func (c *GitlabClient) getProjectsForAuthUser(ctx context.Context, userID int, username string) ([]HostRepository, error) { +func (c *GitlabClient) getProjectsForAuthUser(userID int, username string) ([]HostRepository, error) { opt := &gitlab.ListProjectsOptions{ ListOptions: gitlab.ListOptions{ PerPage: gitlabPageSize, @@ -160,7 +160,7 @@ func (c *GitlabClient) getProjectsForAuthUser(ctx context.Context, userID int, u // Get the first page with projects. projects, resp, err := c.client.Projects.ListUserProjects(userID, opt) if err != nil { - log.Fatal(err) + return nil, err } logPaginationStatus(gitlabUpstream, username, len(projects), resp.TotalPages-resp.NextPage-1, resp.Header.Get("RateLimit-Remaining")) @@ -181,7 +181,7 @@ func (c *GitlabClient) getProjectsForAuthUser(ctx context.Context, userID int, u return repos, nil } -func (c *GitlabClient) getProjectsForGroup(ctx context.Context, group string) ([]HostRepository, error) { +func (c *GitlabClient) getProjectsForGroup(group string) ([]HostRepository, error) { opt := &gitlab.ListGroupProjectsOptions{ ListOptions: gitlab.ListOptions{ PerPage: gitlabPageSize, @@ -217,8 +217,8 @@ func (c *GitlabClient) getProjectsForGroup(ctx context.Context, group string) ([ return repos, nil } -// setUserInfo fetches the authenticated user's information and stores it -func (c *GitlabClient) setUserInfo(ctx context.Context) error { +// setUserInfo fetches the authenticated user's information and stores it. +func (c *GitlabClient) setUserInfo() error { user, _, err := c.client.Users.CurrentUser() if err != nil { return err