github_records_archiver 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04613c74d230d25723b56ff88a3e34c840d8a8ae56bc7543a386f0bb91fc7ca4
4
- data.tar.gz: 0eff9d4f24718e4db5107ccfb6ffd8c45f5783f31de16b51edea0324cda20803
3
+ metadata.gz: eb654d261b3fe129aad0e82db6b04026abae2b8b98abec9a15547ee04d42781c
4
+ data.tar.gz: 801eec766b98062c6484841f1c3089cb07bba749216caeddc4ec7c34acb03d7f
5
5
  SHA512:
6
- metadata.gz: 0704f880ce05d5f0990f36a02bd7962452e072255d88f53d00f5878b035908a7171cf155bdb4284b6cdc8ca5d94ff89f8fbd98fd55bbe6fffb9f6b6226ff860a
7
- data.tar.gz: 328a9351d1161903ffe67f0b3bbcacb8f1830baf87bd72a157c5306d7ab8af75c84d7df49d689d34c9745fe58c843b479573ba038ab726cd9febd4d89d824867
6
+ metadata.gz: 7dfa550f2a3a483cf3713324c228ecbe9b8253d9c1841bb7c1a88cfe8a5b5ee26f45ce5679f23f2d75a7d5802b588e7899f9cde48765fda9e60645cafa7d992a
7
+ data.tar.gz: 23d37b11234cfc06eec4ab49c962c3d374b0dcd2d893a00863e0643395bbd7950a72948143618170a70dcac826846e629ee7adf95e70de2b64698e7e915437e3
@@ -2,8 +2,7 @@ AllCops:
2
2
  Exclude:
3
3
  - archive/**/*
4
4
  - vendor/**/*
5
- - bin/github-records-archiver
6
-
5
+
7
6
  Style/Documentation:
8
7
  Enabled: false
9
8
 
@@ -11,10 +10,25 @@ Metrics/BlockLength:
11
10
  Exclude:
12
11
  - spec/**/*
13
12
  - '*.gemspec'
13
+ - lib/github_records_archiver/cli.rb
14
14
 
15
15
  Metrics/LineLength:
16
16
  Exclude:
17
17
  - spec/**/*
18
+ - lib/github_records_archiver/cli.rb
19
+
20
+ Metrics/MethodLength:
21
+ Exclude:
22
+ - lib/github_records_archiver/cli.rb
23
+ - spec/spec_helper.rb
24
+
25
+ Metrics/AbcSize:
26
+ Exclude:
27
+ - lib/github_records_archiver/cli.rb
28
+
29
+ Metrics/CyclomaticComplexity:
30
+ Exclude:
31
+ - spec/spec_helper.rb
18
32
 
19
33
  Layout/IndentHeredoc:
20
34
  Enabled: false
@@ -1,77 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'thor'
4
- require 'parallel'
5
3
  require_relative '../lib/github_records_archiver'
6
4
 
7
- class GitHubRecordsArchiverCLI < Thor
8
- package_name 'GitHub Records Archiver'
9
- class_option :dest_dir, type: :string, required: false,
10
- desc: "The destination directory for the archive", default: GitHubRecordsArchiver.dest_dir
11
- class_option :token, type: :string, required: false, desc: "A GitHub personal access token with repo scope"
12
- class_option :verbose, type: :boolean, desc: 'Display verbose output while archiving', default: false
13
-
14
- desc 'version', 'Outputs the GitHubRecordsArchiver version'
15
- def version
16
- say "GitHub Records Archiver v#{GitHubRecordsArchiver::VERSION}"
17
- end
18
-
19
- desc "delete [ORGANIZATION]", "Deletes all archives, or the archive for an organization"
20
- def delete(org_name = nil)
21
- path = GitHubRecordsArchiver.dest_dir
22
- path = File.join path, org_name if org_name
23
- FileUtils.rm_rf(path) if yes? "Are you sure? Remove #{path}?"
24
- end
25
-
26
- desc 'archive ORGANIZATION', 'Create or update archive for the given organization'
27
- def archive(org_name)
28
- start_time # Memoize start time for comparison
29
- @org_name = org_name
30
-
31
- GitHubRecordsArchiver.shell = shell
32
- %i(token dest_dir verbose).each do |option|
33
- next unless options[option]
34
- GitHubRecordsArchiver.public_send "#{option}=".to_sym, options[option]
35
- end
36
-
37
- say "Starting archive for @#{org.name} in #{org.archive_dir}"
38
- shell.indent(2) do
39
- archive_teams
40
- archive_repos
41
- end
42
- say "Done in #{Time.now - start_time} seconds.", :green
43
- end
44
-
45
- private
46
-
47
- def start_time
48
- @start_time ||= Time.now
49
- end
50
-
51
- def organization
52
- @organization ||= GitHubRecordsArchiver::Organization.new @org_name
53
- end
54
- alias_method :org, :organization
55
-
56
- def archive_teams
57
- say_status "Teams found:", org.teams.count, :white
58
- Parallel.each(org.teams, progress: 'Archiving teams', &:archive)
59
- end
60
-
61
- def archive_repos
62
- say_status "Repositories found:", org.repos.count, :white
63
-
64
- Parallel.each(org.repos, progress: 'Archiving repos') do |repo|
65
- begin
66
- repo.clone
67
- repo.wiki.clone if repo.has_wiki?
68
- Parallel.each(repo.issues, &:archive)
69
- rescue GitHubRecordsArchiver::GitError => e
70
- say "Failed to archive #{repo.name}", :red
71
- say e.message, :red
72
- end
73
- end
74
- end
75
- end
76
-
77
- GitHubRecordsArchiverCLI.start(ARGV)
5
+ GitHubRecordsArchiver::CLI.start(ARGV)
@@ -7,6 +7,7 @@ require 'fileutils'
7
7
  require 'open3'
8
8
  require 'thor'
9
9
  require 'octokit'
10
+ require 'parallel'
10
11
  require 'dotenv/load'
11
12
 
12
13
  Octokit.auto_paginate = true
@@ -14,6 +15,7 @@ Octokit.auto_paginate = true
14
15
  module GitHubRecordsArchiver
15
16
  autoload :DataHelper, 'github_records_archiver/data_helper'
16
17
  autoload :Comment, 'github_records_archiver/comment'
18
+ autoload :CLI, 'github_records_archiver/cli'
17
19
  autoload :GitRepository, 'github_records_archiver/git_repository'
18
20
  autoload :Issue, 'github_records_archiver/issue'
19
21
  autoload :Organization, 'github_records_archiver/organization'
@@ -24,7 +26,7 @@ module GitHubRecordsArchiver
24
26
  autoload :Wiki, 'github_records_archiver/wiki'
25
27
 
26
28
  class << self
27
- attr_writer :token, :dest_dir, :verbose, :shell
29
+ attr_writer :token, :dest_dir, :verbose, :shell, :client
28
30
 
29
31
  def token
30
32
  @token ||= ENV['GITHUB_TOKEN']
@@ -0,0 +1,72 @@
1
+ module GitHubRecordsArchiver
2
+ class CLI < Thor
3
+ package_name 'GitHub Records Archiver'
4
+ class_option :dest_dir, type: :string, required: false,
5
+ desc: 'The destination directory for the archive', default: GitHubRecordsArchiver.dest_dir
6
+ class_option :token, type: :string, required: false, desc: 'A GitHub personal access token with repo scope'
7
+ class_option :verbose, type: :boolean, desc: 'Display verbose output while archiving', default: false
8
+
9
+ desc 'version', 'Outputs the GitHubRecordsArchiver version'
10
+ def version
11
+ say "GitHub Records Archiver v#{GitHubRecordsArchiver::VERSION}"
12
+ end
13
+
14
+ desc 'delete [ORGANIZATION]', 'Deletes all archives, or the archive for an organization'
15
+ option :force, type: :boolean, desc: 'Delete without prompting', default: false
16
+ def delete(org_name = nil)
17
+ path = GitHubRecordsArchiver.dest_dir
18
+ path = File.join path, org_name if org_name
19
+ FileUtils.rm_rf(path) if options[:force] || yes?("Are you sure? Remove #{path}?")
20
+ end
21
+
22
+ desc 'archive ORGANIZATION', 'Create or update archive for the given organization'
23
+ def archive(org_name)
24
+ start_time # Memoize start time for comparison
25
+ @org_name = org_name
26
+
27
+ GitHubRecordsArchiver.shell = shell
28
+ %i[token dest_dir verbose].each do |option|
29
+ next unless options[option]
30
+ GitHubRecordsArchiver.public_send "#{option}=".to_sym, options[option]
31
+ end
32
+
33
+ say "Starting archive for @#{org.name} in #{org.archive_dir}"
34
+ shell.indent(2) do
35
+ archive_teams
36
+ archive_repos
37
+ end
38
+ say "Done in #{Time.now - start_time} seconds.", :green
39
+ end
40
+
41
+ private
42
+
43
+ def start_time
44
+ @start_time ||= Time.now
45
+ end
46
+
47
+ def organization
48
+ @organization ||= GitHubRecordsArchiver::Organization.new @org_name
49
+ end
50
+ alias org organization
51
+
52
+ def archive_teams
53
+ say_status 'Teams found:', org.teams.count, :white
54
+ Parallel.each(org.teams, progress: 'Archiving teams', &:archive)
55
+ end
56
+
57
+ def archive_repos
58
+ say_status 'Repositories found:', org.repos.count, :white
59
+
60
+ Parallel.each(org.repos, progress: 'Archiving repos') do |repo|
61
+ begin
62
+ repo.clone
63
+ repo.wiki.clone if repo.has_wiki?
64
+ Parallel.each(repo.issues, &:archive)
65
+ rescue GitHubRecordsArchiver::GitError => e
66
+ say "Failed to archive #{repo.name}", :red
67
+ say e.message, :red
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -1,3 +1,3 @@
1
1
  module GitHubRecordsArchiver
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_records_archiver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Balter
@@ -205,6 +205,7 @@ files:
205
205
  - docs/CONTRIBUTING.md
206
206
  - github_records_archiver.gemspec
207
207
  - lib/github_records_archiver.rb
208
+ - lib/github_records_archiver/cli.rb
208
209
  - lib/github_records_archiver/comment.rb
209
210
  - lib/github_records_archiver/data_helper.rb
210
211
  - lib/github_records_archiver/git_repository.rb