backlogcp 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 692c203029420cb10eddbbdc29732393a4dfd32b
4
+ data.tar.gz: f581c630b95305d0d0a1d79f5975f04ff4b0b732
5
+ SHA512:
6
+ metadata.gz: b9345472cf5336779f3543619e1fe1cbe3a5b49fc2423447620df4d62ce1d158e74db09ee76cfb1325f8f1ec2a832a933eee292eb209bbce70852a5c23224a12
7
+ data.tar.gz: ffdf914a2c1d7731fb6bef994738d3f8e942fefd8320eaf762611425c721218cfdb79a0ffae890f078354e59ab028cbade012e8f586e2fd0fd9e5bf53422d881
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,71 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.1
3
+
4
+ Lint/Eval:
5
+ Enabled: false
6
+
7
+ Lint/HandleExceptions:
8
+ Enabled: false
9
+
10
+ Lint/UselessAssignment:
11
+ Enabled: false
12
+
13
+ Metrics/AbcSize:
14
+ Max: 50
15
+
16
+ Metrics/ClassLength:
17
+ Max: 120
18
+
19
+ Metrics/CyclomaticComplexity:
20
+ Max: 15
21
+
22
+ Metrics/LineLength:
23
+ Max: 120
24
+
25
+ Metrics/MethodLength:
26
+ Max: 30
27
+
28
+ Metrics/PerceivedComplexity:
29
+ Max: 15
30
+
31
+ Performance/StringReplacement:
32
+ Enabled: false
33
+
34
+ Style/Alias:
35
+ Enabled: false
36
+
37
+ Style/BarePercentLiterals:
38
+ Enabled: false
39
+
40
+ Style/ClassAndModuleChildren:
41
+ Enabled: false
42
+
43
+ Style/Documentation:
44
+ Enabled: false
45
+
46
+ Style/MutableConstant:
47
+ Enabled: false
48
+
49
+ Style/MultilineOperationIndentation:
50
+ Enabled: false
51
+
52
+ Style/MultilineMethodCallBraceLayout:
53
+ Enabled: false
54
+
55
+ Style/StabbyLambdaParentheses:
56
+ Enabled: false
57
+
58
+ Style/PercentLiteralDelimiters:
59
+ Enabled: false
60
+
61
+ Style/PredicateName:
62
+ Enabled: false
63
+
64
+ Style/RedundantSelf:
65
+ Enabled: false
66
+
67
+ Style/SymbolProc:
68
+ Enabled: false
69
+
70
+ Style/BracesAroundHashParameters:
71
+ Enabled: false
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ - 2.2.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in backlogcp.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 k1LoW
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.
@@ -0,0 +1,60 @@
1
+ # backlogcp
2
+
3
+ Backlog file copy command like `scp`.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'backlogcp', github: "k1LoW/backlogcp"
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install specific_install
20
+ $ gem specific_install https://github.com/k1LoW/backlogcp.git
21
+
22
+ ## Usage
23
+
24
+ ### STEP1
25
+
26
+ Copy Backlog file URI.
27
+
28
+ Example:
29
+
30
+ - https://xxxxxxxxx.backlog.jp/file/XXXXX/path/to/file.png
31
+ - https://xxxxxxxxx.backlog.jp/ViewAttachment.action?attachmentId=000000000000
32
+ - https://xxxxxxxxx.backlog.jp/downloadAttachment/000000000000/file.png
33
+
34
+ ### STEP2
35
+
36
+ Use `backlogcp` command like `scp`.
37
+
38
+ ```sh
39
+ $ export BACKLOG_SPACE_ID=xxxxxxxxx BACKLOG_API_KEY=XXXXXxxxXXXXxxXXXXXxXXXXXXX
40
+ $ backlogcp https://xxxxxxxxx.backlog.jp/file/XXXXX/path/to/file.png ./
41
+ ```
42
+
43
+ ## Support file type
44
+
45
+ - Shared file
46
+ - Attachment file on issue
47
+
48
+ ## Development
49
+
50
+ 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.
51
+
52
+ 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).
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it ( https://github.com/k1LoW/backlogcp/fork )
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create a new Pull Request
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ require 'octorelease'
6
+ rescue LoadError
7
+ end
8
+
9
+ RSpec::Core::RakeTask.new(:spec)
10
+
11
+ task default: :spec
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'backlogcp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'backlogcp'
8
+ spec.version = Backlogcp::VERSION
9
+ spec.authors = ['k1LoW']
10
+ spec.email = ['k1lowxb@gmail.com']
11
+
12
+ spec.summary = 'Backlog file copy command like scp.'
13
+ spec.description = 'Backlog file copy command like scp.'
14
+ spec.homepage = 'https://github.com/k1LoW/backlogcp'
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_runtime_dependency 'backlog_kit'
23
+ spec.add_development_dependency 'bundler', '~> 1.9'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'rubocop', '~> 0.40.0'
27
+ spec.add_development_dependency 'octorelease'
28
+ spec.add_development_dependency 'pry'
29
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'backlogcp'
5
+ require 'pry'
6
+ Pry.start
@@ -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
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'backlogcp'
4
+
5
+ Backlogcp::CLI.new.run
@@ -0,0 +1,5 @@
1
+ require 'backlogcp/version'
2
+ require 'backlogcp/cli'
3
+
4
+ module Backlogcp
5
+ end
@@ -0,0 +1,123 @@
1
+ require 'optparse'
2
+ require 'backlog_kit'
3
+ require 'uri'
4
+
5
+ module Backlogcp
6
+ class CLI
7
+ def run
8
+ opts, args = parse_options
9
+ dl(args[0], args[1])
10
+ end
11
+
12
+ private
13
+
14
+ def dl(from, to)
15
+ if %r(^.+backlog.jp/file/) =~ URI.unescape(from)
16
+ dl_from_shared_file(from, to)
17
+ else
18
+ dl_from_issue_attachment(from, to)
19
+ end
20
+ end
21
+
22
+ # https://[space_id].backlog.jp/file/[project_key]/[dir][filename]
23
+ def dl_from_shared_file(from, to)
24
+ unless %r(^.+backlog.jp/file/(?<project_key>[^/]+)(?<dir>/?.*/)(?<filename>[^/]+)$) =~ URI.unescape(from)
25
+ usage '<from> option should be backlog.jp URI.'
26
+ end
27
+ local = File.expand_path(to)
28
+ to_file_path = if File.directory?(local)
29
+ local + '/' + filename
30
+ else
31
+ local
32
+ end
33
+ client = BacklogKit::Client.new
34
+ files = client.get_shared_files(project_key, dir).body
35
+ selected = files.find do |res|
36
+ res.name == filename
37
+ end
38
+ puts to_file_path
39
+ res = client.download_shared_file(project_key, selected.id)
40
+ File.binwrite(to_file_path, res.body.content)
41
+ end
42
+
43
+ # https://[space_id].backlog.jp/ViewAttachment.action?attachmentId=[attachment_id]
44
+ def dl_from_issue_attachment(from, to)
45
+ if %r(^.+backlog.jp/.+attachmentId=(?<attachment_id>[^/]+)$) =~ URI.unescape(from)
46
+ elsif %r(^.+backlog.jp/downloadAttachment/(?<attachment_id>[^/]+)) =~ URI.unescape(from)
47
+ else
48
+ usage '<from> option should be backlog.jp URI.'
49
+ end
50
+
51
+ selected, attachment = get_issue_and_attachment(attachment_id)
52
+
53
+ filename = attachment.name
54
+ local = File.expand_path(to)
55
+ to_file_path = if File.directory?(local)
56
+ local + '/' + filename
57
+ else
58
+ local
59
+ end
60
+ puts to_file_path
61
+ client = BacklogKit::Client.new
62
+ res = client.download_issue_attachment(selected.issueKey, attachment.id)
63
+ File.binwrite(to_file_path, res.body.content)
64
+ end
65
+
66
+ # http://qiita.com/sonots/items/1b44ed3a770ef790a63d
67
+ def parse_options(argv = ARGV)
68
+ op = OptionParser.new
69
+
70
+ self.class.module_eval do
71
+ define_method(:usage) do |msg = nil|
72
+ puts op.to_s
73
+ puts "error: #{msg}" if msg
74
+ exit 1
75
+ end
76
+ end
77
+
78
+ opts = {}
79
+
80
+ op.banner += ' <from:Backlog shared file URI> <to>'
81
+
82
+ begin
83
+ args = op.parse(argv)
84
+ rescue OptionParser::InvalidOption => e
85
+ usage e.message
86
+ end
87
+
88
+ usage 'number of arguments is less than 2' if args.size < 2
89
+
90
+ [opts, args]
91
+ end
92
+
93
+ def get_issue_and_attachment(attachment_id)
94
+ client = BacklogKit::Client.new
95
+
96
+ selected = nil
97
+ attachment = nil
98
+ limit = 100
99
+ offset = 0
100
+ loop do
101
+ issues = client.get_issues({
102
+ attachment: true,
103
+ count: limit,
104
+ offset: offset * limit
105
+ }).body
106
+ issues.each do |issue|
107
+ issue.attachments.each do |a|
108
+ if a.id.to_s == attachment_id
109
+ attachment = a
110
+ selected = issue
111
+ end
112
+ end
113
+ end
114
+
115
+ (!selected && issues.length == limit) || break
116
+ offset += 1
117
+ end
118
+ usage 'file not found' unless selected
119
+
120
+ [selected, attachment]
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,3 @@
1
+ module Backlogcp
2
+ VERSION = '0.2.0'
3
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backlogcp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - k1LoW
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: backlog_kit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.40.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.40.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: octorelease
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Backlog file copy command like scp.
112
+ email:
113
+ - k1lowxb@gmail.com
114
+ executables:
115
+ - backlogcp
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - ".rubocop.yml"
122
+ - ".travis.yml"
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - backlogcp.gemspec
128
+ - bin/console
129
+ - bin/setup
130
+ - exe/backlogcp
131
+ - lib/backlogcp.rb
132
+ - lib/backlogcp/cli.rb
133
+ - lib/backlogcp/version.rb
134
+ homepage: https://github.com/k1LoW/backlogcp
135
+ licenses:
136
+ - MIT
137
+ metadata: {}
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 2.2.2
155
+ signing_key:
156
+ specification_version: 4
157
+ summary: Backlog file copy command like scp.
158
+ test_files: []