Sha256: d4838b89bc0f2e93a39663b4143ca0a3e6ebc892624bae82137399644fc17517

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

module Idonethis::UseCases
  module Git
    class << self
      def apply(credential, args={})
        log = args[:log] || fail("You need to supply :log adapter")

        dir = File.expand_path("..")

        all_dirs = Dir.entries(dir).reject{|it| ["..", "."].include?(it) }.select{|it| File.directory?(File.join(dir, it))}.map{|it| File.join(dir, it)}

        dirs_that_have_changed_today = all_dirs.select{|it| today?(File.mtime(it)) }
        
        puts "Scanning dir <#{dir}>, which has <#{dirs_that_have_changed_today.size}> repositories that have changed\n\n"

        dirs_that_have_changed_today.each do |dir|
          summary = commit_summary(dir)
          puts %Q{#{Pathname.new(dir).basename} (#{summary.size}):\n-- #{summary.join("\n-- ")}"}
        end

        puts ""
      end

      def today?(time)
        now = Time.now
        time.year == now.year && time.month == now.month && time.day == now.day
      end

      def commit_summary(dir)
        require 'git'
        git = ::Git.open(dir)
        git.log.since('1am').take(10).map{|it| %Q{[#{it.date.strftime("%H:%M")}] #{it.message}}}
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
idonethis-cli-0.5.0 lib/idonethis/use_cases/git.rb
idonethis-cli-0.4.1 lib/idonethis/use_cases/git.rb