lib/gitmine.rb in gitmine-0.1.16 vs lib/gitmine.rb in gitmine-0.2.0

- old
+ new

@@ -1,10 +1,11 @@ require 'rubygems' require 'grit' require 'yaml' require 'httparty' +require 'launchy' class Gitmine def self.list gm = Gitmine.new @@ -13,10 +14,31 @@ 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 self.status + Gitmine.new.status + end + + def status + if issue + puts "#{bold(issue.status)} - #{issue.subject} #{blue("(#{issue.assigned_to})")}" + end + end + + def self.open + Gitmine.new.open + end + + def open + issue_url = "#{Config.redmine_host}/issues/#{issue_id}" + if issue + Launchy.open issue_url + end + end + def initialize @repo = Grit::Repo.new(ENV['PWD']) @branch = File.read('./.git/HEAD').match(/^ref: refs\/heads\/(.+)/)[1] end @@ -24,9 +46,22 @@ @repo.commits(@branch).map do |c| Commit.new(c) end end + def issue_id + @branch[/^\d+/] + end + + # Return issue for current branch or nil + def issue + if issue_id + Issue.find(issue_id) + else + puts "No issue found for branch #{@branch}" + nil + end + end # TODO specs def self.branch(branch_name) issue_id = branch_name[/^\d+/] original_branch = File.read('./.git/HEAD').match(/^ref: refs\/heads\/(.+)/)[1]