From 59eb8ebee79767d2fd21bbbb6d8c96369a93d72f Mon Sep 17 00:00:00 2001 From: Daniel Lehmann Date: Fri, 2 Sep 2011 11:29:32 +0200 Subject: [PATCH 1/9] Changed gemspec to make project ruby 1.9 compatible in development. --- redmine-cli.gemspec | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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" From 08e20f334f544553013e298209c9c89e44d99739 Mon Sep 17 00:00:00 2001 From: Daniel Lehmann Date: Fri, 2 Sep 2011 12:48:17 +0200 Subject: [PATCH 2/9] Reformatted list output. list now shows ticket id instead of link to ticket and additionally shows status and assignee. --- lib/redmine-cli/cli.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/redmine-cli/cli.rb b/lib/redmine-cli/cli.rb index 6f2187b..b163350 100644 --- a/lib/redmine-cli/cli.rb +++ b/lib/redmine-cli/cli.rb @@ -25,11 +25,17 @@ def list collection = Issue.all(:params => 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(" ") @@ -108,6 +114,14 @@ 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 = {} From df91ddf58c603f909081352823e8a6469beba6a7 Mon Sep 17 00:00:00 2001 From: Daniel Lehmann Date: Fri, 2 Sep 2011 12:50:21 +0200 Subject: [PATCH 3/9] Introduced default parameters (such as limit) for active resource queries. --- lib/redmine-cli/cli.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/redmine-cli/cli.rb b/lib/redmine-cli/cli.rb index b163350..b859da2 100644 --- a/lib/redmine-cli/cli.rb +++ b/lib/redmine-cli/cli.rb @@ -14,7 +14,7 @@ class CLI < Thor method_option :std_output, :aliases => "-o", :type => :boolean, :desc => "special output for STDOUT (useful for updates)" def list - params = {} + params = default_parameters params[:assigned_to_id] = map_user(options.assigned_to) if options.assigned_to @@ -155,8 +155,8 @@ 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 = User.all(default_parameters).collect { |user| [ user.login, user.id ] } + projects = Project.all(default_parameters).collect { |project| [ project.identifier, project.id ] } # TODO: Need to determine where to place cache file based on # config file location. @@ -218,6 +218,10 @@ def ask_password(prompt) system "stty echo" password end + + def default_parameters + {:limit => 100} + end end end end From 8255a39729efdc436e08a84c7301fe2066d4d9b4 Mon Sep 17 00:00:00 2001 From: Daniel Lehmann Date: Fri, 2 Sep 2011 12:51:05 +0200 Subject: [PATCH 4/9] Added new command 'projects' to get a list of all projects. --- lib/redmine-cli/cli.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/redmine-cli/cli.rb b/lib/redmine-cli/cli.rb index b859da2..97a3bb9 100644 --- a/lib/redmine-cli/cli.rb +++ b/lib/redmine-cli/cli.rb @@ -42,6 +42,17 @@ def list end end + desc "projects", "Lists all projects" + def projects + projects = Project.all(default_parameters).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) From c54c425f0a8a63c2a954f5b00a0bf2a669243af6 Mon Sep 17 00:00:00 2001 From: Daniel Lehmann Date: Fri, 2 Sep 2011 12:51:33 +0200 Subject: [PATCH 5/9] Updated version of Gemfile.lock --- Gemfile.lock | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) 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 From 442b3b10be83c57cec2deee8494c38e2b65a2df8 Mon Sep 17 00:00:00 2001 From: Daniel Lehmann Date: Fri, 2 Sep 2011 14:13:53 +0200 Subject: [PATCH 6/9] Fixed handling of default parameters. --- lib/redmine-cli/cli.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/redmine-cli/cli.rb b/lib/redmine-cli/cli.rb index 97a3bb9..d1307c7 100644 --- a/lib/redmine-cli/cli.rb +++ b/lib/redmine-cli/cli.rb @@ -44,7 +44,7 @@ def list desc "projects", "Lists all projects" def projects - projects = Project.all(default_parameters).sort {|i,j| i.name <=> j.name}.collect { |project| [ project.id, project.identifier, project.name ] } + projects = Project.all(:params => default_parameters).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) @@ -166,8 +166,8 @@ 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(default_parameters).collect { |user| [ user.login, user.id ] } - projects = Project.all(default_parameters).collect { |project| [ project.identifier, project.id ] } + users = User.all(:params => default_parameters).collect { |user| [ user.login, user.id ] } + projects = Project.all(:params => default_parameters).collect { |project| [ project.identifier, project.id ] } # TODO: Need to determine where to place cache file based on # config file location. From d594566779231490f255943be7bc1ab09397b55a Mon Sep 17 00:00:00 2001 From: Daniel Lehmann Date: Fri, 2 Sep 2011 14:40:16 +0200 Subject: [PATCH 7/9] Added caching of status and priorities, tickets can now be updated with priority. --- lib/redmine-cli/cli.rb | 30 +++++++++++++++++++++++------- lib/redmine-cli/resources.rb | 14 ++++++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/lib/redmine-cli/cli.rb b/lib/redmine-cli/cli.rb index d1307c7..cfe5611 100644 --- a/lib/redmine-cli/cli.rb +++ b/lib/redmine-cli/cli.rb @@ -14,7 +14,7 @@ class CLI < Thor method_option :std_output, :aliases => "-o", :type => :boolean, :desc => "special output for STDOUT (useful for updates)" def list - params = default_parameters + params = {} params[:assigned_to_id] = map_user(options.assigned_to) if options.assigned_to @@ -22,7 +22,7 @@ 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 collection.sort! {|i,j| i.status.id <=> j.status.id } @@ -44,7 +44,7 @@ def list desc "projects", "Lists all projects" def projects - projects = Project.all(:params => default_parameters).sort {|i,j| i.name <=> j.name}.collect { |project| [ project.id, project.identifier, project.name ] } + 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) @@ -88,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" @@ -138,9 +139,10 @@ def ticket_attributes(options) 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 @@ -159,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 @@ -166,8 +172,16 @@ 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(:params => default_parameters).collect { |user| [ user.login, user.id ] } - projects = Project.all(:params => default_parameters).collect { |project| [ project.identifier, project.id ] } + users = User.fetch_all.collect { |user| [ user.login, user.id ] } + 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. @@ -175,6 +189,8 @@ def update_mapping_cache YAML.dump({ :user_mappings => Hash[users], :project_mappings => Hash[projects], + :priority_mappings => priorities, + :status_mappings => status, }, out) 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 From 797c403c3d6b9a7898802eea64558a9d216ce857 Mon Sep 17 00:00:00 2001 From: Daniel Lehmann Date: Fri, 2 Sep 2011 15:12:26 +0200 Subject: [PATCH 8/9] Failing calls to resource users are now getting handled. --- lib/redmine-cli/cli.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/redmine-cli/cli.rb b/lib/redmine-cli/cli.rb index cfe5611..3c745d2 100644 --- a/lib/redmine-cli/cli.rb +++ b/lib/redmine-cli/cli.rb @@ -172,7 +172,11 @@ def map_project(project_name) def update_mapping_cache say 'Updating mapping cache...', :yellow # TODO: Updating user mapping requries Redmine 1.1+ - users = User.fetch_all.collect { |user| [ user.login, user.id ] } + 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 = {} From 181c38647a42298dd9f321af486351449dfe74f7 Mon Sep 17 00:00:00 2001 From: Daniel Lehmann Date: Fri, 2 Sep 2011 15:19:35 +0200 Subject: [PATCH 9/9] Failing calls to resource users are now getting handled. --- lib/redmine-cli/cli.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/redmine-cli/cli.rb b/lib/redmine-cli/cli.rb index 3c745d2..2d1533c 100644 --- a/lib/redmine-cli/cli.rb +++ b/lib/redmine-cli/cli.rb @@ -172,6 +172,7 @@ def map_project(project_name) def update_mapping_cache say 'Updating mapping cache...', :yellow # TODO: Updating user mapping requries Redmine 1.1+ + users = [] begin users = User.fetch_all.collect { |user| [ user.login, user.id ] } rescue Exception => e @@ -186,7 +187,6 @@ def update_mapping_cache 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. File.open(File.expand_path('~/.redmine_cache'), 'w') do |out|