repo_forker 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e3578efae8d2b15899494806244f4e05ab2f1f8e
4
+ data.tar.gz: 1131fd5c1593e95eda0b5b0d034dff3b6846c5af
5
+ SHA512:
6
+ metadata.gz: 5aa039118ecfc6cde636776d0d3abacf2173a9d437a9eacda7de36fc901e4ff9a7a40c51ed8717e555c731c0a8d8a44980a186fc1b280383a1e313fe150cd40b
7
+ data.tar.gz: b07db61b46f99c44d90f68a7c01d9e549f30cd167e5833d014a1df55c5a128b50a1ddd9e41ea4cedfe7408e027218160b664212d504480f2ec58ae7a399023da
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ cache: bundler
3
+ script: 'bundle exec rspec'
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.0
8
+ - ruby-head
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: ruby-head
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Torey Hickman
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,44 @@
1
+ # RepoForker
2
+
3
+ ![Travis CI Build Status](https://api.travis-ci.org/toreyhickman/repo-forker.svg?branch=master)
4
+
5
+ This gem is written to facilitate the forking of a list of GitHub repositories from one user or organization to another.
6
+
7
+
8
+ ## Installation
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'repo_forker'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install repo_forker
22
+
23
+
24
+ ## Usage
25
+ ```ruby
26
+ RepoForker.configure do |config|
27
+ config.api_key = "123456"
28
+ config.source = "some-organization"
29
+ config.destination = "another-organization"
30
+ end
31
+
32
+ repo_list = ["some-repo", "some-other-repo"]
33
+
34
+ RepoForker.fork(repo_list)
35
+ # => { :successful_requests => ["some-repo"], :failed_requests => ["some-other-repo"] }
36
+ ```
37
+
38
+ *Figure 1*. Example configuration and use of RepoForker.
39
+
40
+ In order for RepoForker to make requests to the GitHub API to fork repositories, it must be configured with a GitHub API key, source user/organization, and a destination user/organization. After configuration is complete, prepare a list of repository names and tell RepoForker to fork the repositories. (see Figure 1)
41
+
42
+
43
+ ## Contributing
44
+ If you'd like to help improve RepoForker by adding a new feature, please fork the repository and submit a pull request for your feature branch. Also, please report any bugs that you find.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,35 @@
1
+ require "net/http"
2
+
3
+ require "repo_forker/version"
4
+ require "repo_forker/configuration"
5
+ require "repo_forker/forking_uri"
6
+ require "repo_forker/client"
7
+ require "repo_forker/forking_request"
8
+
9
+ module RepoForker
10
+ extend Configuration
11
+
12
+ def self.client
13
+ @client ||= Client.new
14
+ end
15
+
16
+ def self.fork(repo_names = [])
17
+ repo_names.each_with_object(new_memo) do |repo_name, memo|
18
+ uri = ForkingURI.build(repo_name)
19
+ request_details = ForkingRequest.new(uri.request_uri)
20
+
21
+ response = client.request(request_details)
22
+ record(response, memo, repo_name)
23
+ end
24
+ end
25
+
26
+ private
27
+ def self.new_memo
28
+ { successful_requests: [], failed_requests: [] }
29
+ end
30
+
31
+ def self.record(response, memo, repo_name)
32
+ key = response.code == "202" ? :successful_requests : :failed_requests
33
+ memo[key] << repo_name
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ module RepoForker
2
+ class Client < Net::HTTP
3
+ def self.new(host = uri.host, port = uri.port)
4
+ super(host, port)
5
+ end
6
+
7
+ def initialize(host, port)
8
+ super
9
+ self.use_ssl = true
10
+ end
11
+
12
+ private
13
+ def self.uri
14
+ @uri ||= URI(RepoForker.endpoint)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ module RepoForker
2
+ module Configuration
3
+ def self.extended(base)
4
+ base.reset
5
+ end
6
+
7
+ VALID_CONNECTION_KEYS = [:endpoint, :user_agent]
8
+ VALID_OPTIONS_KEYS = [:api_key, :source, :destination]
9
+ VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
10
+
11
+ DEFAULT_ENDPOINT = "https://api.github.com"
12
+ DEFAULT_USER_AGENT = "RepoForker Ruby Gem #{RepoForker::VERSION}"
13
+
14
+ DEFAULT_API_KEY = nil
15
+ DEFAULT_SOURCE = nil
16
+ DEFAULT_DESTINATION = nil
17
+
18
+ attr_accessor *VALID_CONFIG_KEYS
19
+
20
+ def configure
21
+ yield self if block_given?
22
+ end
23
+
24
+ def reset
25
+ self.endpoint = DEFAULT_ENDPOINT
26
+ self.user_agent = DEFAULT_USER_AGENT
27
+ self.api_key = DEFAULT_API_KEY
28
+ self.source = DEFAULT_SOURCE
29
+ self.destination = DEFAULT_DESTINATION
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,18 @@
1
+ module RepoForker
2
+ class ForkingRequest < Net::HTTP::Post
3
+ def initialize(path)
4
+ super
5
+ assign_user_agent_header
6
+ assign_authorization_header
7
+ end
8
+
9
+ private
10
+ def assign_user_agent_header
11
+ self["user-agent"] = RepoForker.user_agent
12
+ end
13
+
14
+ def assign_authorization_header
15
+ self["authorization"] = "token #{RepoForker.api_key}"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ module RepoForker
2
+ class ForkingURI < URI::HTTPS
3
+ def self.build(repo_name)
4
+ super(build_params(repo_name))
5
+ end
6
+
7
+ private
8
+ def self.build_params(repo_name)
9
+ { :path => build_path(repo_name),
10
+ :host => build_host,
11
+ :query => build_query }
12
+ end
13
+
14
+ def self.build_path(repo_name)
15
+ "/repos/#{RepoForker.source}/#{repo_name}/forks"
16
+ end
17
+
18
+ def self.build_host
19
+ RepoForker.endpoint.sub(/\w+:\/\//, "")
20
+ end
21
+
22
+ def self.build_query
23
+ "organization=#{RepoForker.destination}"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module RepoForker
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'repo_forker/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "repo_forker"
8
+ spec.version = RepoForker::VERSION
9
+ spec.authors = ["Torey Hickman"]
10
+ spec.email = ["torey@toreyhickman.com"]
11
+ spec.summary = "Fork a list of repositories."
12
+ spec.description = "This gem facilitates forking multiple repositories from one organization/user to another"
13
+ spec.homepage = "https://github.com/toreyhickman/repo-forker"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2"
24
+ end
@@ -0,0 +1,23 @@
1
+ require 'repo_forker'
2
+
3
+ describe RepoForker::Client do
4
+ describe ".new" do
5
+ let(:client) { RepoForker::Client.new }
6
+
7
+ it "is a kind of Ruby Net::HTTP object" do
8
+ expect(client).to be_a_kind_of Net::HTTP
9
+ end
10
+
11
+ it "has the host of the GitHub api" do
12
+ expect(client.address).to eq "api.github.com"
13
+ end
14
+
15
+ it "uses 443 as its port" do
16
+ expect(client.port).to eq 443
17
+ end
18
+
19
+ it "uses ssl" do
20
+ expect(client.use_ssl?).to be true
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ require "repo_forker"
2
+
3
+ describe RepoForker::ForkingRequest do
4
+
5
+ let(:request_path) { "/path_to_repo?with=options" }
6
+ let(:request) { RepoForker::ForkingRequest.new(request_path) }
7
+
8
+ let(:fake_api_key) { "123456" }
9
+ let(:fake_user_agent) { "my app" }
10
+
11
+ before(:each) do
12
+ RepoForker.configure do |config|
13
+ config.api_key = fake_api_key
14
+ config.user_agent = fake_user_agent
15
+ end
16
+ end
17
+
18
+ after(:each) do
19
+ RepoForker.reset
20
+ end
21
+
22
+ describe ".new" do
23
+ it "is a kind of Net::HTTP::Post object" do
24
+ expect(request).to be_a_kind_of Net::HTTP::Post
25
+ end
26
+
27
+ it "assigns the user-agent header" do
28
+ expect(request["user-agent"]).to eq RepoForker.user_agent
29
+ end
30
+
31
+ it "assigns the authorization header" do
32
+ expect(request["authorization"]).to eq "token #{RepoForker.api_key}"
33
+ end
34
+
35
+ it "has a path" do
36
+ expect(request.path).to eq request_path
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,48 @@
1
+ require 'repo_forker'
2
+
3
+ describe RepoForker::ForkingURI do
4
+
5
+ let(:fake_api_key) { "123456" }
6
+ let(:fake_source) { "good-coder" }
7
+ let(:fake_destination) { "helper" }
8
+ let(:fake_repo_to_fork) { "cool-library" }
9
+
10
+ before(:each) do
11
+ RepoForker.configure do |config|
12
+ config.api_key = fake_api_key
13
+ config.source = fake_source
14
+ config.destination = fake_destination
15
+ end
16
+ end
17
+
18
+ after(:each) do
19
+ RepoForker.reset
20
+ end
21
+
22
+ describe ".build" do
23
+ it "is a kind of Ruby URI::HTTPS object" do
24
+ expect(RepoForker::ForkingURI.build fake_repo_to_fork).to be_a_kind_of URI::HTTPS
25
+ end
26
+
27
+ it "has a path to request forking the repository" do
28
+ expected_path = "/repos/#{fake_source}/#{fake_repo_to_fork}/forks"
29
+ built_uri = RepoForker::ForkingURI.build(fake_repo_to_fork)
30
+
31
+ expect(built_uri.path).to eq expected_path
32
+ end
33
+
34
+ it "has a query string to specify the destination organization" do
35
+ expected_query_string = "organization=#{fake_destination}"
36
+ built_uri = RepoForker::ForkingURI.build(fake_repo_to_fork)
37
+
38
+ expect(built_uri.query).to eq expected_query_string
39
+ end
40
+
41
+ it "has a properly formatted request uri" do
42
+ expected_request_uri = "/repos/#{fake_source}/#{fake_repo_to_fork}/forks?organization=#{fake_destination}"
43
+ built_uri = RepoForker::ForkingURI.build(fake_repo_to_fork)
44
+
45
+ expect(built_uri.request_uri).to eq expected_request_uri
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,96 @@
1
+ require 'repo_forker'
2
+
3
+ describe RepoForker do
4
+ it "has a version" do
5
+ expect(RepoForker::VERSION).to_not be_nil
6
+ end
7
+
8
+ describe "default values" do
9
+ RepoForker::Configuration::VALID_CONFIG_KEYS.each do |key|
10
+ it "has a default #{key}" do
11
+ constant_name = "DEFAULT_#{key.upcase}"
12
+ expected_default_value = RepoForker::Configuration.const_get(constant_name)
13
+ expect(RepoForker.send(key)).to eq expected_default_value
14
+ end
15
+ end
16
+ end
17
+
18
+ describe ".configure" do
19
+ after(:each) do
20
+ RepoForker.reset
21
+ end
22
+
23
+ RepoForker::Configuration::VALID_CONFIG_KEYS.each do |key|
24
+ it "sets the #{key}" do
25
+ RepoForker.configure do |config|
26
+ config.send("#{key}=", key)
27
+ end
28
+
29
+ expect(RepoForker.send(key)).to eq key
30
+ end
31
+ end
32
+ end
33
+
34
+ describe ".client" do
35
+ it "returns a Client object" do
36
+ expect(RepoForker.client).to be_an_instance_of RepoForker::Client
37
+ end
38
+ end
39
+
40
+ describe ".fork" do
41
+ let(:client) { RepoForker.client }
42
+
43
+ let(:repo_1) { "some_repo" }
44
+ let(:repo_2) { "some_other_repo" }
45
+ let(:list) { [repo_1, repo_2] }
46
+
47
+ let(:mock_api_key) { "123456" }
48
+ let(:mock_source) { "good_coder" }
49
+ let(:mock_destination) { "helper" }
50
+
51
+ before(:each) do
52
+ RepoForker.configure do |config|
53
+ config.api_key = mock_api_key
54
+ config.source = mock_source
55
+ config.destination = mock_destination
56
+ end
57
+ end
58
+
59
+ after(:each) do
60
+ RepoForker.reset
61
+ end
62
+
63
+ it "makes a request to fork each repo in the list" do
64
+ allow(RepoForker).to receive(:record)
65
+ allow(client).to receive(:request)
66
+
67
+ list.each do |repo_name|
68
+ fake_uri = double("uri", request_uri: "/path/to/#{repo_name}")
69
+ allow(RepoForker::ForkingURI).to receive(:build).with(repo_name).and_return(fake_uri)
70
+
71
+ fake_request = double("request")
72
+ allow(RepoForker::ForkingRequest).to receive(:new).with(fake_uri.request_uri).and_return(fake_request)
73
+
74
+ expect(client).to receive(:request).with(fake_request)
75
+ end
76
+
77
+ RepoForker.fork list
78
+ end
79
+
80
+ it "returns a record of successful and failed requests" do
81
+ list.each do |repo_name|
82
+ fake_uri = double("uri", request_uri: "/path/to/#{repo_name}")
83
+ allow(RepoForker::ForkingURI).to receive(:build).with(repo_name).and_return(fake_uri)
84
+
85
+ fake_request = double("request")
86
+ allow(RepoForker::ForkingRequest).to receive(:new).with(fake_uri.request_uri).and_return(fake_request)
87
+ end
88
+
89
+ successful_response = double("success", code: "202")
90
+ failed_response = double("fail", code: "404")
91
+ allow(client).to receive(:request).and_return(successful_response, failed_response)
92
+
93
+ expect(RepoForker.fork list).to eq({ successful_requests: [repo_1], failed_requests: [repo_2] })
94
+ end
95
+ end
96
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: repo_forker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Torey Hickman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ description: This gem facilitates forking multiple repositories from one organization/user
56
+ to another
57
+ email:
58
+ - torey@toreyhickman.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .travis.yml
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/repo_forker.rb
70
+ - lib/repo_forker/client.rb
71
+ - lib/repo_forker/configuration.rb
72
+ - lib/repo_forker/forking_request.rb
73
+ - lib/repo_forker/forking_uri.rb
74
+ - lib/repo_forker/version.rb
75
+ - repo_forker.gemspec
76
+ - spec/client_spec.rb
77
+ - spec/forking_request_spec.rb
78
+ - spec/forking_uri_spec.rb
79
+ - spec/repo_forker_spec.rb
80
+ homepage: https://github.com/toreyhickman/repo-forker
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.4.3
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Fork a list of repositories.
104
+ test_files:
105
+ - spec/client_spec.rb
106
+ - spec/forking_request_spec.rb
107
+ - spec/forking_uri_spec.rb
108
+ - spec/repo_forker_spec.rb