redmine-cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in redmine-cli.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ redmine-cli (0.0.1)
5
+ activeresource (~> 3.0.0)
6
+ thor
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ activemodel (3.0.1)
12
+ activesupport (= 3.0.1)
13
+ builder (~> 2.1.2)
14
+ i18n (~> 0.4.1)
15
+ activeresource (3.0.1)
16
+ activemodel (= 3.0.1)
17
+ activesupport (= 3.0.1)
18
+ activesupport (3.0.1)
19
+ builder (2.1.2)
20
+ columnize (0.3.1)
21
+ i18n (0.4.2)
22
+ linecache (0.43)
23
+ ruby-debug (0.10.3)
24
+ columnize (>= 0.1)
25
+ ruby-debug-base (~> 0.10.3.0)
26
+ ruby-debug-base (0.10.3)
27
+ linecache (>= 0.3)
28
+ thor (0.14.3)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ activeresource (~> 3.0.0)
35
+ redmine-cli!
36
+ ruby-debug
37
+ thor
data/README.markdown ADDED
@@ -0,0 +1,11 @@
1
+ # A command line interface for redmine
2
+
3
+ ## Use cases
4
+
5
+ redmine list
6
+ redmine list -a
7
+ redmine show 524
8
+ redmine update 524 -d "New description"
9
+ redmine update 256 --assigned_to "me"
10
+ redmine update 2,3,4 --assigned_to "me"
11
+ redmine list --status 1 | xargs redmine update --asigned_to "me" --status 3 -l
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/bin/redmine ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ lib = Pathname.new(__FILE__).dirname.join('..', 'lib').expand_path
5
+ $LOAD_PATH.unshift lib.to_s
6
+
7
+ require 'redmine-cli'
8
+
9
+ Redmine::Cli::CLI.start
@@ -0,0 +1,4 @@
1
+ require 'thor'
2
+ require 'active_resource'
3
+ require 'redmine-cli/issue'
4
+ require 'redmine-cli/cli'
@@ -0,0 +1,141 @@
1
+ module Redmine
2
+ module Cli
3
+ class CLI < Thor
4
+ desc "list", "List all issues for the user"
5
+ method_option :assigned_to, :aliases => "-a", :desc => "id or user name of person the ticket is assigned to"
6
+ method_option :status, :aliases => "-s", :desc => "id or name of status for ticket"
7
+ method_option :std_output, :aliases => "-o", :type => :boolean,
8
+ :desc => "special output for STDOUT (useful for updates)"
9
+ def list
10
+ params = {}
11
+
12
+ params[:assigned_to_id] = map_user(options.assigned_to) if options.assigned_to
13
+
14
+ params[:status_id] = map_status(options.status) if options.status
15
+
16
+ collection = Issue.all(:params => params)
17
+
18
+ unless options.std_output
19
+ issues = collection.collect { |issue| [link_to_issue(issue.id), issue.subject, issue.status.name] }
20
+
21
+ if issues.any?
22
+ issues.insert(0, ["URL", "Subject", "Status"])
23
+ print_table(issues)
24
+ end
25
+ else
26
+ say collection.collect(&:id).join(",")
27
+ end
28
+ end
29
+
30
+ desc "show TICKET", "Display information of a ticket"
31
+ def show(ticket)
32
+ issue = Issue.find(ticket)
33
+
34
+ display_issue(issue)
35
+ rescue ActiveResource::ResourceNotFound
36
+ say "No ticket with number: #{ticket}", :red
37
+ end
38
+
39
+ method_option :assigned_to, :aliases => "-a", :desc => "id or user name of person the ticket is assigned to"
40
+ method_option :status, :aliases => "-s", :desc => "id or name of status for ticket"
41
+ method_option :project, :aliases => "-p", :desc => "project for the ticket"
42
+ desc "new SUBJECT [DESCRIPTION]", "Create a new ticket"
43
+ def new(subject, description="")
44
+ params =
45
+ Thor::CoreExt::HashWithIndifferentAccess.new(:subject => subject,
46
+ :description => description,
47
+ :project => Issue.config.default_project_id)
48
+ params.merge!(options)
49
+
50
+ unless params.project
51
+ raise "No default project specified"
52
+ end
53
+
54
+ issue = Issue.create(ticket_attributes(params))
55
+
56
+ say "Created ticket: #{link_to_issue(issue.id)}", :green
57
+ rescue ActiveResource::ResourceNotFound
58
+ say "Could not create ticket with: #{options.inspect}", :red
59
+ rescue RuntimeError => e
60
+ say e.message, :red
61
+ end
62
+
63
+ method_option :tickets, :aliases => "-l", :desc => "list of tickets"
64
+ method_option :status, :aliases => "-s", :desc => "id or name of status for ticket"
65
+ method_option :subject, :aliases => "-t", :desc => "subject for ticket (title)"
66
+ method_option :description, :aliases => "-d", :desc => "description for ticket"
67
+ method_option :assigned_to, :aliases => "-a", :desc => "id or user name of person the ticket is assigned to"
68
+ desc "update [TICKETS]", "Update tickets"
69
+ def update(tickets = "")
70
+ tickets = options.tickets if tickets.blank? && options.tickets.present?
71
+
72
+ tickets = tickets.split(",")
73
+
74
+ if tickets.empty?
75
+ say "No tickets to update", :red
76
+ exit 1
77
+ end
78
+
79
+ tickets.collect { |ticket| Thread.new { update_ticket(ticket, options) } }.each(&:join)
80
+ end
81
+
82
+ no_tasks do
83
+ def link_to_issue(id)
84
+ "#{Issue.config.url}/issues/#{id}"
85
+ end
86
+
87
+ def ticket_attributes(options)
88
+ attributes = {}
89
+
90
+ attributes[:subject] = options.subject if options.subject.present?
91
+ attributes[:description] = options.description if options.description.present?
92
+ attributes[:project_id] = options.project if options.project.present?
93
+ attributes[:assigned_to_id] = map_user(options.assigned_to) if options.assigned_to.present?
94
+ attributes[:status_id] = options.status if options.status.present?
95
+
96
+ attributes
97
+ end
98
+
99
+ def display_issue(issue)
100
+ shell.print_wrapped "#{link_to_issue(issue.id)} - #{issue.status.name}"
101
+ shell.print_wrapped "Subject: #{issue.subject}"
102
+ shell.print_wrapped issue.description || "", :ident => 2
103
+ end
104
+
105
+ def map_user(user_name)
106
+ get_mapping(:user_mappings, user_name)
107
+ end
108
+
109
+ def map_status(status_name)
110
+ get_mapping(:status_mappings, status_name)
111
+ end
112
+
113
+ def get_mapping(mapping, value)
114
+ return value if value.to_i != 0
115
+
116
+ if Issue.config[mapping].nil? || (mapped = Issue.config[mapping][value]).nil?
117
+ say "No #{mapping} for #{value}", :red
118
+ exit 1
119
+ end
120
+
121
+ return mapped
122
+ end
123
+
124
+ def update_ticket(ticket, options)
125
+ issue = Issue.find(ticket)
126
+ params = ticket_attributes(options)
127
+
128
+ if issue.update_attributes(params)
129
+ say "Updated: #{ticket}. Options: #{params.inspect}", :green
130
+ display_issue(issue)
131
+ else
132
+ say "Could not update ticket with: #{params.inspect}", :red
133
+ end
134
+ rescue ActiveResource::ResourceNotFound
135
+ say "Could not find ticket: #{ticket}", :red
136
+ end
137
+
138
+ end
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,16 @@
1
+ module Redmine
2
+ module Cli
3
+ class Issue < ActiveResource::Base
4
+ def self.config
5
+ @config ||= Thor::CoreExt::HashWithIndifferentAccess.new(YAML.load_file(File.expand_path("~/.redmine")))
6
+ rescue Errno::ENOENT
7
+ puts "You need to create the file .redmine in your home with your username, password and url"
8
+ exit(1)
9
+ end
10
+
11
+ self.site = config.url
12
+ self.user = config.username
13
+ self.password = config.password
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module Redmine
2
+ module Cli
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "redmine-cli/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "redmine-cli"
7
+ s.version = Redmine::Cli::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jorge Dias"]
10
+ s.email = ["jorge@mrdias.com"]
11
+ s.homepage = "http://rubygems.org/gems/redmine-cli"
12
+ s.summary = %q{Command line interface for redmine}
13
+ s.description = %q{A simple command line interface for redmine for easy scripting}
14
+
15
+ s.rubyforge_project = "redmine-cli"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency "activeresource", "~>3.0.0"
23
+ s.add_dependency "thor"
24
+ s.add_development_dependency "ruby-debug"
25
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redmine-cli
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Jorge Dias
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-30 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: activeresource
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ - 0
34
+ version: 3.0.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: thor
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 3
46
+ segments:
47
+ - 0
48
+ version: "0"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: ruby-debug
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :development
64
+ version_requirements: *id003
65
+ description: A simple command line interface for redmine for easy scripting
66
+ email:
67
+ - jorge@mrdias.com
68
+ executables:
69
+ - redmine
70
+ extensions: []
71
+
72
+ extra_rdoc_files: []
73
+
74
+ files:
75
+ - .gitignore
76
+ - Gemfile
77
+ - Gemfile.lock
78
+ - README.markdown
79
+ - Rakefile
80
+ - bin/redmine
81
+ - lib/redmine-cli.rb
82
+ - lib/redmine-cli/cli.rb
83
+ - lib/redmine-cli/issue.rb
84
+ - lib/redmine-cli/version.rb
85
+ - redmine-cli.gemspec
86
+ has_rdoc: true
87
+ homepage: http://rubygems.org/gems/redmine-cli
88
+ licenses: []
89
+
90
+ post_install_message:
91
+ rdoc_options: []
92
+
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 3
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ requirements: []
114
+
115
+ rubyforge_project: redmine-cli
116
+ rubygems_version: 1.3.7
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: Command line interface for redmine
120
+ test_files: []
121
+