github_issue_exporter 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: 354c890b4dfbc919bdf6a9f613c51f77e9749998
4
+ data.tar.gz: fd7dc8cf8f2c0e92f9c3dbaddb6f3f755b7be2e8
5
+ SHA512:
6
+ metadata.gz: ecb5b1495eb91c1c905286982274ef5e0551cbbc9b4f29ae264cc8addc85d0d7d0dd617b9a2071b1fb0cb2341af42974b1f54876c43ecd032cf31bd4fa22f871
7
+ data.tar.gz: 4dd49545cd5fa7db758abae755ebfafa573421c5a4d72aad17b9f63c588c770bbb6d6bd6632d9eb8c9afb03ab61270465deaa500159f3ca544665a24d336c0a6
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Scott Williams
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # GitHub Issue Exporter
2
+
3
+ [![Circle CI](https://circleci.com/gh/Tallwave/github_issue_exporter.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/Tallwave/github_issue_exporter) [![Code Climate](https://codeclimate.com/github/Tallwave/github_issue_exporter/badges/gpa.svg)](https://codeclimate.com/github/Tallwave/github_issue_exporter)
4
+
5
+ Need to archive some repositories that are stored on GitHub? Great. Don't forget to hold on to any open issues you may still have. GitHub Issue Exporter is a command-line utility that will download all the open issues for a single repository.
6
+
7
+ ## Installation
8
+
9
+ GitHub Issue Exporter is built with Ruby and needs Ruby 2.0 or higher. Install it with RubyGems.
10
+
11
+ ```
12
+ gem install github_issue_exporter
13
+ ```
14
+
15
+ Some environments may require `sudo` permissions.
16
+
17
+ ```
18
+ sudo gem install github_issue_exporter
19
+ ```
20
+
21
+ ## Usage
22
+ You'll need 3 things to run this, the name of the owner of the repository, the repository name, and an access token that has the authority to download the Issues. You can generate this token from [here](https://github.com/settings/tokens), and clicking on "Generate new token". Here's a [blog post with some more of the details involved](http://blog.swilliams.me/words/2015/04/01/two-factor-authentication-for-github/).
23
+
24
+ The Exporter has a couple of options.
25
+
26
+ `--multiple-files` By default Issue Exporter downloads and stores all the issues into a single JSON file. Setting the `multiple-files` flag will create a separate file for each Issue.
27
+
28
+ `--output` Set the directory to store the issues in. By default it is the current directory.
29
+
30
+ ## Roadmap
31
+
32
+ * Import issues back into a repository.
33
+ * Allow outputting to stdout.
34
+
35
+ ## Contributing
36
+
37
+ * Fork
38
+ * Make it better
39
+ * Create a Pull Request
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby -W
2
+ # Copyright (c) 2015 Scott Williams
3
+
4
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
5
+
6
+ require 'issue_exporter/cli'
7
+
8
+ module IssueExporting
9
+ class Command
10
+ include CLI
11
+
12
+ def about
13
+ VERSION
14
+ end
15
+
16
+ def usage
17
+ <<HERE
18
+ Download all open issues from a GitHub repository.
19
+
20
+ Usage: #{$PROGRAM_NAME} [OPTION]... [OWNER] [REPO] [TOKEN]
21
+
22
+ Example: #{$PROGRAM_NAME} swilliams issue_exporter abcdef
23
+
24
+ TOKEN is only necessary for private repositories.
25
+
26
+ -o, --output DIRECTORY
27
+ set output path
28
+ (default: current working directory)
29
+
30
+ --multiple-files Use a separate file for each issue
31
+ (default: one single file)
32
+
33
+ -h, --help display this help and exit
34
+ --version display the version
35
+
36
+ HERE
37
+
38
+ end
39
+
40
+ def initialize
41
+ super
42
+ @output = nil
43
+ @multiple_files = false
44
+ end
45
+
46
+ def define_options(opts)
47
+ opts.on('-o', '--output ARG') { |arg| @output = arg }
48
+ opts.on('--multiple-files') { @multiple_files = true }
49
+ end
50
+
51
+ def process_input(arg, index)
52
+ case index
53
+ when 0
54
+ @owner = arg
55
+ when 1
56
+ @repo = arg
57
+ when 2
58
+ @token = arg
59
+ end
60
+ end
61
+
62
+ def perform_action
63
+ options = { path: @output, multiple_files: @multiple_files }
64
+ exporter = IssueExporting::Exporter.new(@owner, @repo, @token, options)
65
+ exporter.export
66
+ end
67
+ end
68
+ end
69
+
70
+ IssueExporting::Command.new.run
@@ -0,0 +1,21 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/lib')
2
+
3
+ require 'issue_exporter'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'github_issue_exporter'
7
+ s.version = IssueExporting::VERSION
8
+ s.required_ruby_version = '>= 2.0'
9
+ s.summary = 'Tools to export GitHub Issues'
10
+ s.description = <<-HERE
11
+ Download Issues from a GitHub repository.
12
+ HERE
13
+ s.license = 'MIT'
14
+ s.author = 'Scott Williams'
15
+ s.email = 'scott@swilliams.me'
16
+ s.homepage = 'https://github.com/Tallwave/github_issue_exporter'
17
+ s.files = Dir['{bin,lib}/**/*'] + ['github_issue_exporter.gemspec']
18
+ s.executables = ['export-github-issues']
19
+ s.extra_rdoc_files = ['LICENSE', 'README.md']
20
+ s.require_paths = ['lib']
21
+ end
@@ -0,0 +1,9 @@
1
+ # Copyright (c) 2015 Scott Williams
2
+
3
+ require 'English'
4
+ require 'shellwords'
5
+ require 'json'
6
+ require 'issue_exporter/outputter'
7
+ require 'issue_exporter/export'
8
+ require 'issue_exporter/error'
9
+ require 'issue_exporter/version'
@@ -0,0 +1,38 @@
1
+ # Copyright (c) 2015 Scott Williams
2
+
3
+ require 'optparse'
4
+ require 'issue_exporter'
5
+
6
+ module IssueExporting
7
+ module CLI
8
+
9
+ def run
10
+ begin
11
+ OptionParser.new do |opts|
12
+ define_options opts
13
+ opts.on '-h', '--help' do
14
+ puts usage
15
+ exit
16
+ end
17
+
18
+ opts.on '--version' do
19
+ puts about
20
+ exit
21
+ end
22
+
23
+ end.parse!
24
+ rescue OptionParser::ParseError => e
25
+ raise UsageError, e
26
+ end
27
+
28
+ fail UsageError, 'missing argument' if ARGV.empty?
29
+ fail UsageError, 'incorrect number of arguments' if ARGV.count != 3
30
+ ARGV.each_with_index { |arg, index| process_input arg, index }
31
+ perform_action()
32
+
33
+ rescue UsageError => e
34
+ puts "#{$PROGRAM_NAME}: #{e}\nTry `#{$PROGRAM_NAME} --help` for more information."
35
+ exit false
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,6 @@
1
+ # Copyright (c) 2015 Scott Williams
2
+
3
+ module IssueExporting
4
+ class UsageError < RuntimeError
5
+ end
6
+ end
@@ -0,0 +1,55 @@
1
+ # Copyright (c) 2015 Scott Williams
2
+
3
+ require 'net/http'
4
+ require 'json'
5
+
6
+ module IssueExporting
7
+ class Exporter
8
+
9
+ attr_accessor :outputter
10
+
11
+ def initialize(owner, repo, token = nil, options = {})
12
+ @owner = owner
13
+ @repo = repo
14
+ @token = token
15
+ @outputter = FileOutputter.new options
16
+ end
17
+
18
+ def export
19
+ url = URI.parse make_url
20
+ response = Net::HTTP::get url
21
+ if err = error_message(response)
22
+ handle_error err
23
+ else
24
+ outputter.write response
25
+ end
26
+ end
27
+
28
+ private
29
+ def error_message(response_text)
30
+ response_object = JSON.parse response_text
31
+ if response_object.is_a? Hash
32
+ response_object["message"]
33
+ end
34
+ end
35
+
36
+ def handle_error(error_message)
37
+ abort "ERROR: #{error_message}"
38
+ end
39
+
40
+ def make_url
41
+ url_format = @token ? url_with_token : url_without_token
42
+ url_format % [@owner, @repo, @token]
43
+ end
44
+
45
+ def url_with_token
46
+ "#{url_without_token}?access_token=%s"
47
+ end
48
+
49
+ def url_without_token
50
+ "https://api.github.com/repos/%s/%s/issues"
51
+ end
52
+
53
+ end
54
+ end
55
+
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2015 Scott Williams
2
+
3
+ module IssueExporting
4
+ class FileOutputter
5
+ def initialize(options = {})
6
+ @options = options
7
+ end
8
+
9
+ def write(response_text)
10
+ path = @options[:path] || default_path
11
+ if @options[:multiple_files]
12
+ write_multi_file path, response_text
13
+ else
14
+ write_single_file path, response_text
15
+ end
16
+ end
17
+
18
+ private
19
+ def default_path
20
+ Dir.pwd
21
+ end
22
+
23
+ def default_filename
24
+ "issues.json"
25
+ end
26
+
27
+ def write_single_file(dir, response_text)
28
+ path = "#{dir}/#{default_filename}"
29
+ File.open(path, 'w') { |f| f.write response_text }
30
+ end
31
+
32
+ def write_multi_file(dir, response_text)
33
+ array_of_issues = JSON.parse response_text
34
+ array_of_issues.each do |issue|
35
+ issue_number = issue["number"]
36
+ filename = "#{dir}/issue-#{issue_number}.json"
37
+ File.open(filename, 'w') { |f| f.write issue.to_json }
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ # Copyright (c) 2015 Scott Williams
2
+
3
+ module IssueExporting
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github_issue_exporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Scott Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |2
14
+ Download Issues from a GitHub repository.
15
+ email: scott@swilliams.me
16
+ executables:
17
+ - export-github-issues
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - LICENSE
21
+ - README.md
22
+ files:
23
+ - LICENSE
24
+ - README.md
25
+ - bin/export-github-issues
26
+ - github_issue_exporter.gemspec
27
+ - lib/issue_exporter.rb
28
+ - lib/issue_exporter/cli.rb
29
+ - lib/issue_exporter/error.rb
30
+ - lib/issue_exporter/export.rb
31
+ - lib/issue_exporter/outputter.rb
32
+ - lib/issue_exporter/version.rb
33
+ homepage: https://github.com/Tallwave/github_issue_exporter
34
+ licenses:
35
+ - MIT
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '2.0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 2.2.2
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Tools to export GitHub Issues
57
+ test_files: []