Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-3.4.6
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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"
16 changes: 16 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
GEM
remote: https://rubygems.org/
specs:
minitest (5.26.0)
rake (13.3.0)

PLATFORMS
arm64-darwin-25
x86_64-linux

DEPENDENCIES
minitest
rake

BUNDLED WITH
2.7.1
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions lib/pull_request_body.rb
Original file line number Diff line number Diff line change
@@ -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
12 changes: 5 additions & 7 deletions remove_before_launch.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
24 changes: 24 additions & 0 deletions test/pull_request_body_test.rb
Original file line number Diff line number Diff line change
@@ -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