diff --git a/Gemfile.lock b/Gemfile.lock index 121c4e9..1bd8bd0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,27 +1,28 @@ PATH remote: . specs: - redmine-cli (0.1.0) + redmine-cli (0.1.1) activeresource (~> 3.0.0) thor GEM remote: http://rubygems.org/ specs: - activemodel (3.0.1) - activesupport (= 3.0.1) + activemodel (3.0.10) + activesupport (= 3.0.10) builder (~> 2.1.2) - i18n (~> 0.4.1) - activeresource (3.0.1) - activemodel (= 3.0.1) - activesupport (= 3.0.1) - activesupport (3.0.1) + i18n (~> 0.5.0) + activeresource (3.0.10) + activemodel (= 3.0.10) + activesupport (= 3.0.10) + activesupport (3.0.10) + archive-tar-minitar (0.5.2) aruba (0.2.3) background_process cucumber (~> 0.9.0) background_process (1.2) builder (2.1.2) - columnize (0.3.1) + columnize (0.3.4) cucumber (0.9.3) builder (~> 2.1.2) diff-lcs (~> 1.1.2) @@ -32,9 +33,10 @@ GEM gherkin (2.2.9) json (~> 1.4.6) term-ansicolor (~> 1.0.5) - i18n (0.4.2) + i18n (0.5.0) json (1.4.6) - linecache (0.43) + linecache19 (0.5.12) + ruby_core_source (>= 0.1.4) rspec (2.0.1) rspec-core (~> 2.0.1) rspec-expectations (~> 2.0.1) @@ -45,22 +47,25 @@ GEM rspec-mocks (2.0.1) rspec-core (~> 2.0.1) rspec-expectations (~> 2.0.1) - ruby-debug (0.10.3) - columnize (>= 0.1) - ruby-debug-base (~> 0.10.3.0) - ruby-debug-base (0.10.3) - linecache (>= 0.3) + ruby-debug-base19 (0.11.25) + columnize (>= 0.3.1) + linecache19 (>= 0.5.11) + ruby_core_source (>= 0.1.4) + ruby-debug19 (0.11.6) + columnize (>= 0.3.1) + linecache19 (>= 0.5.11) + ruby-debug-base19 (>= 0.11.19) + ruby_core_source (0.1.5) + archive-tar-minitar (>= 0.5.2) term-ansicolor (1.0.5) - thor (0.14.3) + thor (0.14.6) PLATFORMS ruby DEPENDENCIES - activeresource (~> 3.0.0) aruba cucumber redmine-cli! rspec - ruby-debug - thor + ruby-debug19 diff --git a/lib/redmine-cli/cli.rb b/lib/redmine-cli/cli.rb index 6f2187b..2d1533c 100644 --- a/lib/redmine-cli/cli.rb +++ b/lib/redmine-cli/cli.rb @@ -22,20 +22,37 @@ def list params[:project_id] = map_project(options.project) if options.project - collection = Issue.all(:params => params) + collection = Issue.fetch_all(params) unless options.std_output - issues = collection.collect { |issue| [link_to_issue(issue.id), issue.subject, issue.status.name] } + collection.sort! {|i,j| i.status.id <=> j.status.id } + issues = collection.collect do |issue| + assignee = "" + assignee = issue.assigned_to.name if issue.respond_to?(:assigned_to) + ["#{issue.id}", issue.status.name, issue.priority.name, assignee, issue.subject] + end if issues.any? - issues.insert(0, ["URL", "Subject", "Status"]) + issues.insert(0, ["Id", "Status", "Priority", "Assignee", "Status"]) print_table(issues) + say "#{collection.count} issues - #{link_to_project(params[:project_id])}", :yellow end else say collection.collect(&:id).join(" ") end end + desc "projects", "Lists all projects" + def projects + projects = Project.fetch_all.sort {|i,j| i.name <=> j.name}.collect { |project| [ project.id, project.identifier, project.name ] } + if projects.any? + projects.insert(0, ["Id", "Key", "Name"]) + print_table(projects) + say "#{projects.count} projects - #{link_to_project}", :yellow + end + + end + desc "show TICKET", "Display information of a ticket" def show(ticket) issue = Issue.find(ticket) @@ -71,6 +88,7 @@ def new(subject, description="") method_option :tickets, :aliases => "-l", :desc => "list of tickets", :type => :array method_option :status, :aliases => "-s", :desc => "id or name of status for ticket" + method_option :priority, :aliases => "-p", :desc => "id or name of priority for ticket" method_option :subject, :aliases => "-t", :desc => "subject for ticket (title)" method_option :description, :aliases => "-d", :desc => "description for ticket" method_option :assigned_to, :aliases => "-a", :desc => "id or user name of person the ticket is assigned to" @@ -108,14 +126,23 @@ def link_to_issue(id) "#{Redmine::Cli::config.url}/issues/#{id}" end + def link_to_project(name = nil) + if name + "#{Redmine::Cli::config.url}/projects/#{name}/issues" + else + "#{Redmine::Cli::config.url}" + end + end + def ticket_attributes(options) attributes = {} attributes[:subject] = options.subject if options.subject.present? attributes[:description] = options.description if options.description.present? - attributes[:project_id] = options.project if options.project.present? + attributes[:project_id] = map_project(options.project) if options.project.present? attributes[:assigned_to_id] = map_user(options.assigned_to) if options.assigned_to.present? - attributes[:status_id] = options.status if options.status.present? + attributes[:status_id] = map_status(options.status) if options.status.present? + attributes[:priority_id] = map_priority(options.priority)if options.priority.present? attributes end @@ -134,6 +161,10 @@ def map_status(status_name) get_mapping(:status_mappings, status_name) end + def map_priority(priority_name) + get_mapping(:priority_mappings, priority_name) + end + def map_project(project_name) get_mapping(:project_mappings, project_name) end @@ -141,8 +172,20 @@ def map_project(project_name) def update_mapping_cache say 'Updating mapping cache...', :yellow # TODO: Updating user mapping requries Redmine 1.1+ - users = User.all.collect { |user| [ user.login, user.id ] } - projects = Project.all.collect { |project| [ project.identifier, project.id ] } + users = [] + begin + users = User.fetch_all.collect { |user| [ user.login, user.id ] } + rescue Exception => e + say "Failed to fetch users: #{e}", :red + end + projects = Project.fetch_all.collect { |project| [ project.identifier, project.id ] } + + priorities = {} + status = {} + Issue.fetch_all.each do |issue| + priorities[issue.priority.name] = issue.priority.id if issue.priority + status[issue.status.name] = issue.status.id if issue.status + end # TODO: Need to determine where to place cache file based on # config file location. @@ -150,6 +193,8 @@ def update_mapping_cache YAML.dump({ :user_mappings => Hash[users], :project_mappings => Hash[projects], + :priority_mappings => priorities, + :status_mappings => status, }, out) end end @@ -204,6 +249,10 @@ def ask_password(prompt) system "stty echo" password end + + def default_parameters + {:limit => 100} + end end end end diff --git a/lib/redmine-cli/resources.rb b/lib/redmine-cli/resources.rb index 7a799c3..b88c67b 100644 --- a/lib/redmine-cli/resources.rb +++ b/lib/redmine-cli/resources.rb @@ -21,6 +21,20 @@ def find(*arguments) super end + + def fetch_all(params = {}) + limit = 100 + offset = 0 + + resources = [] + + while((fetched_resources = self.all(:params => params.merge({:limit => limit, :offset => offset}))).any?) + resources += fetched_resources + offset += limit + end + + resources + end end end diff --git a/redmine-cli.gemspec b/redmine-cli.gemspec index afefa38..6156230 100644 --- a/redmine-cli.gemspec +++ b/redmine-cli.gemspec @@ -21,7 +21,11 @@ Gem::Specification.new do |s| s.add_dependency "activeresource", "~>3.0.0" s.add_dependency "thor" - s.add_development_dependency "ruby-debug" + if RUBY_VERSION =~ /1.9/ + s.add_development_dependency "ruby-debug19" + else + s.add_development_dependency "ruby-debug" + end s.add_development_dependency "rspec" s.add_development_dependency "cucumber" s.add_development_dependency "aruba"