Sha256: a2c59823868ac175bb4e6c13e2ce43127a2eec46f518da94b6ee1b9efdc9d178

Contents?: true

Size: 1.93 KB

Versions: 6

Compression:

Stored size: 1.93 KB

Contents

require 'rake'
require 'rake/tasklib'

class ContributorTasks < Rake::TaskLib
  def initialize
    define
  end

  def define
    desc "Update contributors list in README"
    task :update_contributors do
      if new_contributors?
        puts "New contributors!"
        new_contributors.each {|name| puts "- #{name}"}
        puts ""

        print "Updating the 'Contributors' section of README..."

        File.open("README.md", "w+") do |file|
          file.puts readme_without_contributors_section
          file.puts "## Contributors (sorted alphabetically)"
          file.puts ""
          committers.each {|name| file.puts "* #{name}"}
        end
        puts "done!"
      else
        puts "No new contributors."
      end
    end

    task :release do
      puts "#####################"
      puts "For the twitters"
      puts "#####################"
      puts "[ANN] chili_presentations v#{ChiliPresentations::VERSION} released. Changes: http://bit.ly/chili_presentation_changes, Repo: http://bit.ly/chili_presentations #chiliproject"
      puts "#####################"

    end
  end

  private
    def all_committers
      all_names = `git shortlog -s |cut -s -f2`
      all_names.gsub!(/\sand\s/, "\n").split("\n").uniq!.sort!
    end

    def committers
      excluded_committers = ["Tom Kersten"]
      @committers ||= all_committers - excluded_committers
    end

    def readme_file_contents
      @readme_contents ||= `cat README.md`
    end

    def existing_contributors
      existing_contributors = readme_file_contents[/## Contributors(.|\n)*/].strip.split("\n* ")
      existing_contributors.shift # remove "Contributors..." line
      existing_contributors
    end

    def new_contributors
      @new_contributors ||= committers - existing_contributors
    end

    def new_contributors?
      !new_contributors.empty?
    end

    def readme_without_contributors_section
      readme_file_contents.sub(/## Contributors(.|\n)*/, '')
    end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
chili_presentations-0.2.2 lib/tasks/contributor_tasks.rb
chili_presentations-0.2.1 lib/tasks/contributor_tasks.rb
chili_presentations-0.2.0 lib/tasks/contributor_tasks.rb
chili_presentations-0.1.3 lib/tasks/contributor_tasks.rb
chili_presentations-0.1.2 lib/tasks/contributor_tasks.rb
chili_presentations-0.1.1 lib/tasks/contributor_tasks.rb