Sha256: aa44c73358d322215ca844e24f4093fb9ee1bf37099a0531474f85292879291f

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

module Gitmine
  class Gitmine
    def self.list
      gm = Gitmine.new
      gm.commits.each do |commit|
        status = commit.issue ? commit.issue.status : 'N/A'
        puts "#{commit.id[0..6]} #{status.ljust(12)} #{commit.committer.name.ljust(15)} #{commit.message[0..50].gsub("\n", '')}"
      end
    end

    def initialize
      @repo = Grit::Repo.new(ENV['PWD'])
      @branch = File.read('./.git/HEAD').match(/^ref: refs\/heads\/(.+)/)[1]
    end

    def commits
      @repo.commits(@branch).map do |c|
        Commit.new(c)
      end
    end


    def self.branch(branch_name)
      issue_id = branch_name[/^\d+/]
      original_branch = File.read('./.git/HEAD').match(/^ref: refs\/heads\/(.+)/)[1]
      config = Issue.config

      raise "Invalid branch name. It should start with the issue number" unless issue_id

      puts "Create the branch #{branch_name}"
      run_cmd("git checkout -b #{branch_name}")

      puts "Push it to origin"
      run_cmd("git push origin #{branch_name}")

      puts "Make the local branch tracking the remote"
      run_cmd("git branch --set-upstream #{branch_name} origin/#{branch_name}")

      puts "Adding a note to the Issue ##{issue_id}"
      note = "Branch *#{branch_name}* created from #{original_branch}"
      if config['github']
        note << %{ - "See on Github":https://github.com/#{config['github']}/tree/#{branch_name}}
        note << %{ - "Compare on Github":https://github.com/#{config['github']}/compare/#{original_branch}...#{branch_name}}
      end

      Issue.find(issue_id).add_note(note)
    end

    def self.run_cmd(cmd)
      puts cmd
      exit! unless system(cmd)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gitmine-0.1.4.pre.1 lib/gitmine/gitmine.rb