github-tv 0.3

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: 394f431dfda18daf4d28a8029df24597a89ebc4d
4
+ data.tar.gz: 14805bcf47d60819849d5badf5636354983351db
5
+ SHA512:
6
+ metadata.gz: 0b258ca144cbe17b1e46fec1ee22fa7a2f64a9a71ca1c420b918f6be1ff3839c5bc4d1e5f6b7f298b0cdf2aceb850f50c385e8231914c2c705dcc50563104e7a
7
+ data.tar.gz: 038227509055ee627dc807d168f14ca7eb70103b4720d4e5f2c299ca3e3af6897cc0b04182810c83300cbdc90591d7eae783e123080ca1e284fcf58d32a13d1e
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .bundle/
2
+ Gemfile.lock
3
+ pkg/
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 evilmartians
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,28 @@
1
+ # Github-TV: Forks your colleagues' open-source repos to organization page
2
+
3
+ This is just a POC.
4
+
5
+ ## Usage
6
+
7
+ ```bash
8
+ gem install github-tv
9
+ github-tv *path/url for config*
10
+ ```
11
+
12
+ Config should be in format of
13
+
14
+ ```yaml
15
+ ---
16
+ organization: where_to_sync_repos
17
+ repos:
18
+ - user1/repo1
19
+ - user2/repo2
20
+ ```
21
+
22
+ ## Contributors
23
+
24
+ * @gazay, @brainopia
25
+
26
+ ## License
27
+
28
+ The MIT License
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/github-tv ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/github-tv'
4
+ require 'io/console'
5
+ require 'open-uri'
6
+
7
+ config_location = ARGV.shift or abort 'Missing path/url for config'
8
+ config = YAML.load open config_location
9
+
10
+ token = `git config github.tv`.chomp
11
+
12
+ if token.empty?
13
+ puts 'Please authenticate yourself to create a token for further usage.'
14
+
15
+ print 'Username: '
16
+ username = gets.chomp
17
+
18
+ print 'Password: '
19
+ password = STDIN.noecho(&:gets).chomp
20
+ puts
21
+
22
+ client = Octokit::Client.new \
23
+ login: username,
24
+ password: password
25
+
26
+ response = client.create_authorization \
27
+ scopes: ['public_repo'],
28
+ note: "github-tv #{Time.now}"
29
+
30
+ token = response.token
31
+ `git config --global github.tv #{token}`
32
+ end
33
+
34
+ config['token'] = token
35
+ GithubTV.new(config).run
data/github-tv.gemspec ADDED
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'github-tv'
3
+ gem.version = '0.3'
4
+ gem.license = 'MIT'
5
+ gem.authors = ['brainopia', 'gazay']
6
+ gem.email = 'brainopia@evilmartians.com'
7
+ gem.summary = 'Forks your colleagues open-source repos to organization page'
8
+ gem.homepage = 'https://github.com/evilmartians/github-tv'
9
+ gem.files = `git ls-files`.split($/)
10
+ gem.require_paths = %w(lib)
11
+ gem.executables = 'github-tv'
12
+
13
+ gem.add_dependency 'octokit'
14
+ end
15
+
data/lib/github-tv.rb ADDED
@@ -0,0 +1,74 @@
1
+ require 'yaml'
2
+ require 'octokit'
3
+
4
+ class GithubTV
5
+ attr_reader :token, :org, :repos
6
+
7
+ def initialize(config)
8
+ @token = config.fetch 'token'
9
+ @repos = config.fetch 'repos'
10
+ @org = config.fetch 'organization'
11
+ end
12
+
13
+ def run
14
+ repos.each do |repo|
15
+ Sync.new(client, org, repo).run
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def client
22
+ @client ||= Octokit::Client
23
+ .new(access_token: token)
24
+ .tap(&:user) # check auth
25
+
26
+ rescue Octokit::Unauthorized
27
+ raise "Your token (#{token.inspect}) is invalid"
28
+ end
29
+
30
+ class Sync
31
+ def initialize(client, target, source_repo)
32
+ @client = client
33
+ @target = target
34
+ @source, @project = source_repo.split('/')
35
+ end
36
+
37
+ def run
38
+ if @client.repository? target_repo
39
+ fast_forward
40
+ puts "#@project fast-forwarded"
41
+ else
42
+ @client.fork source_repo, organization: @target
43
+ puts "#@project forked"
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def fast_forward
50
+ system <<-SH
51
+ [ -d #@project.git ] || git clone --mirror #{source_url}
52
+ cd #@project.git
53
+ git fetch -p origin
54
+ git push --mirror #{target_url}
55
+ SH
56
+ end
57
+
58
+ def target_repo
59
+ "#@target/#@project"
60
+ end
61
+
62
+ def source_repo
63
+ "#@source/#@project"
64
+ end
65
+
66
+ def source_url
67
+ "https://github.com/#{source_repo}.git"
68
+ end
69
+
70
+ def target_url
71
+ "https://#{@client.access_token}@github.com/#{target_repo}.git"
72
+ end
73
+ end
74
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github-tv
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.3'
5
+ platform: ruby
6
+ authors:
7
+ - brainopia
8
+ - gazay
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-11-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: octokit
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ description:
29
+ email: brainopia@evilmartians.com
30
+ executables:
31
+ - github-tv
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - Gemfile
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - bin/github-tv
41
+ - github-tv.gemspec
42
+ - lib/github-tv.rb
43
+ homepage: https://github.com/evilmartians/github-tv
44
+ licenses:
45
+ - MIT
46
+ metadata: {}
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 2.4.1
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: Forks your colleagues open-source repos to organization page
67
+ test_files: []