From e1da540e83fac1df902ecc51dbe70aff95978ff0 Mon Sep 17 00:00:00 2001 From: Vincent Rolea <3525369+virolea@users.noreply.github.com> Date: Wed, 8 Oct 2025 15:30:45 +0200 Subject: [PATCH 1/3] Refactor the lib and add tests --- Gemfile | 8 ++++++++ Gemfile.lock | 15 +++++++++++++++ Rakefile | 8 ++++++++ lib/pull_request_body.rb | 13 +++++++++++++ remove_before_launch.rb | 12 +++++------- test/pull_request_body_test.rb | 24 ++++++++++++++++++++++++ 6 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 Rakefile create mode 100644 lib/pull_request_body.rb create mode 100644 test/pull_request_body_test.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..97eae5a --- /dev/null +++ b/Gemfile @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } + +gem "minitest" +gem "rake" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..4fac2e9 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,15 @@ +GEM + remote: https://rubygems.org/ + specs: + minitest (5.26.0) + rake (13.3.0) + +PLATFORMS + arm64-darwin-25 + +DEPENDENCIES + minitest + rake + +BUNDLED WITH + 2.7.1 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..56926c6 --- /dev/null +++ b/Rakefile @@ -0,0 +1,8 @@ +require "minitest/test_task" + +Minitest::TestTask.create(:test) do |t| + t.libs << "test" + t.warning = false + t.verbose = true + t.test_globs = ["test/**/*_test.rb"] +end diff --git a/lib/pull_request_body.rb b/lib/pull_request_body.rb new file mode 100644 index 0000000..1f85dc0 --- /dev/null +++ b/lib/pull_request_body.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class PullRequestBody + INCOMPLETE_TODO_REGEX = /^\s*-\s+\[\s\]\s+(.+)$/.freeze + + def initialize(text:) + @text = text + end + + def incomplete_todos + @text.scan(INCOMPLETE_TODO_REGEX).map(&:first) + end +end diff --git a/remove_before_launch.rb b/remove_before_launch.rb index f69ddb3..9aae4d7 100644 --- a/remove_before_launch.rb +++ b/remove_before_launch.rb @@ -1,18 +1,16 @@ # frozen_string_literal: true -REGEX = /^\s*-\s+\[\s\]\s+(.+)$/.freeze +require_relative "lib/pull_request_body" -pull_request_body = ARGV[0] +pull_request_body = PullRequestBody.new(text: ARGV[0]) -incomplete_todos = pull_request_body.scan(REGEX) - -if incomplete_todos.empty? +if pull_request_body.incomplete_todos.empty? exit 0 else puts "⚠️ There are still uncompleted todos that need your attention:\n\n" - incomplete_todos.each do |incomplete_todo| - puts "□ #{incomplete_todo.first}\n" + pull_request_body.incomplete_todos.each do |incomplete_todo| + puts "□ #{incomplete_todo}\n" end exit 1 diff --git a/test/pull_request_body_test.rb b/test/pull_request_body_test.rb new file mode 100644 index 0000000..e0a5a3c --- /dev/null +++ b/test/pull_request_body_test.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require "minitest/autorun" +require_relative "../lib/pull_request_body" + +class PullRequestBodyTest < Minitest::Test + TEST_MARKDOWN = <<~MARKDOWN + This is a test to see if the parser can look for the different unchecked TODOs that can be bundled in a PR description. + + - [ ] Good syntax + - [x] This is a checked TODO + - [ ] Nested + - [ ] Bad syntax: extra space after the dash + + MARKDOWN + + def test_find_variously_formatted_incomplete_todos + pull_request_body = PullRequestBody.new(text: TEST_MARKDOWN) + incomplete_todos = pull_request_body.incomplete_todos + + assert incomplete_todos.length, 3 + assert incomplete_todos == ["Good syntax", "Nested", "Bad syntax: extra space after the dash"] + end +end From e43c12dc9e4433423c39a9632970da722fe131ad Mon Sep 17 00:00:00 2001 From: Vincent Rolea <3525369+virolea@users.noreply.github.com> Date: Wed, 8 Oct 2025 17:36:55 +0200 Subject: [PATCH 2/3] Add lib to the image --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index f21591f..6dbe8a7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ FROM ruby:3.4.6-alpine COPY remove_before_launch.rb /remove_before_launch.rb +COPY /lib /lib ENTRYPOINT ["ruby", "/remove_before_launch.rb"] From 3608dd49c488d16d20f4e9b1f3f855c5672bc81d Mon Sep 17 00:00:00 2001 From: Vincent Rolea <3525369+virolea@users.noreply.github.com> Date: Wed, 8 Oct 2025 18:31:06 +0200 Subject: [PATCH 3/3] Add test workflow --- .github/workflows/test.yml | 22 ++++++++++++++++++++++ .ruby-version | 1 + Gemfile.lock | 1 + 3 files changed, 24 insertions(+) create mode 100644 .github/workflows/test.yml create mode 100644 .ruby-version diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e674c38 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,22 @@ +on: + pull_request: + push: + branches: [ main ] + +jobs: + remove_before_launch: + runs-on: ubuntu-latest + name: Remove before launch + + steps: + - name: Checkout + uses: actions/checkout@v5 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: .ruby-version + bundler-cache: true + + - name: Run Ruby tests + run: rake test diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..4ae6486 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-3.4.6 diff --git a/Gemfile.lock b/Gemfile.lock index 4fac2e9..5cfeea6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,6 +6,7 @@ GEM PLATFORMS arm64-darwin-25 + x86_64-linux DEPENDENCIES minitest