Righto. Pretty vague title? Check. Checkception? Definitely.

In order for us to raise the quality of our PR’s and QA on the pull requests. We started introducing pull requests templates. They list the standard things people should check for that can’t be caught by our CI.

Things such as;

  • Spelling errors.
  • Documentation updates.
  • CSS checks etc.
  • Whether you even read your own PR.

Of course like any good developer, the first thing people do with these annoying check boxes is ignore them. So when I finally got fed up by it pointing this out in PR’s a build a todo checker.

Also the build experience was a Meh, running it locally is a pain in the buttocks.

Lets get started

Lets kick it of with the directory structure.

.github/
├── actions
│   └── todo-checker
│       ├── Dockerfile
│       ├── Gemfile
│       ├── Gemfile.lock
│       ├── run.rb
│       └── run.sh
├── pull_request_template.md
└── workflows
    └── todo.yml

The todo.yml workflow looks like this:

name: Todos
on: pull_request_target
jobs:
  verify:
    name: Todos
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
      - uses: ./.github/actions/todo-checker
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

And the ruby file to do all this like this:

require "octokit"
require "json"

puts current_repo = ENV["GITHUB_REPOSITORY"]
puts root = ENV["GITHUB_WORKSPACE"]

puts "---> #{ENV["GITHUB_EVENT_NAME"]} #{ENV["GITHUB_EVENT_PATH"]}"
context = JSON.parse(File.read(ENV["GITHUB_EVENT_PATH"]), object_class: OpenStruct)

client = Octokit::Client.new(access_token: ENV["GITHUB_TOKEN"])

# Check for todos
puts "---> Checking todos for repo '#{current_repo}' #{context.number}"
pr = client.pull(current_repo, context.number.to_i)

def has_open_todos?(pull_request)
  if pull_request.body.match(/\- \[ \]/)
    puts "Has open todos :( Fix them!"
    exit 1
  end
end

has_open_todos?(pr)

Now whenever anyone is like BRUU, can I merge? It blocks the merge before before unless you completed the checks.

Want more annoying GitHub checks?

Would you like to stay up to date on ? Subscribe here! I'll only use your email to keep u up to date on new technology and software development tips. It wont be shared. Feel free to unsubscribe anytime!