tworingtools 1.0.1 → 1.1.0

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.
Files changed (4) hide show
  1. checksums.yaml +5 -5
  2. data/bin/sync-forks +79 -0
  3. data/lib/echoexec.rb +4 -0
  4. metadata +38 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 34ae3a3f775e1353d0be46b351137618bb67abc7
4
- data.tar.gz: 2deab3f3545851f87fd1120cd97f2b136a97fdf5
2
+ SHA256:
3
+ metadata.gz: 4d7d0be0130a2ec64a0612715df8d264d5ad8b79df6edc20ddab819ba11e3a19
4
+ data.tar.gz: 7603723b72cb09ef67085a89802fea08155847aa5981433a21a099732a5ba3f7
5
5
  SHA512:
6
- metadata.gz: 866ef9350b32926b914a8e944a6679f90026934406c06ace796660c310164f967d029381ac05b127210e20ecce407d4199c715fe845bf35fb1615a936965e850
7
- data.tar.gz: 896e7fb5fd3aa610ff1eb2e7c495555699ec97a3f796a39384605d53db997181058013e30d824660b8f5520ea943ed2d3a27fa5c3030869b039413a1a8d9c312
6
+ metadata.gz: 3db60b7f6bb28097e3c1dc1b53c40d57300fa85b3dca16486bfdb9793941afa9a87a44faba376e460aad82b829b8c67506b312fd59c6fce114175524c7e937d7
7
+ data.tar.gz: d080ca7a67ad1298eeed0c95cad45833b400ad12ce29dcccd598e241a17496fbf47e71b51599dba72358c050c41fb7e1e937414ee00aa67c74054b1924f71f9b
data/bin/sync-forks ADDED
@@ -0,0 +1,79 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'github_api'
4
+ require 'json'
5
+ require 'optparse'
6
+ require_relative '../lib/echoexec'
7
+
8
+ options = {}
9
+ parser = OptionParser.new do |opts|
10
+ opts.banner = <<~BANNER
11
+
12
+ Usage: sync-forks [options] <directory>
13
+
14
+ <directory> is the path containing the directories holding your forks, and/or
15
+ to where those you don't yet have should be cloned.
16
+
17
+ Examples:
18
+
19
+ sync-forks -u/--username <user> -p/--password <pass> [-o/--one-time-pw <otp>] .
20
+ sync-forks -u/--username <user> -t/--token <token> .
21
+
22
+ If you already have a Personal Access Token, provide it in the second form.
23
+ Otherwise, use the first form, which will register a new token for you named
24
+ “sync-forks”. Then use that to invoke the program again. This is because
25
+ requests using basic authentication (user/pass) are too rate limited.
26
+
27
+ Options:
28
+
29
+ BANNER
30
+
31
+ opts.on('-uUSERNAME', '--username=USERNAME', 'GitHub username. Required for all invocations.') do |user| options[:username] = user end
32
+ opts.on('-tTOKEN', '--token=TOKEN', 'GitHub personal access token. The primary way to use this program.') do |t| options[:token] = t end
33
+ opts.on('-pPASSWORD', '--password=PASSWORD', 'GitHub password.') do |pass| options[:password] = pass end
34
+ opts.on('-oOTP', '--one-time-pw=OTP', 'GitHub 2FA token, if you have it enabled.') do |otp| options[:otp] = otp end
35
+ end
36
+ parser.parse!
37
+
38
+ github = nil
39
+ if nil != options[:token] && nil != options[:username] then
40
+ github = Github.new oauth_token: options[:token]
41
+ elsif nil != options[:username] && nil != options[:password]
42
+ github = Github.new do |config|
43
+ config.basic_auth = "#{options[:username]}:#{options[:password]}"
44
+ if nil != options[:otp] then
45
+ config.connection_options = {headers: {"X-GitHub-OTP" => options[:otp]}}
46
+ end
47
+ end
48
+ token = github.auth.create scopes: ['repo'], note: 'sync-forks3'
49
+ puts "Created new token, use it to call sync-forks again:"
50
+ puts
51
+ puts "\tsync-forks -u #{user} -t #{token.token}"
52
+ puts
53
+ exit
54
+ else
55
+ puts "Must provide either a username/token or username/password/otp combination to authenticate."
56
+ puts parser
57
+ exit
58
+ end
59
+
60
+ repos = github.repos.list user: options[:username], auto_pagination: true
61
+ forks = repos.select {|x| x.fork}
62
+
63
+ current_dir = Dir.new(ARGV[0])
64
+ forks.each do |forked|
65
+ info = github.repos(user: options[:username], repo: forked.name).get
66
+ fork_url = info.source.ssh_url
67
+ name = forked.name
68
+ url = forked.ssh_url
69
+
70
+ puts '---'
71
+ if current_dir.entries.include? name then
72
+ puts "#{name} already exists."
73
+ else
74
+ echo_and_exec "git clone #{url}"
75
+ Dir.chdir "#{name}"
76
+ echo_and_exec "git remote add upstream #{fork_url}"
77
+ Dir.chdir ".."
78
+ end
79
+ end
data/lib/echoexec.rb ADDED
@@ -0,0 +1,4 @@
1
+ def echo_and_exec command
2
+ puts command
3
+ `#{command}`
4
+ end
metadata CHANGED
@@ -1,24 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tworingtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew McKnight
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-17 00:00:00.000000000 Z
12
- dependencies: []
13
- description: " - rebuild-sims: Delete all simulators and recreate one for each compatible
14
- platform and device type pairing.\n"
11
+ date: 2018-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: github_api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.18'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.18'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ description: |2
42
+ - rebuild-sims: Delete all simulators and recreate one for each compatible platform and device type pairing.
43
+ - sync-forks: Make sure all your GitHub forks are clones into a given directory, and have “upstream” remotes pointing to the repos that were forked.
15
44
  email: andrew@tworingsoft.com
16
45
  executables:
17
46
  - rebuild-sims
47
+ - sync-forks
18
48
  extensions: []
19
49
  extra_rdoc_files: []
20
50
  files:
21
51
  - bin/rebuild-sims
52
+ - bin/sync-forks
53
+ - lib/echoexec.rb
22
54
  homepage: https://github.com/TwoRingSoft/tools
23
55
  licenses:
24
56
  - MIT
@@ -39,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
39
71
  version: '0'
40
72
  requirements: []
41
73
  rubyforge_project:
42
- rubygems_version: 2.5.2.3
74
+ rubygems_version: 2.7.6
43
75
  signing_key:
44
76
  specification_version: 4
45
77
  summary: A collection of command line tools.