backlog_bulk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c918a86432c6fd6a889c93bf4c798eba8d86c2f2
4
+ data.tar.gz: d3e3c2842ae9b67f5d60ac999f5455c70d66afce
5
+ SHA512:
6
+ metadata.gz: 8ed69c09ffac0450a75c95f9844f58efd4fa229bad42456dab83d5de8fb8471e275fbde6632604a572adc0fca9da4b0ee61948f3f71301194c1776ed8d276dbf
7
+ data.tar.gz: 2f15dcfef3a60850fe8aa13f0b3e429cbb72ef0298aacb8378bf8ae1b7dcd8972e069a699e3a9cc2f7e19520c1edcc7f832dbb9b85addf7a1929b02826db2992
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ backlog_bulk.conf
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in backlog_bulk.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 ISOBE Kazuhiko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # backlog_bulk
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/backlog_bulk`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ backlog_bulk is a script to post the issues and comments the same content on multiple projects of backlog.jp.
6
+
7
+ ## Installation
8
+
9
+ install it yourself as:
10
+
11
+ $ gem install backlog_bulk
12
+
13
+ ## Usage
14
+
15
+ ```
16
+ Commands:
17
+ backlog_bulk close --issuekeys <issuekeysfile>
18
+ backlog_bulk comment --issuekeys <issuekeysfile> --content <content_name>
19
+ backlog_bulk help [COMMAND]
20
+ backlog_bulk issue --projects <project_key_file>
21
+ backlog_bulk showissue --issuekeys <issuekeysfile>
22
+
23
+ Options:
24
+ c, [--config=CONFIG] # use config file
25
+ # Default: backlog_bulk.conf
26
+ d, [--debug], [--no-debug] # enable debug mode
27
+ ```
28
+
29
+ ### create issues
30
+
31
+ Create a file that contains project key per line.
32
+ for example:
33
+
34
+ ```
35
+ $ cat projects
36
+ ABC
37
+ DEF
38
+ GHI
39
+ ```
40
+
41
+ Create a config file (YAML format) named `backlog_bulk.conf`.
42
+ for example:
43
+
44
+ ```
45
+ ---
46
+ space: 'your backlog space name'
47
+ api_key: 'your backlog api key'
48
+ summary: 'issue subject'
49
+ startDate: '2015-01-01'
50
+ dueDate: '2015-12-31'
51
+ description: |
52
+ Hi, all
53
+
54
+ This is a multipost issue.
55
+ ```
56
+
57
+ Execute `backlog_bulk issue --projects projects`
58
+
59
+ ### comment
60
+
61
+ Create a `issuekeys` file that contains issue key per line.
62
+ for example:
63
+
64
+ ```
65
+ ABC-3
66
+ DEF-123
67
+ GHI-408
68
+ ```
69
+
70
+ Add config to comment content.
71
+ for example:
72
+
73
+ ```
74
+ ---
75
+ space: 'your backlog space name'
76
+ api_key: 'your backlog api key'
77
+ summary: 'issue subject'
78
+ startDate: '2015-01-01'
79
+ dueDate: '2015-12-31'
80
+ description: |
81
+ Hi, all
82
+
83
+ This is a multipost issue.
84
+ comment1: |
85
+ This is a comment example.
86
+ comment2: |
87
+ This is a comment example, too.
88
+ ```
89
+
90
+
91
+
92
+ `$ backlog_bulk comment --issuekeys issuekeys --content comment1`
93
+
94
+ ## Development
95
+
96
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec backlog_bulk` to use the code located in this directory, ignoring other installed copies of this gem.
97
+
98
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
99
+
100
+ ## Contributing
101
+
102
+ 1. Fork it ( https://github.com/[my-github-username]/backlog_bulk/fork )
103
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
104
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
105
+ 4. Push to the branch (`git push origin my-new-feature`)
106
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,8 @@
1
+ ---
2
+ space: 'your backlog space name'
3
+ api_key: 'your backlog api key'
4
+ summary: 'issue subject'
5
+ startDate: '2015-01-01'
6
+ dueDate: '2015-12-31'
7
+ description: |
8
+ This is a sample issue description.
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'backlog_bulk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "backlog_bulk"
8
+ spec.version = BacklogBulk::VERSION
9
+ spec.authors = ["ISOBE Kazuhiko"]
10
+ spec.email = ["muramasa64@gmail.com"]
11
+
12
+ spec.summary = %q{Bulk post to backlog.jp}
13
+ spec.description = %q{backlog_bulk is a script to post the issues and comments the same content on multiple projects of backlog.jp.}
14
+ spec.homepage = "https://github.com/muramasa64/backlog_bulk"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_dependency "thor", "~> 0.19"
25
+ spec.add_dependency "backlog_jp", "~> 0.0.9"
26
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "backlog_bulk"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/backlog_bulk ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "backlog_bulk"
4
+
5
+ BacklogBulk::CLI.start
@@ -0,0 +1,7 @@
1
+ require "backlog_bulk/version"
2
+ require "backlog_bulk/cli"
3
+ require "backlog_bulk/config"
4
+
5
+ module BacklogBulk
6
+ # Your code goes here...
7
+ end
@@ -0,0 +1,150 @@
1
+ # coding: utf-8
2
+ require 'backlog_bulk'
3
+ require 'backlog_jp'
4
+ require 'logger'
5
+ require 'thor'
6
+
7
+ module BacklogBulk
8
+ class CLI < Thor
9
+ class_option :config, aliases: [:c], type: :string, desc: "use config file", default: "backlog_bulk.conf"
10
+ class_option :debug, aliases: [:d], type: :boolean, desc: "enable debug mode", default: false
11
+
12
+ desc "issue --projects <project_key_file>", ""
13
+ option :projects, aliases: [:p], type: :string, desc: "project key each line"
14
+ def issue
15
+ conf = BacklogBulk::Config.new(options)
16
+ @client = BacklogJp::Client.new(space: conf.space, api_key: conf.api_key)
17
+ $stderr.puts @client.inspect if conf.debug
18
+ priority_id = get_priority_id(@client)
19
+ unless priority_id
20
+ $stderr.puts "initialize failed: priority_id => nil"
21
+ exit 1
22
+ end
23
+
24
+ open(conf.projects, 'r').each_line do |project_key|
25
+ project_key.chomp!
26
+ project_id, issue_type_id = init_project(@client, project_key)
27
+ unless project_id && issue_type_id
28
+ $stderr.puts "initialize failed: project_key =>#{project_key}, projec_id => #{project_id.inspect}, issue_type => #{issue_type_id.inspect}"
29
+ exit 1
30
+ end
31
+
32
+ begin
33
+ result = @client.post 'issues',
34
+ 'projectId': project_id,
35
+ 'issueTypeId': issue_type_id,
36
+ 'summary': conf.summary,
37
+ 'startDate': conf.startDate,
38
+ 'priorityId': priority_id,
39
+ 'description': conf.description
40
+ puts "post new issue success: project_key => #{project_key} issueKey => #{result[:issueKey]}"
41
+ rescue BacklogJp::Client::APIException => e
42
+ $stderr.puts "post new issue failed: project_key => #{project_key} #{e}"
43
+ end
44
+ end
45
+ end
46
+
47
+ desc "comment --issuekeys <issuekeysfile> --content <content_name>", ""
48
+ option :issuekeys, aliases: [:i], type: :string, desc: "issuekey each line", required: true
49
+ option :content, aliases: [:t], type: :string, desc: "content_name in config file", required: true
50
+ def comment
51
+ conf = BacklogBulk::Config.new(options)
52
+ @client = BacklogJp::Client.new(space: conf.space, api_key: conf.api_key)
53
+ $stderr.puts @client.inspect if conf.debug
54
+
55
+ open(conf.issuekeys, 'r').each_line do |issuekey|
56
+ issuekey.chomp!
57
+
58
+ begin
59
+ @client.post "issues/#{issuekey}/comments", content: conf[conf.content]
60
+ puts "post new comment\tsuccess\t#{issuekey}\t"
61
+ rescue BacklogJp::Client::APIException => e
62
+ $stderr.puts "post new comment failed: project_key => #{project_key} #{e}"
63
+ end
64
+ end
65
+ end
66
+
67
+ desc "showissue --issuekeys <issuekeysfile>", ""
68
+ option :issuekeys, aliases: [:i], type: :string, desc: "issuekey each line", required: true
69
+ def showissue
70
+ conf = BacklogBulk::Config.new(options)
71
+ @client = BacklogJp::Client.new(space: conf.space, api_key: conf.api_key)
72
+ $stderr.puts @client.inspect if conf.debug
73
+
74
+ open(conf.issuekeys, 'r').each_line do |issuekey|
75
+ issuekey.chomp!
76
+ begin
77
+ result = @client.get "issues/#{issuekey}"
78
+ puts "#{issuekey}\t#{result[:summary]}"
79
+ rescue BacklogJp::Client::APIException => e
80
+ $stderr.puts "show issue failed: issuekey => #{issuekey} #{e}"
81
+ end
82
+ end
83
+ end
84
+
85
+ desc "close --issuekeys <issuekeysfile>", ""
86
+ option :issuekeys, aliases: [:i], type: :string, desc: "issuekey each line", required: true
87
+ def close
88
+ conf = BacklogBulk::Config.new(options)
89
+ @client = BacklogJp::Client.new(space: conf.space, api_key: conf.api_key)
90
+ $stderr.puts @client.inspect if conf.debug
91
+ ss = get_statuses(@client)
92
+
93
+ open(conf.issuekeys, 'r').each_line do |issuekey|
94
+ issuekey.chomp!
95
+ begin
96
+ result = @client.patch "issues/#{issuekey}", statusId: ss['完了']
97
+ puts "#{issuekey}\t#{result[:status][:name]}"
98
+ rescue BacklogJp::Client::APIException => e
99
+ $stderr.puts "show issue failed: issuekey => #{issuekey} #{e}"
100
+ end
101
+ end
102
+ end
103
+
104
+ private
105
+ def get_statuses(client)
106
+ begin
107
+ r = client.get 'statuses'
108
+ ss = {}
109
+ r.each {|s| ss[s[:name]] = s[:id]}
110
+ return ss
111
+ rescue BacklogJp::Client::APIException => e
112
+ $stderr.puts "get statuses failed: #{e}"
113
+ end
114
+ end
115
+
116
+ def init_project(client, project_key)
117
+ [get_project_id(client, project_key), get_last_issue_type_id(client, project_key)]
118
+ end
119
+
120
+ def get_project_id(client, project_key)
121
+ p project_key
122
+ begin
123
+ project = client.get "projects/#{project_key}"
124
+ return project[:id]
125
+ rescue BacklogJp::Client::APIException => e
126
+ $stderr.puts "get projects failed: project_key => #{project_key} #{e}"
127
+ end
128
+ end
129
+
130
+ def get_priority_id(client)
131
+ begin
132
+ priorities = client.get 'priorities'
133
+ priority = priorities.find {|pri| pri[:name] == '中'}
134
+ return priority[:id]
135
+ rescue BacklogJp::Client::APIException => e
136
+ $stderr.puts "get priorities failed: #{e}"
137
+ end
138
+ end
139
+
140
+ def get_last_issue_type_id(client, project_key)
141
+ begin
142
+ issue_types = client.get "projects/#{project_key}/issueTypes"
143
+ issue_type = issue_types.max_by {|ts| ts[:displayOrder]}
144
+ return issue_type[:id]
145
+ rescue BacklogJp::Client::APIException => e
146
+ $stderr.puts "get issueTypes failed: project_key => #{project_key} #{e}"
147
+ end
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,39 @@
1
+ require 'backlog_bulk'
2
+ require 'ostruct'
3
+ require 'yaml'
4
+
5
+ module BacklogBulk
6
+ class Config < OpenStruct
7
+ def initialize(options = nil)
8
+ @table = {}
9
+ @hash_table = {}
10
+
11
+ if options
12
+ if options[:config]
13
+ conf = YAML.load_file(options[:config])
14
+ @table, @hash_table = load_config(conf)
15
+ end
16
+
17
+ @table, @hash_table = load_config(options, @table, @hash_table)
18
+ end
19
+ end
20
+
21
+ def to_h
22
+ @hash_table
23
+ end
24
+
25
+ private
26
+ def load_config(conf, table = {}, hash_table = {})
27
+ table = table.dup
28
+ hash_table = hash_table.dup
29
+ conf.each do |k,v|
30
+ table[k.to_sym] = (v.is_a?(Hash) ? self.class.new(v) : v)
31
+ hash_table[k.to_sym] = v
32
+
33
+ new_ostruct_member(k)
34
+ end
35
+ [table, hash_table]
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,3 @@
1
+ module BacklogBulk
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backlog_bulk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ISOBE Kazuhiko
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-09 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: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.19'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.19'
55
+ - !ruby/object:Gem::Dependency
56
+ name: backlog_jp
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.9
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.9
69
+ description: backlog_bulk is a script to post the issues and comments the same content
70
+ on multiple projects of backlog.jp.
71
+ email:
72
+ - muramasa64@gmail.com
73
+ executables:
74
+ - backlog_bulk
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - backlog_bulk.conf.sample
85
+ - backlog_bulk.gemspec
86
+ - bin/console
87
+ - bin/setup
88
+ - exe/backlog_bulk
89
+ - lib/backlog_bulk.rb
90
+ - lib/backlog_bulk/cli.rb
91
+ - lib/backlog_bulk/config.rb
92
+ - lib/backlog_bulk/version.rb
93
+ homepage: https://github.com/muramasa64/backlog_bulk
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.7
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Bulk post to backlog.jp
117
+ test_files: []
118
+ has_rdoc: