Skip to content

Some new features #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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
63 changes: 56 additions & 7 deletions lib/redmine-cli/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -134,22 +161,40 @@ 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

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.
File.open(File.expand_path('~/.redmine_cache'), 'w') do |out|
YAML.dump({
:user_mappings => Hash[users],
:project_mappings => Hash[projects],
:priority_mappings => priorities,
:status_mappings => status,
}, out)
end
end
Expand Down Expand Up @@ -204,6 +249,10 @@ def ask_password(prompt)
system "stty echo"
password
end

def default_parameters
{:limit => 100}
end
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions lib/redmine-cli/resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion redmine-cli.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down