Skip to content

Instantly share code, notes, and snippets.

@existentialmutt
Created September 10, 2021 16:34
Show Gist options
  • Save existentialmutt/e4c34dc30e508f24c6c3e5f6dd40b99b to your computer and use it in GitHub Desktop.
Save existentialmutt/e4c34dc30e508f24c6c3e5f6dd40b99b to your computer and use it in GitHub Desktop.

Revisions

  1. existentialmutt created this gist Sep 10, 2021.
    29 changes: 29 additions & 0 deletions update_standard_todo.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/usr/bin/env ruby
    require 'pathname'
    require "tempfile"
    require "fileutils"


    base = ENV.fetch("STANDARD_UPDATE_BASE") { "$HEAD" }
    files = `git diff #{base} --name-only --staged`.split("\n")

    app_root = Pathname.new File.expand_path('../../', __FILE__)

    todo_path = File.join(app_root, ".standard_todo.yml")

    Tempfile.create do |tempfile|
    File.foreach(todo_path) do |line|
    trimmed = line.gsub(/^\s+- /, "").chomp
    if files.include?(trimmed)
    puts line
    else
    tempfile << line
    end
    end

    tempfile.flush

    FileUtils.cp(tempfile.path, todo_path)
    end

    `git add .standard_todo.yml`