octokit_issue_export 0.0.1

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: 2636fbbcf4ef27a1eed011651327551f16cfc131
4
+ data.tar.gz: dd7c2564eefc124929d6dbc2ae839bc397bf9be6
5
+ SHA512:
6
+ metadata.gz: 94aed2fcef699347603573c3a81c358b3bc952e4be54b3174946a31504231299c67e08b37ddc1813ba444e0acb3dae1233cc6c5b4932ce3b01d04b553c3ab31a
7
+ data.tar.gz: b6d0792b7bb873fd678060ff29bbe290a8565a360e221834bbf40ab6d674ceb982afcd2d5ec3f4dc7653ab7da3f114d118d90ba63ec9b79b2c59bd981658d85e
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in octokit_issue_export.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 linyows
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,53 @@
1
+ OctokitIssueExport
2
+ ==================
3
+
4
+ Export issues from projects on GitHub
5
+
6
+ Installation
7
+ ------------
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'octokit_issue_export'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install octokit_issue_export
20
+
21
+ Usage
22
+ -----
23
+
24
+ ```
25
+ # Provide authentication credentials
26
+ Octokit.configure do |c|
27
+ c.login = 'defunkt'
28
+ c.password = 'c0d3b4ssssss!'
29
+ end
30
+
31
+ # Fetch the current user
32
+ Octokit.export_org_issues('rails')
33
+ ```
34
+
35
+ Contributing
36
+ ------------
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
43
+
44
+ Author
45
+ ------
46
+
47
+ - [@linyows](https://github.com/linyows)
48
+
49
+
50
+ License
51
+ -------
52
+
53
+ MIT
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,101 @@
1
+ module Octokit
2
+ class Client
3
+ module IssueExport
4
+ def export_issues(username = nil)
5
+ username = login if username.nil?
6
+ repos(username).each { |repo| export_issues_by_repo(repo) }
7
+ end
8
+
9
+ def export_organization_issues(organization)
10
+ org_repos(organization).each { |repo| export_issues_by_repo(repo) }
11
+ end
12
+ alias :export_org_issues :export_organization_issues
13
+
14
+ def export_issues_by_repository(repo)
15
+ self._dir_for_export = File.join(%w(.) + repo.full_name.split('/'))
16
+
17
+ puts "[#{repo.full_name}]"
18
+ if repo(repo.full_name).has_issues?
19
+ _export_issues_by_repository(repo.full_name)
20
+ else
21
+ puts "- project without issues"
22
+ end
23
+ end
24
+ alias :export_issues_by_repo :export_issues_by_repository
25
+
26
+ def _export_issues_by_repository(repo)
27
+ %i(open closed).each { |state|
28
+ page = 1
29
+ loop do
30
+ paged_issues = issues(repo,
31
+ per_page: 100,
32
+ page: page,
33
+ state: state)
34
+ break if paged_issues.empty?
35
+ paged_issues.each { |issue|
36
+ _output_for_export(issue.number, state, issue.comments, issue.title)
37
+ _export_issue(repo, issue)
38
+ }
39
+ page += 1
40
+ end
41
+ }
42
+ end
43
+
44
+ def _output_for_export(number, state, comments, title)
45
+ puts <<-OUTPUT.gsub(/\s{10}/, '').gsub(/\n/, '')
46
+ - #{"##{number}".rjust(4)},
47
+ state: #{state.to_s.rjust(6)},
48
+ comments: #{comments.to_s.rjust(3)},
49
+ title: "#{title.to_s}"
50
+ OUTPUT
51
+ end
52
+
53
+ def _export_issue(repo, issue)
54
+ data = _dump_resources(issue)
55
+
56
+ comment_data = []
57
+ page = 1
58
+ loop do
59
+ paged_comments = issue_comments(repo,
60
+ issue.number,
61
+ per_page: 100,
62
+ page: page)
63
+ break if paged_comments.empty?
64
+ paged_comments.each { |comment| comment_data << _dump_resources(comment) }
65
+ page += 1
66
+ end
67
+
68
+ data.merge!(comment_data: comment_data)
69
+ file = File.join(_dir_for_export, "#{issue.number}.json")
70
+ _export_json(data, file)
71
+ end
72
+
73
+ def _dump_resources(resources)
74
+ return resources unless resources.respond_to?(:attrs)
75
+ resources.attrs.each_with_object({}) do |(k,v), result|
76
+ result[k] = v.respond_to?(:attrs) ? v.attrs : v
77
+ end
78
+ end
79
+
80
+ def _dir_for_export=(path)
81
+ _mkdir_recursive(path)
82
+ @_dir_for_export = path
83
+ end
84
+
85
+ def _dir_for_export
86
+ @_dir_for_export
87
+ end
88
+
89
+ def _mkdir_recursive(path)
90
+ return if File.directory?(path)
91
+ parent = File::dirname(path)
92
+ _mkdir_recursive(parent)
93
+ Dir::mkdir(path)
94
+ end
95
+
96
+ def _export_json(data, file)
97
+ File.open(file , 'w') { |f| f.write JSON.pretty_generate(data) }
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,7 @@
1
+ require 'octokit/client/issue_export'
2
+
3
+ module Octokit
4
+ class Client
5
+ include Octokit::Client::IssueExport
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module OctokitIssueExport
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'octokit'
2
+ require 'octokit_issue_export/version'
3
+ require 'octokit_issue_export/client'
4
+
5
+ module OctokitIssueExport
6
+ end
@@ -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 'octokit_issue_export/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "octokit_issue_export"
8
+ spec.version = OctokitIssueExport::VERSION
9
+ spec.authors = ["linyows"]
10
+ spec.email = ["linyows@gmail.com"]
11
+ spec.description = %q{Octokit Extension}
12
+ spec.summary = %q{Export issues from projects on github}
13
+ spec.homepage = "https://github.com/linyows/octokit_issue_export"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_dependency "octokit", "~> 2.5.0"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "pry"
25
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: octokit_issue_export
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - linyows
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 2.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 2.5.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.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: pry
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
+ description: Octokit Extension
70
+ email:
71
+ - linyows@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/octokit/client/issue_export.rb
82
+ - lib/octokit_issue_export.rb
83
+ - lib/octokit_issue_export/client.rb
84
+ - lib/octokit_issue_export/version.rb
85
+ - octokit_issue_export.gemspec
86
+ homepage: https://github.com/linyows/octokit_issue_export
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.0.3
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Export issues from projects on github
110
+ test_files: []