From 44e95a31e5619be868fcb931028d11eea61f294e Mon Sep 17 00:00:00 2001 From: Matthew Hutchinson Date: Sun, 29 Dec 2024 23:27:30 +0000 Subject: [PATCH] add rubocop, apply fixes, push with bundler, prep for new release --- .github/workflows/build.yml | 34 ------------- .github/workflows/ci.yml | 56 ++++++++++++++++++++++ .github/workflows/push_gem.yml | 25 ---------- .quickhook/pre-commit/ruby-lint | 3 ++ .rubocop.yml | 2 + CHANGELOG.md | 9 +++- Gemfile | 6 ++- PULL_REQUEST_TEMPLATE.md | 16 ------- README.md | 42 ++++++++-------- Rakefile | 2 +- bin/rubocop | 5 ++ lib/lolcommits/plugin/term_output.rb | 17 ++++--- lib/lolcommits/term_output.rb | 4 +- lib/lolcommits/term_output/version.rb | 2 +- lolcommits-term_output.gemspec | 6 +-- test/lolcommits/plugin/term_output_test.rb | 25 +++++----- test/test_helper.rb | 12 ++--- 17 files changed, 130 insertions(+), 136 deletions(-) delete mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/push_gem.yml create mode 100755 .quickhook/pre-commit/ruby-lint create mode 100644 .rubocop.yml delete mode 100644 PULL_REQUEST_TEMPLATE.md create mode 100755 bin/rubocop diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 19d0d2f..0000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Tests - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -permissions: - contents: read - -jobs: - test: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - ruby-version: ['3.1', '3.2', '3.3', '3.4'] - steps: - - uses: actions/checkout@v4 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true - - name: Configure git user name, email - run: | - git config --global user.name $NAME - git config --global user.email $EMAIL - env: - NAME: "George Costanza" - EMAIL: "george.costanza@vandelay.com" - - name: Run tests - run: bundle exec rake test diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..662a8fd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,56 @@ +name: CI +permissions: + contents: read + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + rubocop: + name: RuboCop + runs-on: ubuntu-latest + env: + BUNDLE_ONLY: rubocop + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Ruby and install gems + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.3.0 + bundler-cache: true + - name: Run Rubocop + run: bundle exec rubocop --parallel + test: + name: ${{ format('Unit tests (Ruby {0})', matrix.ruby-version) }} + runs-on: ubuntu-latest + strategy: + matrix: + ruby-version: + - "3.1" + - "3.2" + - "3.3" + - "3.4" + continue-on-error: true + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Ruby and install gems + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + bundler-cache: true + - name: Configure Git + run: | + git config --global user.name $NAME + git config --global user.email $EMAIL + env: + NAME: "George Costanza" + EMAIL: "george.costanza@vandelay.com" + - name: Run tests + run: bundle exec rake test diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml deleted file mode 100644 index d974f13..0000000 --- a/.github/workflows/push_gem.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Publish gem to RubyGems.org - -on: - push: - tags: - - v* - -jobs: - push: - name: Push gem to RubyGems.org - runs-on: ubuntu-latest - - permissions: - id-token: write - contents: write - - steps: - - uses: actions/checkout@v4 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - bundler-cache: true - ruby-version: ruby - - - uses: rubygems/release-gem@v1 diff --git a/.quickhook/pre-commit/ruby-lint b/.quickhook/pre-commit/ruby-lint new file mode 100755 index 0000000..fcf3f0f --- /dev/null +++ b/.quickhook/pre-commit/ruby-lint @@ -0,0 +1,3 @@ +#!/bin/sh +set -e +grep -E "\.rb$|Rakefile|Gemfile" | xargs ./bin/rubocop --config .rubocop.yml --force-exclusion diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..dc9c9b4 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,2 @@ +inherit_gem: + rubocop-rails-omakase: rubocop.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index e47d611..b48421c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ project adheres to [Semantic Versioning][Semver]. - Your contribution here! +## [0.5.1] - 2024-12-29 +### Changed +- Push gems with bundler (not GitHub actions) +- Updated documentation links + ## [0.5.0] - 2024-09-24 ### Removed - Support for Ruby < 3.1 (older rubies no longer supported) @@ -68,7 +73,8 @@ project adheres to [Semantic Versioning][Semver]. ### Changed - Initial release -[Unreleased]: https://github.com/lolcommits/lolcommits-term_output/compare/v0.5.0...HEAD +[Unreleased]: https://github.com/lolcommits/lolcommits-term_output/compare/v0.5.1...HEAD +[0.5.1]: https://github.com/lolcommits/lolcommits-term_output/compare/v0.5.0...v0.5.1 [0.5.0]: https://github.com/lolcommits/lolcommits-term_output/compare/v0.4.0...v0.5.0 [0.4.0]: https://github.com/lolcommits/lolcommits-term_output/compare/v0.3.0...v0.4.0 [0.3.0]: https://github.com/lolcommits/lolcommits-term_output/compare/v0.2.0...v0.3.0 @@ -82,4 +88,3 @@ project adheres to [Semantic Versioning][Semver]. [0.0.2]: https://github.com/lolcommits/lolcommits-term_output/compare/v0.0.1...v0.0.2 [0.0.1]: https://github.com/lolcommits/lolcommits-term_output/compare/0251ee8...v0.0.1 [KeepAChangelog]: http://keepachangelog.com/en/1.0.0/ -[Semver]: http://semver.org/spec/v2.0.0.html diff --git a/Gemfile b/Gemfile index 851fabc..b816373 100644 --- a/Gemfile +++ b/Gemfile @@ -1,2 +1,6 @@ -source 'https://rubygems.org' +source "https://rubygems.org" gemspec + +group :rubocop do + gem "rubocop-rails-omakase", require: false +end diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 1425369..0000000 --- a/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,16 +0,0 @@ - -Explain what you're changing and why here. - ---- -#### :memo: Checklist - -Please check this list and leave it intact for the reviewer. Thanks! :heart: - -- [ ] Commit messages provide context (why not just what, some tips [here](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)). -- [ ] If relevant, mention GitHub issue number above and include in a commit message. -- [ ] Latest code from master merged. -- [ ] New behaviour has test coverage. -- [ ] Avoid duplicating code. -- [ ] No commented out code. -- [ ] Avoid comments for your code, write code that explains itself. -- [ ] Changes are simple, useful, clear and brief. diff --git a/README.md b/README.md index 6ee4830..32d9782 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,16 @@ # Lolcommits Term Output -[![Build](https://img.shields.io/github/actions/workflow/status/lolcommits/lolcommits-term_output/build.yml?branch=main&style=flat)](https://github.com/lolcommits/lolcommits-term_output/actions/workflows/build.yml) +[![CI](https://img.shields.io/github/actions/workflow/status/lolcommits/lolcommits-term_output/ci.yml?branch=main&style=flat&label=CI)](https://github.com/lolcommits/lolcommits-term_output/actions/workflows/ci.yml) [![Gem](https://img.shields.io/gem/v/lolcommits-term_output.svg?style=flat)](http://rubygems.org/gems/lolcommits-term_output) [![Depfu](https://img.shields.io/depfu/lolcommits/lolcommits-term_output.svg?style=flat)](https://depfu.com/github/lolcommits/lolcommits-term_output) -[lolcommits](https://lolcommits.github.io/) takes a snapshot with your -webcam every time you git commit code, and archives a lolcat style image -with it. Git blame has never been so much fun! +[lolcommits](https://lolcommits.github.io/) takes a snapshot with your webcam +every time you git commit code, and archives a lolcat style image with it. Git +blame has never been so much fun! -This plugin uses the [inline -image](http://iterm2.com/documentation-images.html) feature available in -[iTerm2](http://iterm2.com/index.html) to display each lolcommit (images -only) in your terminal (after committing). For example: +This plugin uses the [inline image](http://iterm2.com/documentation-images.html) +feature available in [iTerm2](http://iterm2.com/index.html) to display each +lolcommit (images only) in your terminal (after committing). For example: ![iterm inline sample screenshot](./assets/images/sample.png) @@ -34,19 +33,19 @@ Then configure to enable and set the remote endpoint: $ lolcommits --config -p term_output # set enabled to `true` -That's it! Your next lolcommit will be displayed within your terminal. -To disable use: +That's it! Your next lolcommit will be displayed within your terminal. To +disable use: $ lolcommits --config -p term_output # and set enabled to `false` ## Development -Check out this repo and run `bin/setup`, this will install all -dependencies and generate docs. Use `bundle exec rake` to run all tests. +Check out this repo and run `bin/setup`, this will install all dependencies and +generate docs. Use `bundle exec rake` to run all tests. -You can also run `bin/console` for an interactive prompt that will allow -you to experiment with the gem code. +You can also run `bin/console` for an interactive prompt that will allow you to +experiment with the gem code. ## Tests @@ -63,17 +62,14 @@ Generate docs for this gem with: ## Troubles? If you think something is broken or missing, please raise a new -[issue](https://github.com/lolcommits/lolcommits-term_output/issues). -Take a moment to check it hasn't been raised in the past (and possibly -closed). +[issue](https://github.com/lolcommits/lolcommits-term_output/issues). Take a +moment to check it hasn't been raised in the past (and possibly closed). ## Contributing -Bug -[reports](https://github.com/lolcommits/lolcommits-term_output/issues) -and [pull -requests](https://github.com/lolcommits/lolcommits-term_output/pulls) -are welcome on GitHub. +Bug [reports](https://github.com/lolcommits/lolcommits-term_output/issues) and +[pull requests](https://github.com/lolcommits/lolcommits-term_output/pulls) are +welcome on GitHub. When submitting pull requests, remember to add tests covering any new behaviour, and ensure all tests are passing on CI. Read the [contributing @@ -93,7 +89,7 @@ The gem is available as open source under the terms of ## Links -* [CI](https://github.com/lolcommits/lolcommits-term_output/actions/workflows/build.yml) +* [CI](https://github.com/lolcommits/lolcommits-term_output/actions/workflows/ci.yml) * [RDoc](http://rdoc.info/projects/lolcommits/lolcommits-term_output) * [Issues](http://github.com/lolcommits/lolcommits-term_output/issues) * [Report a bug](http://github.com/lolcommits/lolcommits-term_output/issues/new) diff --git a/Rakefile b/Rakefile index 1f0c899..d9d87ca 100644 --- a/Rakefile +++ b/Rakefile @@ -18,4 +18,4 @@ Rake::TestTask.new(:test) do |t| t.test_files = FileList["test/**/*_test.rb"] end -task :default => ['test'] +task default: [ 'test' ] diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 0000000..397dc4f --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "bundler/setup" +load Gem.bin_path("rubocop", "rubocop") diff --git a/lib/lolcommits/plugin/term_output.rb b/lib/lolcommits/plugin/term_output.rb index 5ff9b70..e5c9ee1 100644 --- a/lib/lolcommits/plugin/term_output.rb +++ b/lib/lolcommits/plugin/term_output.rb @@ -1,14 +1,13 @@ # frozen_string_literal: true -require 'base64' -require 'lolcommits/plugin/base' +require "base64" +require "lolcommits/plugin/base" module Lolcommits module Plugin class TermOutput < Base - ## Prompts the user to configure the plugin's options. The default - #superclass method will ask for the `enabled` option to be set. + # superclass method will ask for the `enabled` option to be set. # # @return [Hash] hash of configured options `{ enabled: true/false }` # @return [Nil] if this terminal does not support this plugin @@ -33,16 +32,16 @@ def configure_options! def run_capture_ready if terminal_supported? if !runner.vcs_info || runner.vcs_info.repo.empty? - debug 'repo is empty, skipping term output' + debug "repo is empty, skipping term output" elsif !image_path - debug 'lolcommit videos not supported' + debug "lolcommit videos not supported" else debug "rendering image in iTerm" base64 = Base64.encode64(open(image_path, &:read).to_s) puts "#{begin_escape}1337;File=inline=1:#{base64};alt=#{runner.message};#{end_escape}\n" end else - debug 'Terminal not supported (requires iTerm2)' + debug "Terminal not supported (requires iTerm2)" end end @@ -89,7 +88,7 @@ def end_escape # @return [Boolan] true when running within a Tmux session # def tmux? - !ENV['TMUX'].nil? + !ENV["TMUX"].nil? end ## @@ -98,7 +97,7 @@ def tmux? # @return [Boolan] true when terminal identifies as iTerm # def terminal_supported? - ENV['TERM_PROGRAM'] =~ /iTerm/ + ENV["TERM_PROGRAM"] =~ /iTerm/ end end end diff --git a/lib/lolcommits/term_output.rb b/lib/lolcommits/term_output.rb index b1ab28a..2b6f2f4 100644 --- a/lib/lolcommits/term_output.rb +++ b/lib/lolcommits/term_output.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true -require 'lolcommits/term_output/version' -require 'lolcommits/plugin/term_output' +require "lolcommits/term_output/version" +require "lolcommits/plugin/term_output" diff --git a/lib/lolcommits/term_output/version.rb b/lib/lolcommits/term_output/version.rb index 4a37f56..391cac1 100644 --- a/lib/lolcommits/term_output/version.rb +++ b/lib/lolcommits/term_output/version.rb @@ -2,6 +2,6 @@ module Lolcommits module TermOutput - VERSION = "0.5.0".freeze + VERSION = "0.5.1".freeze end end diff --git a/lolcommits-term_output.gemspec b/lolcommits-term_output.gemspec index 230696a..dc75df5 100644 --- a/lolcommits-term_output.gemspec +++ b/lolcommits-term_output.gemspec @@ -5,8 +5,8 @@ require 'lolcommits/term_output/version' Gem::Specification.new do |spec| spec.name = "lolcommits-term_output" spec.version = Lolcommits::TermOutput::VERSION - spec.authors = ["Matthew Hutchinson"] - spec.email = ["matt@hiddenloop.com"] + spec.authors = [ "Matthew Hutchinson" ] + spec.email = [ "matt@hiddenloop.com" ] spec.summary = "Display lolcommits within your iTerm terminal" spec.homepage = "https://github.com/lolcommits/lolcommits-term_output" spec.license = "LGPL-3.0" @@ -24,7 +24,7 @@ Gem::Specification.new do |spec| spec.test_files = `git ls-files -- {test,features}/*`.split("\n") spec.bindir = "bin" spec.executables = [] - spec.require_paths = ["lib"] + spec.require_paths = [ "lib" ] spec.required_ruby_version = ">= 3.1" diff --git a/test/lolcommits/plugin/term_output_test.rb b/test/lolcommits/plugin/term_output_test.rb index 424810a..8650d45 100644 --- a/test/lolcommits/plugin/term_output_test.rb +++ b/test/lolcommits/plugin/term_output_test.rb @@ -3,21 +3,20 @@ require "test_helper" describe Lolcommits::Plugin::TermOutput do - include Lolcommits::TestHelpers::GitRepo include Lolcommits::TestHelpers::FakeIO # initialize and reset env vars before tests run before do - @old_tmux = ENV['TMUX'] - @old_term_program = ENV['TERM_PROGRAM'] - ENV['TERM_PROGRAM'] = "iTerm" - ENV['TMUX'] = nil + @old_tmux = ENV["TMUX"] + @old_term_program = ENV["TERM_PROGRAM"] + ENV["TERM_PROGRAM"] = "iTerm" + ENV["TMUX"] = nil end after do - ENV['TERM_PROGRAM'] = @old_term_program - ENV['TMUX'] = @old_tmux + ENV["TERM_PROGRAM"] = @old_term_program + ENV["TMUX"] = @old_tmux end describe "with a runner" do @@ -29,7 +28,7 @@ def runner end def lolcommit_path - File.expand_path(File.dirname(__FILE__) + '../../../assets/test_image.jpg') + File.expand_path(File.dirname(__FILE__) + "../../../assets/test_image.jpg") end def plugin @@ -69,7 +68,7 @@ def check_plugin_output(matching_regex) describe "when running in a Tmux session" do before do - ENV['TMUX'] = 'true' + ENV["TMUX"] = "true" end it "outputs lolcommits image inline to terminal with Tmux escape sequence" do @@ -79,7 +78,7 @@ def check_plugin_output(matching_regex) describe "when using an unsupported terminal" do before do - ENV['TERM_PROGRAM'] = "konsole" + ENV["TERM_PROGRAM"] = "konsole" end it "outputs nothing to the terminal" do @@ -90,7 +89,7 @@ def check_plugin_output(matching_regex) describe "configuration" do it "allows plugin options to be configured" do - inputs = %w( true ) # enabled option + inputs = %w[ true ] # enabled option configured_plugin_options = {} fake_io_capture(inputs: inputs) do @@ -102,11 +101,11 @@ def check_plugin_output(matching_regex) describe "when terminal not supported" do before do - ENV['TERM_PROGRAM'] = "konsole" + ENV["TERM_PROGRAM"] = "konsole" end it "does not allow options to be configured" do - inputs = %w( true ) # enabled option + inputs = %w[ true ] # enabled option configured_plugin_options = {} output = fake_io_capture(inputs: inputs) do diff --git a/test/test_helper.rb b/test/test_helper.rb index 82e83f3..66766ff 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,17 +1,17 @@ # frozen_string_literal: true -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) # lolcommits gem -require 'lolcommits' +require "lolcommits" # lolcommit test helpers -require 'lolcommits/test_helpers/git_repo' -require 'lolcommits/test_helpers/fake_io' +require "lolcommits/test_helpers/git_repo" +require "lolcommits/test_helpers/fake_io" # plugin gem test libs -require 'lolcommits/term_output' -require 'minitest/autorun' +require "lolcommits/term_output" +require "minitest/autorun" # swallow all debug output during test runs def debug(msg); end