backlog-cli 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +61 -0
- data/Rakefile +1 -0
- data/backlog-cli.gemspec +25 -0
- data/bin/backlog-cli +4 -0
- data/lib/backlog/cli.rb +3 -0
- data/lib/backlog/cli/commands.rb +138 -0
- data/lib/backlog/cli/core.rb +92 -0
- data/lib/backlog/cli/version.rb +5 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dae7886f4a5083ae91c24e3fda8765f1ba434595
|
4
|
+
data.tar.gz: 319ab4c09155767e5e6ea6812177da97b3e19292
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 944d3f93e99ae096cc717293a551892dada62f89bd66f63de289b8d3f2f52b85d34118e442fdc809e69e13b4bd38dc601210cf4bd2adf3ddfdc6da2e9698c52f
|
7
|
+
data.tar.gz: 16b28921818dcf7caa4ae7da5c7f32c73538559cae388d4ed59327a55248fa0b3558ddba93c604ab757bea6d6b1a8155699581fbbd4fcd18b3af3238c37e58bb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 toyama0919
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Backlog::Cli
|
2
|
+
|
3
|
+
Backlog Command Line Interface
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'backlog-cli'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install backlog-cli
|
18
|
+
|
19
|
+
## Setting File(required)
|
20
|
+
|
21
|
+
```yaml:$HOME/.backlogrc
|
22
|
+
|
23
|
+
default:
|
24
|
+
space: toyama0919
|
25
|
+
user: toyama0919
|
26
|
+
password: hogehoge
|
27
|
+
assigner_id: 4604
|
28
|
+
|
29
|
+
company:
|
30
|
+
space: hoge
|
31
|
+
user: toyama-h
|
32
|
+
password: hogehoge
|
33
|
+
assigner_id: 19981
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
### use default profile
|
40
|
+
```bash
|
41
|
+
backlog-cli -l PROJ
|
42
|
+
```
|
43
|
+
|
44
|
+
### use other profile
|
45
|
+
```bash
|
46
|
+
backlog-cli -l PROJ --profile company
|
47
|
+
```
|
48
|
+
|
49
|
+
### help
|
50
|
+
```bash
|
51
|
+
backlog-cli -l PROJ --profile company
|
52
|
+
```
|
53
|
+
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it ( http://github.com/<my-github-username>/backlog-cli/fork )
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/backlog-cli.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'backlog/cli/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "backlog-cli"
|
8
|
+
spec.version = Backlog::Cli::VERSION
|
9
|
+
spec.authors = ["toyama0919"]
|
10
|
+
spec.email = ["toyama0919@gmail.com"]
|
11
|
+
spec.summary = %q{Backlog command line interface.}
|
12
|
+
spec.description = %q{Backlog command line interface.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_runtime_dependency "feed-normalizer"
|
24
|
+
spec.add_runtime_dependency "thor"
|
25
|
+
end
|
data/bin/backlog-cli
ADDED
data/lib/backlog/cli.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
require 'thor'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
class Hash
|
7
|
+
def symbolize_keys!
|
8
|
+
keys.each do |key|
|
9
|
+
self[(key.to_sym rescue key) || key] = delete(key)
|
10
|
+
end
|
11
|
+
self
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Backlog
|
16
|
+
module Cli
|
17
|
+
class Commands < Thor
|
18
|
+
class_option :profile, type: :string, default: 'default', desc: 'profile by .backlogrc'
|
19
|
+
map '-v' => :version, '-s' => :find_issue, '-u' => :update_issue, '-n' => :create_issue, '-l' => :list, '-o' => :open
|
20
|
+
|
21
|
+
def initialize(args = [], options = {}, config = {})
|
22
|
+
super(args, options, config)
|
23
|
+
profile = config[:shell].base.options['profile']
|
24
|
+
@core = Backlog::Cli::Core.new(profile)
|
25
|
+
end
|
26
|
+
|
27
|
+
desc '-n [project key] -s [issue summary] -d [issue description] --assigner_id [assigner_id]', 'create_issue'
|
28
|
+
option :summary, type: :string, aliases: '-s', desc: 'issue summary'
|
29
|
+
option :description, type: :string, aliases: '-d', desc: 'issue description'
|
30
|
+
option :assignerId, type: :string, desc: 'assigner id, see get_users.'
|
31
|
+
def create_issue(project_key)
|
32
|
+
puts JSON.pretty_generate(@core.create_issue(project_key.upcase, options))
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'get_comments -k [issue key]', 'get comments'
|
36
|
+
option :key, type: :string, aliases: '-k', desc: 'issue key'
|
37
|
+
def get_comments
|
38
|
+
puts JSON.pretty_generate(@core.get_comments(options))
|
39
|
+
end
|
40
|
+
|
41
|
+
desc '-u -k [issue key] -c [issue comment]', 'add comment'
|
42
|
+
option :key, type: :string, aliases: '-k', desc: 'issue key'
|
43
|
+
option :comment, type: :string, aliases: '-c', desc: 'issue comment'
|
44
|
+
def update_issue
|
45
|
+
puts JSON.pretty_generate(@core.update_issue(options))
|
46
|
+
end
|
47
|
+
|
48
|
+
desc 'get_issue -k [issue key]', 'get issue'
|
49
|
+
option :key, type: :string, aliases: '-k', desc: 'issue key'
|
50
|
+
def get_issue
|
51
|
+
result = @core.get_issue(options)
|
52
|
+
puts JSON.pretty_generate(result)
|
53
|
+
end
|
54
|
+
|
55
|
+
desc 'open -k [issue key]', 'open issue'
|
56
|
+
option :key, type: :string, aliases: '-k', desc: 'issue key'
|
57
|
+
def open
|
58
|
+
result = @core.get_issue(options)
|
59
|
+
`open #{result['url']}`
|
60
|
+
end
|
61
|
+
|
62
|
+
desc '-s [project key]', 'find issue'
|
63
|
+
option :project_key, type: :string, aliases: '-p', desc: 'project key'
|
64
|
+
option :limit, type: :numeric, aliases: '-n', desc: 'limit', default: 10
|
65
|
+
option :assignerId, type: :string, desc: 'assigner id, see get_users.'
|
66
|
+
option :query, type: :string, aliases: '-q', desc: 'query keyword.'
|
67
|
+
option :all, type: :boolean, desc: 'all issue', default: false
|
68
|
+
def find_issue(project_key)
|
69
|
+
results = @core.find_issue(project_key.upcase, options)
|
70
|
+
selected = results.map do |result|
|
71
|
+
result.select { |k, v| %w(id url key summary description).include? k }
|
72
|
+
end
|
73
|
+
puts JSON.pretty_generate(selected.reverse)
|
74
|
+
end
|
75
|
+
|
76
|
+
desc '-l [project key] -n [num]', 'list summary'
|
77
|
+
option :limit, type: :numeric, aliases: '-n', desc: 'limit', default: 10
|
78
|
+
def list(project_key)
|
79
|
+
items = @core.get_rss(project_key.upcase).slice(0, options[:limit])
|
80
|
+
results = []
|
81
|
+
items.each do |item|
|
82
|
+
result = {}
|
83
|
+
result[:title] = item.title
|
84
|
+
result[:content] = item.content
|
85
|
+
result[:authors] = item.authors.first
|
86
|
+
result[:date_published] = item.date_published
|
87
|
+
result[:url] = item.id
|
88
|
+
result[:urls] = @core.urls(item.content)
|
89
|
+
results << result
|
90
|
+
end
|
91
|
+
puts JSON.pretty_generate(results.reverse)
|
92
|
+
end
|
93
|
+
|
94
|
+
desc 'get_projects', 'get projects'
|
95
|
+
def get_projects
|
96
|
+
results = @core.get_projects
|
97
|
+
puts JSON.pretty_generate(results)
|
98
|
+
end
|
99
|
+
|
100
|
+
desc 'get_project_summaries', 'get project summaries'
|
101
|
+
def get_project_summaries
|
102
|
+
results = @core.get_project_summaries
|
103
|
+
puts JSON.pretty_generate(results)
|
104
|
+
end
|
105
|
+
|
106
|
+
desc 'get_users [project_key]', 'get users'
|
107
|
+
def get_users(project_key)
|
108
|
+
results = @core.get_users(project_key.upcase)
|
109
|
+
puts JSON.pretty_generate(results)
|
110
|
+
end
|
111
|
+
|
112
|
+
desc 'create_issue_by_file ', 'cat issue.txt | backlog-cli create_issue_by_file '
|
113
|
+
def create_issue_by_file
|
114
|
+
yaml = load_yaml
|
115
|
+
project_key = yaml.delete(:project_key)
|
116
|
+
@core.create_issue(project_key, yaml)
|
117
|
+
end
|
118
|
+
|
119
|
+
desc 'update_issue_by_file [project_key] ', 'cat issue.txt | backlog-cli update_issue_by_file '
|
120
|
+
def update_issue_by_file
|
121
|
+
@core.update_issue(load_yaml)
|
122
|
+
end
|
123
|
+
|
124
|
+
desc '-v', 'show version information'
|
125
|
+
def version
|
126
|
+
puts Backlog::Cli::VERSION
|
127
|
+
end
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
def load_yaml
|
132
|
+
yaml = YAML.load(STDIN.read)
|
133
|
+
yaml.symbolize_keys!
|
134
|
+
yaml
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
require 'xmlrpc/client'
|
5
|
+
require 'yaml'
|
6
|
+
require 'feed-normalizer'
|
7
|
+
|
8
|
+
module Backlog
|
9
|
+
module Cli
|
10
|
+
class Core
|
11
|
+
DOMAIN = 'backlog.jp'
|
12
|
+
def initialize(profile)
|
13
|
+
info = YAML.load_file("#{ENV['HOME']}/.backlogrc")[profile]
|
14
|
+
@user = info['user']
|
15
|
+
@space = info['space']
|
16
|
+
@password = info['password']
|
17
|
+
@assigner_id = info['assigner_id']
|
18
|
+
api_url = "https://#{@user}:#{@password}@#{@space}.#{DOMAIN}/XML-RPC"
|
19
|
+
@server = XMLRPC::Client.new2(api_url)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_issue(project_key, options)
|
23
|
+
args = options.dup
|
24
|
+
args[:projectId] = get_project(project_key)['id']
|
25
|
+
args[:assignerId] = options[:assigner_id].nil? ? @assigner_id : options[:assigner_id]
|
26
|
+
@server.call('backlog.createIssue', args)
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_comment(options)
|
30
|
+
args = { key: options[:key], content: options[:content] }
|
31
|
+
@server.call('backlog.addComment', args)
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_comments(options)
|
35
|
+
issue_id = get_issue(options)['id']
|
36
|
+
@server.call('backlog.getComments', issue_id)
|
37
|
+
end
|
38
|
+
|
39
|
+
def update_issue(options)
|
40
|
+
args = { key: options[:key], comment: options[:comment] }
|
41
|
+
@server.call('backlog.updateIssue', args)
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_issue(options)
|
45
|
+
@server.call('backlog.getIssue', options[:key])
|
46
|
+
end
|
47
|
+
|
48
|
+
def find_issue(project_key, options)
|
49
|
+
args = options.dup
|
50
|
+
args[:projectId] = get_project(project_key)['id']
|
51
|
+
args[:statusId] = [1, 2, 3]
|
52
|
+
args[:sort] = 'UPDATED'
|
53
|
+
if options[:all]
|
54
|
+
args.delete(:assignerId)
|
55
|
+
else
|
56
|
+
args[:assignerId] = @assigner_id
|
57
|
+
end
|
58
|
+
@server.call('backlog.findIssue', args)
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_projects
|
62
|
+
@server.call('backlog.getProjects')
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_project_summaries
|
66
|
+
@server.call('backlog.getProjectSummaries')
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_users(project_key)
|
70
|
+
@server.call('backlog.getUsers', get_project(project_key)['id'])
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_rss(project_key)
|
74
|
+
feed = FeedNormalizer::FeedNormalizer.parse open(
|
75
|
+
"https://#{@space}.#{DOMAIN}/rss/#{project_key}", http_basic_authentication: [@user, @password]
|
76
|
+
)
|
77
|
+
feed.items
|
78
|
+
end
|
79
|
+
|
80
|
+
def urls(body)
|
81
|
+
regex = /https?\:\/\/[-_.!~*'()a-zA-Z0-9;\/?:@&=+$,%#]+/
|
82
|
+
body.scan(regex).uniq.sort.reverse
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def get_project(project_key)
|
88
|
+
@server.call('backlog.getProject', project_key)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: backlog-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- toyama0919
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: feed-normalizer
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Backlog command line interface.
|
70
|
+
email:
|
71
|
+
- toyama0919@gmail.com
|
72
|
+
executables:
|
73
|
+
- backlog-cli
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- backlog-cli.gemspec
|
83
|
+
- bin/backlog-cli
|
84
|
+
- lib/backlog/cli.rb
|
85
|
+
- lib/backlog/cli/commands.rb
|
86
|
+
- lib/backlog/cli/core.rb
|
87
|
+
- lib/backlog/cli/version.rb
|
88
|
+
homepage: ''
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.2.2
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Backlog command line interface.
|
112
|
+
test_files: []
|