diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..644cd0954 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [ckolkey] diff --git a/.github/workflows/automerge-nightly.yml b/.github/workflows/automerge-nightly.yml deleted file mode 100644 index 6a0822c1f..000000000 --- a/.github/workflows/automerge-nightly.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Automerge Nightly -on: - push: - branches: - - master - -jobs: - merge: - name: "Merge Master into Nightly" - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}" - - - name: perform merge - run: | - git config --global user.email "${GITHUB_ACTOR}" - git config --global user.name "${GITHUB_ACTOR}@users.noreply.github.com" - git status - git pull - git checkout master - git status - git checkout nightly - git reset --hard origin/nightly - git merge master --no-edit - git push - git status diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 17532bdd3..05eab19a8 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -12,13 +12,10 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: Swatinem/rust-cache@v2 - - uses: taiki-e/install-action@v2 with: tool: selene,typos-cli - - name: Run linters run: make lint @@ -32,3 +29,30 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} version: latest args: --color always --check lua/ tests/ + + ruby_lint: + name: Rubocop + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + - run: bundle exec rubocop + + lua_types: + name: lua-typecheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: Homebrew/actions/setup-homebrew@master + - run: brew install lua-language-server + - uses: luarocks/gh-actions-lua@v10 + with: + luaVersion: luajit + - uses: luarocks/gh-actions-luarocks@v5 + with: + luaRocksVersion: "3.12.1" + - run: | + luarocks install llscheck + llscheck lua/ diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c1b374c37..0a397c918 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,32 +9,39 @@ on: jobs: test: name: Test - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} strategy: matrix: release: [stable, nightly] + os: [ubuntu-latest] + env: + CI: "1" steps: - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + + - uses: rhysd/action-setup-vim@v1 + with: + neovim: true + version: ${{ matrix.release }} + - name: Install Dependencies run: | - mkdir -p ~/.local/share/neogit-test/site/pack/plenary.nvim/start - cd ~/.local/share/neogit-test/site/pack/plenary.nvim/start - git clone https://github.com/nvim-lua/plenary.nvim - - mkdir -p ~/.local/share/neogit-test/site/pack/telescope.nvim/start - cd ~/.local/share/neogit-test/site/pack/telescope.nvim/start - git clone https://github.com/nvim-telescope/telescope.nvim + git config --global core.compression 0 + git clone https://github.com/nvim-lua/plenary.nvim tmp/plenary + git clone https://github.com/nvim-telescope/telescope.nvim tmp/telescope + git clone https://github.com/sindrets/diffview.nvim tmp/diffview + git clone https://github.com/nvim-telescope/telescope-fzf-native.nvim tmp/telescope-fzf-native + cd tmp/telescope-fzf-native + make - - name: Install Neovim + - name: E2E Test run: | - wget https://github.com/neovim/neovim/releases/download/${{ matrix.release }}/nvim-linux64.tar.gz - tar -zxf nvim-linux64.tar.gz - sudo ln -s $(pwd)/nvim-linux64/bin/nvim /usr/local/bin + bundle exec rspec - - name: Test - continue-on-error: false - env: - ci: "1" + - name: Unit Test run: | make test diff --git a/.gitignore b/.gitignore index 6bfce6717..5e39200ec 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ doc/tags # Environment .envrc +/tests/.min/* diff --git a/.luarc.json b/.luarc.json index b03227d4b..3a2495a62 100644 --- a/.luarc.json +++ b/.luarc.json @@ -1,6 +1,6 @@ { - "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json", - "Lua.diagnostics.disable": [ + "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json", + "diagnostics.disable": [ "redefined-local" ], "diagnostics.globals": [ @@ -9,5 +9,6 @@ "describe", "before_each" ], - "workspace.checkThirdParty": "Disable", + "workspace.checkThirdParty": false, + "runtime.version": "LuaJIT" } diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 000000000..52c146b09 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,17 @@ +require: + - rubocop-rspec +AllCops: + NewCops: enable + TargetRubyVersion: 3.3.1 +Style/StringLiterals: + EnforcedStyle: double_quotes +RSpec/DescribeClass: + Enabled: false +RSpec/MultipleExpectations: + Enabled: false +RSpec/ExampleLength: + Enabled: false +RSpec/NestedGroups: + Enabled: false +Style/NestedModifier: + Enabled: false diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 000000000..9c25013db --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.3.6 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7f021274d..10fd3df64 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,3 @@ -> [!IMPORTANT] -> Until neovim 0.10 is released, please base any changes on the `nightly` branch. - # Contributing Contributions of all kinds are very welcome. If you are planning to implement a larger feature please open an issue @@ -53,15 +50,30 @@ Simply clone *Neogit* to your project directory of choice to be able to use your Logging is a useful tool for inspecting what happens in the code and in what order. Neogit uses [`Plenary`](https://github.com/nvim-lua/plenary.nvim) for logging. -Export the environment variables `NEOGIT_LOG_CONSOLE="sync"` to enable logging, and `NEOGIT_LOG_LEVEL="debug"` for more -verbose logging. +#### Enabling logging via environment variables + +- To enable logging to console, export `NEOGIT_LOG_CONSOLE="sync"` +- To enable logging to a file, export `NEOGIT_LOG_FILE="true"` +- For more verbose logging, set the log level to `debug` via `NEOGIT_LOG_LEVEL="debug"` + +#### Enabling logging via lua api + +To turn on logging while neovim is already running, you can use: + +```lua +:lua require("neogit.logger").config.use_file = true -- for logs to ~/.cache/nvim/neogit.log. +:lua require("neogit.logger").config.use_console = true -- for logs to console. +:lua require("neogit.logger").config.level = 'debug' -- to set the log level +``` +#### Using the logger from the neogit codebase ```lua local logger = require("neogit.logger") -logger.fmt_info("This is a log message: %d", 2) -logger.fmt_debug("This is a verbose log message: %q", status) +logger.info("This is a log message") +logger.debug(("This is a verbose log message: %q"):format(str_to_quote)) +logger.debug(("This is a verbose log message: %s"):format(vim.inspect(thing))) ``` If suitable, prefer to scope your logs using `[ SCOPE ]` to make it easier to find the source of a message, such as: @@ -76,7 +88,7 @@ rather than: ### Testing -Neogit is tested using [`Plenary`](https://github.com/nvim-lua/plenary.nvim#plenarytest_harness). +Neogit is tested using [`Plenary`](https://github.com/nvim-lua/plenary.nvim#plenarytest_harness) for unit tests, and `rspec` (yes, ruby) for e2e tests. It uses a *Busted* style testing, where each lua file inside [`./tests/specs/{test_name}_spec.lua`] is run. @@ -101,9 +113,11 @@ See [the test documentation for more details](./tests/README.md). ### Linting Additionally, linting is enforced using `selene` to catch common errors, most of which are also caught by -`lua-language-server`. +`lua-language-server`. Source code spell checking is done via `typos`. -```sh make lint ``` +```sh +make lint +``` ### Formatting diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..e906795c1 --- /dev/null +++ b/Gemfile @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +ruby File.read(".ruby-version").strip + +source "https://rubygems.org" + +gem "activesupport" +gem "amazing_print" +gem "debug" +gem "fuubar" +gem "git" +gem "neovim" +gem "pastel" +gem "quickfix_formatter" +gem "rspec" +gem "rubocop" +gem "rubocop-performance" +gem "rubocop-rspec" +gem "super_diff" +gem "tmpdir" + +gem "lefthook", "~> 1.7" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 000000000..212087ae9 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,154 @@ +GEM + remote: https://rubygems.org/ + specs: + activesupport (7.2.0) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + amazing_print (1.6.0) + ast (2.4.2) + attr_extras (7.1.0) + base64 (0.2.0) + bigdecimal (3.1.8) + concurrent-ruby (1.3.4) + connection_pool (2.4.1) + debug (1.9.2) + irb (~> 1.10) + reline (>= 0.3.8) + diff-lcs (1.5.1) + drb (2.2.1) + fileutils (1.7.2) + fuubar (2.5.1) + rspec-core (~> 3.0) + ruby-progressbar (~> 1.4) + git (2.1.1) + activesupport (>= 5.0) + addressable (~> 2.8) + process_executer (~> 1.1) + rchardet (~> 1.8) + i18n (1.14.5) + concurrent-ruby (~> 1.0) + io-console (0.7.2) + irb (1.14.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + json (2.7.2) + language_server-protocol (3.17.0.3) + lefthook (1.7.22) + logger (1.6.0) + minitest (5.25.1) + msgpack (1.7.2) + multi_json (1.15.0) + neovim (0.10.0) + msgpack (~> 1.1) + multi_json (~> 1.0) + optimist (3.1.0) + parallel (1.26.3) + parser (3.3.4.2) + ast (~> 2.4.1) + racc + pastel (0.8.0) + tty-color (~> 0.5) + patience_diff (1.2.0) + optimist (~> 3.0) + process_executer (1.1.0) + psych (5.1.2) + stringio + public_suffix (6.0.1) + quickfix_formatter (0.1.0) + rspec (>= 3.12.0) + racc (1.8.1) + rainbow (3.1.1) + rchardet (1.8.0) + rdoc (6.7.0) + psych (>= 4.0.0) + regexp_parser (2.9.2) + reline (0.5.9) + io-console (~> 0.5) + rexml (3.3.5) + strscan + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.2) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + rubocop (1.65.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.4, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.32.1) + parser (>= 3.3.1.0) + rubocop-performance (1.21.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rspec (3.0.4) + rubocop (~> 1.61) + ruby-progressbar (1.13.0) + securerandom (0.3.1) + stringio (3.1.1) + strscan (3.1.0) + super_diff (0.12.1) + attr_extras (>= 6.2.4) + diff-lcs + patience_diff + tmpdir (0.2.0) + fileutils + tty-color (0.6.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.5.0) + +PLATFORMS + arm64-darwin-22 + arm64-darwin-23 + arm64-darwin-24 + x64-mingw-ucrt + x86_64-darwin-20 + x86_64-linux + +DEPENDENCIES + activesupport + amazing_print + debug + fuubar + git + lefthook (~> 1.7) + neovim + pastel + quickfix_formatter + rspec + rubocop + rubocop-performance + rubocop-rspec + super_diff + tmpdir + +RUBY VERSION + ruby 3.3.6p108 + +BUNDLED WITH + 2.5.23 diff --git a/Makefile b/Makefile index eba24cd05..19efec42a 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,17 @@ test: - LUA_PATH="./?.lua" TEST_FILES=$$TEST_FILES NEOGIT_LOG_LEVEL=error NEOGIT_LOG_CONSOLE="sync" GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null NVIM_APPNAME=neogit-test nvim --headless -S "./tests/init.lua" + TEMP_DIR=$$TEMP_DIR TEST_FILES=$$TEST_FILES GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null NVIM_APPNAME=neogit-test nvim --headless -S "./tests/init.lua" + +specs: + bundle install && CI=1 bundle exec rspec --format Fuubar lint: selene --config selene/config.toml lua typos -lint-short: - selene --config selene/config.toml --display-style Quiet lua +format: + stylua . + +typecheck: + llscheck lua/ -.PHONY: lint test +.PHONY: format lint typecheck diff --git a/README.md b/README.md index 5513edb39..fbe5393e8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ +