spaarti 0.0.6 → 0.1.0

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
  SHA1:
3
- metadata.gz: e9a57c801b96b3809d34d8e9fd904b81980dfee4
4
- data.tar.gz: dae03872a828d1fc299e5e72a98cf1a29b828ec8
3
+ metadata.gz: c42ba062b7a494cebed060c05573e29456f03fdc
4
+ data.tar.gz: 7f0ea344fc7cf4eccf66ab0e9ca0d6c10d97739b
5
5
  SHA512:
6
- metadata.gz: bccf34e30b3b3132042040c97f59cec8c1cbbddb214620b26baf419e43cc904ca906ea249fee83f26eaf43c5f5dfca035dbd787557d52077b41d640cfe493b4a
7
- data.tar.gz: 407d88057978eb2f57e007a605fb6253775612e69fefeaa841d5fbe275423b81e33d4cd14815ae3f985685c89886f5725c4638aa2483f6597a9ef71667d6ecd9
6
+ metadata.gz: 8b07d2daf7693308084d93e72752cdb716d1a68a7fa41a72674ab6f09bfd19c96d2d53ce2e2459ab307ed3d1acc7153e64ce91f3884ca251530d9840d6ca0c1a
7
+ data.tar.gz: 827d5277721187b041c163691026c4bf3749eb923211434913856664c8fcc479d9a7da73f500e305d30f3442ce3441dfc39b1aac219ac300dc3e7b7c240a3e94
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ coverage/
3
3
  .coveralls.yml
4
4
  .bundle
5
5
  Gemfile.lock
6
+ tmp
data/README.md CHANGED
@@ -12,6 +12,27 @@ Tool to maintain local clones of repos you have access to on GitHub
12
12
 
13
13
  ## Usage
14
14
 
15
+ To clone all your repos to the current directory: `spaarti`
16
+
17
+ Adding `-p` will remove orphaned repos (repos on disk that don't exist on GitHub, or that you no longer have access to).
18
+
19
+ Adding `-q` will silence output except errors.
20
+
21
+ You can override the defaults by defining a config file in YAML:
22
+
23
+ ```
24
+ base_path: Defaults to './', this is the root that repos will be cloned to
25
+ auth_file: Passed to OctoAuth for storing your GitHub token, the default will use ~/.octoauth.yml
26
+ exclude: Hash where keys are attributes of a repo (https://developer.github.com/v3/repos/#get) and values are array of regex pattern strings, with any repo whose attribute matches any pattern not being pulled
27
+ format: Format string used to determine path. Defaults to "%{full_name}", so "akerl/blog" is cloned at "akerl/blog". Available keys: https://developer.github.com/v3/repos/#get
28
+ git_config: Hash of key/value pairs, will be set in .git/config for cloned repos. Useful for setting things like user.name/email
29
+ quiet: Boolean, controls verbosity of status output
30
+ purge: Boolean, true will remove repos that are on-disk but not accessible by you on GitHub
31
+ url_type: Used to determine how to clone, one of: html, clone, git, ssh, svn. Defaults to 'ssh'
32
+ ```
33
+
34
+ The default config path is `~/.spaarti.yml`, but you can provide an alternate path with `./spaarti -c /path/to/config`
35
+
15
36
  ## Installation
16
37
 
17
38
  gem install spaarti
data/bin/spaarti CHANGED
File without changes
data/lib/spaarti/repo.rb CHANGED
@@ -39,12 +39,16 @@ module Spaarti
39
39
  err(error_msg) unless res
40
40
  end
41
41
 
42
+ def url
43
+ @url ||= @data["#{@options[:url_type]}_url".to_sym]
44
+ end
45
+
42
46
  def clone
43
47
  return log("#{@data[:full_name]} already cloned") if Dir.exist? @path
44
- log "Cloning #{@data[:ssh_url]} to #{@path}"
48
+ log "Cloning #{url} to #{@path}"
45
49
  run(
46
- "git clone '#{@data[:ssh_url]}' '#{@path}' &>/dev/null",
47
- "Failed to clone #{@data[:ssh_url]}"
50
+ "git clone '#{url}' '#{@path}' &>/dev/null",
51
+ "Failed to clone #{url}"
48
52
  )
49
53
  end
50
54
 
data/lib/spaarti/site.rb CHANGED
@@ -13,9 +13,10 @@ module Spaarti
13
13
  config_file: File.expand_path('~/.spaarti.yml'),
14
14
  exclude: [],
15
15
  format: '%{full_name}',
16
- git_config: [],
16
+ git_config: {},
17
17
  quiet: false,
18
- purge: false
18
+ purge: false,
19
+ url_type: 'ssh'
19
20
  }
20
21
 
21
22
  ##
@@ -24,6 +25,7 @@ module Spaarti
24
25
  def initialize(params = {})
25
26
  @options = DEFAULT_OPTIONS.dup.merge params
26
27
  load_config(params.include? :config_file)
28
+ auth
27
29
  end
28
30
 
29
31
  def sync!
@@ -71,13 +73,15 @@ module Spaarti
71
73
 
72
74
  def repos
73
75
  @repos ||= client.repos.map do |data|
74
- next if excluded(data.name) || excluded(data.full_name)
76
+ next if excluded(data)
75
77
  Repo.new data.to_h, client, @options
76
- end
78
+ end.compact
77
79
  end
78
80
 
79
- def excluded(string)
80
- @options[:exclude].any? { |x| string.match(x) }
81
+ def excluded(data)
82
+ @options[:exclude].any? do |key, patterns|
83
+ patterns.any? { |pattern| data[key].match pattern }
84
+ end
81
85
  end
82
86
  end
83
87
  end
@@ -1,5 +1,5 @@
1
1
  ##
2
2
  # Set the version (needed for Mercenary -v)
3
3
  module Spaarti
4
- VERSION = '0.0.6'
4
+ VERSION = '0.1.0'
5
5
  end
data/spaarti.gemspec CHANGED
@@ -17,14 +17,16 @@ Gem::Specification.new do |s|
17
17
  s.test_files = `git ls-files spec/*`.split
18
18
  s.executables = ['spaarti']
19
19
 
20
- s.add_dependency 'octokit', '~> 3.7.0'
21
- s.add_dependency 'octoauth', '~> 1.0.0'
20
+ s.add_dependency 'octokit', '~> 3.8.0'
21
+ s.add_dependency 'octoauth', '~> 1.0.1'
22
22
  s.add_dependency 'mercenary', '~> 0.3.4'
23
23
  s.add_dependency 'cymbal', '~> 1.0.0'
24
24
 
25
25
  s.add_development_dependency 'rubocop', '~> 0.29.0'
26
26
  s.add_development_dependency 'rake', '~> 10.4.0'
27
- s.add_development_dependency 'coveralls', '~> 0.7.0'
27
+ s.add_development_dependency 'coveralls', '~> 0.8.0'
28
28
  s.add_development_dependency 'rspec', '~> 3.2.0'
29
29
  s.add_development_dependency 'fuubar', '~> 2.0.0'
30
+ s.add_development_dependency 'webmock', '~> 1.21.0'
31
+ s.add_development_dependency 'vcr', '~> 2.9.2'
30
32
  end
data/spec/bin_spec.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spaarti do
4
+ end
@@ -0,0 +1,2 @@
1
+ ---
2
+ spaarti: sekrit
@@ -0,0 +1,4 @@
1
+ base_path: tmp/base
2
+ quiet: true
3
+ auth_file: spec/examples/auth.yml
4
+ url_type: git
@@ -0,0 +1,72 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.github.com/user/repos?per_page=100
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/vnd.github.moondragon+json
12
+ User-Agent:
13
+ - Octokit Ruby Gem 3.8.0
14
+ Content-Type:
15
+ - application/json
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - GitHub.com
25
+ Date:
26
+ - Sun, 05 Apr 2015 14:56:23 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Status:
32
+ - 200 OK
33
+ X-Ratelimit-Limit:
34
+ - '5000'
35
+ X-Ratelimit-Remaining:
36
+ - '4998'
37
+ X-Ratelimit-Reset:
38
+ - '1428249267'
39
+ Cache-Control:
40
+ - private, max-age=60, s-maxage=60
41
+ X-Oauth-Scopes:
42
+ - repo
43
+ X-Accepted-Oauth-Scopes:
44
+ - ''
45
+ Vary:
46
+ - Accept, Authorization, Cookie, X-GitHub-OTP
47
+ - Accept-Encoding
48
+ X-Github-Media-Type:
49
+ - github.moondragon; format=json
50
+ X-Xss-Protection:
51
+ - 1; mode=block
52
+ X-Frame-Options:
53
+ - deny
54
+ Content-Security-Policy:
55
+ - default-src 'none'
56
+ Access-Control-Allow-Credentials:
57
+ - 'true'
58
+ Access-Control-Expose-Headers:
59
+ - ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
60
+ X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
61
+ Access-Control-Allow-Origin:
62
+ - "*"
63
+ Strict-Transport-Security:
64
+ - max-age=31536000; includeSubdomains; preload
65
+ X-Content-Type-Options:
66
+ - nosniff
67
+ body:
68
+ encoding: ASCII-8BIT
69
+ string: '[{"id":23901941,"name":"spaarti","full_name":"akerl/spaarti","owner":{"login":"akerl","id":491209,"avatar_url":"https://avatars.githubusercontent.com/u/491209?v=3","gravatar_id":"","url":"https://api.github.com/users/akerl","html_url":"https://github.com/akerl","followers_url":"https://api.github.com/users/akerl/followers","following_url":"https://api.github.com/users/akerl/following{/other_user}","gists_url":"https://api.github.com/users/akerl/gists{/gist_id}","starred_url":"https://api.github.com/users/akerl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akerl/subscriptions","organizations_url":"https://api.github.com/users/akerl/orgs","repos_url":"https://api.github.com/users/akerl/repos","events_url":"https://api.github.com/users/akerl/events{/privacy}","received_events_url":"https://api.github.com/users/akerl/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/akerl/spaarti","description":"Tool to maintain local clones of repos you have access to on GitHub","fork":false,"url":"https://api.github.com/repos/akerl/spaarti","forks_url":"https://api.github.com/repos/akerl/spaarti/forks","keys_url":"https://api.github.com/repos/akerl/spaarti/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akerl/spaarti/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akerl/spaarti/teams","hooks_url":"https://api.github.com/repos/akerl/spaarti/hooks","issue_events_url":"https://api.github.com/repos/akerl/spaarti/issues/events{/number}","events_url":"https://api.github.com/repos/akerl/spaarti/events","assignees_url":"https://api.github.com/repos/akerl/spaarti/assignees{/user}","branches_url":"https://api.github.com/repos/akerl/spaarti/branches{/branch}","tags_url":"https://api.github.com/repos/akerl/spaarti/tags","blobs_url":"https://api.github.com/repos/akerl/spaarti/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akerl/spaarti/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akerl/spaarti/git/refs{/sha}","trees_url":"https://api.github.com/repos/akerl/spaarti/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akerl/spaarti/statuses/{sha}","languages_url":"https://api.github.com/repos/akerl/spaarti/languages","stargazers_url":"https://api.github.com/repos/akerl/spaarti/stargazers","contributors_url":"https://api.github.com/repos/akerl/spaarti/contributors","subscribers_url":"https://api.github.com/repos/akerl/spaarti/subscribers","subscription_url":"https://api.github.com/repos/akerl/spaarti/subscription","commits_url":"https://api.github.com/repos/akerl/spaarti/commits{/sha}","git_commits_url":"https://api.github.com/repos/akerl/spaarti/git/commits{/sha}","comments_url":"https://api.github.com/repos/akerl/spaarti/comments{/number}","issue_comment_url":"https://api.github.com/repos/akerl/spaarti/issues/comments{/number}","contents_url":"https://api.github.com/repos/akerl/spaarti/contents/{+path}","compare_url":"https://api.github.com/repos/akerl/spaarti/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akerl/spaarti/merges","archive_url":"https://api.github.com/repos/akerl/spaarti/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akerl/spaarti/downloads","issues_url":"https://api.github.com/repos/akerl/spaarti/issues{/number}","pulls_url":"https://api.github.com/repos/akerl/spaarti/pulls{/number}","milestones_url":"https://api.github.com/repos/akerl/spaarti/milestones{/number}","notifications_url":"https://api.github.com/repos/akerl/spaarti/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akerl/spaarti/labels{/name}","releases_url":"https://api.github.com/repos/akerl/spaarti/releases{/id}","created_at":"2014-09-11T03:05:28Z","updated_at":"2015-04-05T14:20:01Z","pushed_at":"2015-04-05T14:20:00Z","git_url":"git://github.com/akerl/spaarti.git","ssh_url":"git@github.com:akerl/spaarti.git","clone_url":"https://github.com/akerl/spaarti.git","svn_url":"https://github.com/akerl/spaarti","homepage":"","size":364,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master","master_branch":"master","permissions":{"admin":true,"push":true,"pull":true}}]'
70
+ http_version:
71
+ recorded_at: Sun, 05 Apr 2015 14:56:23 GMT
72
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spaarti do
4
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+
4
+ describe Spaarti do
5
+ describe 'Site' do
6
+ let(:path) { 'tmp/base' }
7
+ let(:config) { 'spec/examples/config.yml' }
8
+ let(:subject) { Spaarti::Site.new config_file: config }
9
+
10
+ before(:each) do
11
+ FileUtils.rm_rf path
12
+ FileUtils.mkdir_p path
13
+ end
14
+
15
+ describe '#sync!' do
16
+ it 'clones repo' do
17
+ expect(File.exist? "#{path}/akerl/spaarti/.git").to be_falsey
18
+ VCR.use_cassette('repos') { subject.sync! }
19
+ expect(File.exist? "#{path}/akerl/spaarti/.git").to be_truthy
20
+ end
21
+
22
+ context 'with purge enabled' do
23
+ it 'purges repos that are orphaned' do
24
+ FileUtils.mkdir_p "#{path}/akerl/orphan/.git"
25
+ VCR.use_cassette('repos') do
26
+ Spaarti::Site.new(purge: true, config_file: config).sync!
27
+ end
28
+ expect(File.exist? "#{path}/akerl/orphan").to be_falsey
29
+ end
30
+ end
31
+ context 'with purge disabled' do
32
+ it 'does not purge repos that are orphaned' do
33
+ FileUtils.mkdir_p "#{path}/akerl/orphan/.git"
34
+ VCR.use_cassette('repos') do
35
+ Spaarti::Site.new(purge: false, config_file: config).sync!
36
+ end
37
+ expect(File.exist? "#{path}/akerl/orphan").to be_truthy
38
+ end
39
+ end
40
+
41
+ it 'supports excluding repos' do
42
+ VCR.use_cassette('repos') do
43
+ Spaarti::Site.new(
44
+ exclude: { full_name: ['[ab]a'] }, config_file: config
45
+ ).sync!
46
+ end
47
+ expect(File.exist? "#{path}/akerl/spaarti").to be_falsey
48
+ end
49
+ end
50
+
51
+ describe '#purge!' do
52
+ it 'purges repos that are orphaned' do
53
+ FileUtils.mkdir_p "#{path}/akerl/orphan/.git"
54
+ VCR.use_cassette('repos') do
55
+ Spaarti::Site.new(purge: true, config_file: config).sync!
56
+ end
57
+ expect(File.exist? "#{path}/akerl/orphan").to be_falsey
58
+ end
59
+ end
60
+ end
61
+ end
data/spec/spaarti_spec.rb CHANGED
@@ -1 +1,9 @@
1
1
  require 'spec_helper'
2
+
3
+ describe Spaarti do
4
+ describe '#new' do
5
+ it 'creates a Site object' do
6
+ expect(Spaarti.new).to be_an_instance_of Spaarti::Site
7
+ end
8
+ end
9
+ end
data/spec/spec_helper.rb CHANGED
@@ -8,3 +8,15 @@ end
8
8
 
9
9
  require 'rspec'
10
10
  require 'spaarti'
11
+
12
+ require 'vcr'
13
+ VCR.configure do |c|
14
+ c.cassette_library_dir = 'spec/fixtures/cassettes'
15
+ c.hook_into :webmock
16
+ c.before_record do |i|
17
+ i.request.headers.delete 'Authorization'
18
+ %w(Etag X-Github-Request-Id X-Served-By).each do |header|
19
+ i.response.headers.delete header
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spaarti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-20 00:00:00.000000000 Z
11
+ date: 2015-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.7.0
19
+ version: 3.8.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.7.0
26
+ version: 3.8.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: octoauth
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.0
33
+ version: 1.0.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.0.0
40
+ version: 1.0.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mercenary
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: 0.7.0
103
+ version: 0.8.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: 0.7.0
110
+ version: 0.8.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -136,6 +136,34 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: 2.0.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 1.21.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 1.21.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: vcr
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 2.9.2
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 2.9.2
139
167
  description: Maintain local clones of repos you have access to on GitHub
140
168
  email: me@lesaker.org
141
169
  executables:
@@ -157,6 +185,12 @@ files:
157
185
  - lib/spaarti/site.rb
158
186
  - lib/spaarti/version.rb
159
187
  - spaarti.gemspec
188
+ - spec/bin_spec.rb
189
+ - spec/examples/auth.yml
190
+ - spec/examples/config.yml
191
+ - spec/fixtures/cassettes/repos.yml
192
+ - spec/spaarti/repo_spec.rb
193
+ - spec/spaarti/site_spec.rb
160
194
  - spec/spaarti_spec.rb
161
195
  - spec/spec_helper.rb
162
196
  homepage: https://github.com/akerl/spaarti
@@ -184,5 +218,11 @@ signing_key:
184
218
  specification_version: 4
185
219
  summary: Helper for cloning GitHub repos
186
220
  test_files:
221
+ - spec/bin_spec.rb
222
+ - spec/examples/auth.yml
223
+ - spec/examples/config.yml
224
+ - spec/fixtures/cassettes/repos.yml
225
+ - spec/spaarti/repo_spec.rb
226
+ - spec/spaarti/site_spec.rb
187
227
  - spec/spaarti_spec.rb
188
228
  - spec/spec_helper.rb