makers_toolbelt 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/makers +34 -0
- data/command_map.yml +3 -0
- data/lib/makers_toolbelt/fetch_pull_requests.rb +70 -0
- data/lib/makers_toolbelt.rb +2 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1c9fb2b90998dc14414977e405e5fd07e0a988e7
|
4
|
+
data.tar.gz: 38c81495bd401c25e10bc9694d82642cc7f78ff3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: caf8d12d671025bc1fc4d424b953c7177c3130014908a686793c9eec8b81cd6fcde6a1aa4b93fb5e241a139ed2f0b7c14da3f83c924b6f0e7b89cb2d6fd3c9ba
|
7
|
+
data.tar.gz: 020b45d5aad48c4ef5fc422d27c5531a354c21882739baac3b58763d708bd6bc341f84fd46b8a5377deff1df6b648689361a62a4d02da31a8d5ec719c5724d4d
|
data/bin/makers
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'makers_toolbelt'
|
4
|
+
|
5
|
+
module MakersToolbelt
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def run(command, *args)
|
9
|
+
map = command_map[command]
|
10
|
+
|
11
|
+
fail "Unknown command #{command}" unless map
|
12
|
+
|
13
|
+
args_hash = map['args'].each_with_index.inject({}) do |hash, arg_with_index|
|
14
|
+
key, index = *arg_with_index
|
15
|
+
hash[key.to_sym] = args[index]
|
16
|
+
hash
|
17
|
+
end
|
18
|
+
runner = eval(map['class']).new(args_hash)
|
19
|
+
runner.run
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def command_map
|
25
|
+
@command_map ||= load_command_map
|
26
|
+
end
|
27
|
+
|
28
|
+
def load_command_map
|
29
|
+
YAML.load(File.read(File.expand_path('../../command_map.yml', __FILE__)))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
MakersToolbelt.run(ARGV[0], *ARGV.slice(1, ARGV.length - 1))
|
data/command_map.yml
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'octokit'
|
2
|
+
|
3
|
+
module MakersToolbelt
|
4
|
+
class FetchPullRequests
|
5
|
+
OPEN_SWITCHES = ['-a', '--all', '-o', '--open']
|
6
|
+
CLOSED_SWITCHES = ['-a', '--all', '-c', '--closed']
|
7
|
+
|
8
|
+
attr_reader :options, :filter
|
9
|
+
|
10
|
+
def initialize(options = {})
|
11
|
+
@options = options
|
12
|
+
@filter = options[:filter] || '--open'
|
13
|
+
end
|
14
|
+
|
15
|
+
def run()
|
16
|
+
pulls = []
|
17
|
+
pulls << open_pull_requests if include_open?
|
18
|
+
pulls << closed_pull_requests if include_closed?
|
19
|
+
|
20
|
+
pulls.flatten!.select! {|p| p.head.repo }
|
21
|
+
|
22
|
+
puts pulls
|
23
|
+
pulls.map { |p| [p.head.repo.owner.login, p.head.repo.html_url] }.each do |name, url|
|
24
|
+
puts "adding #{name}"
|
25
|
+
`git remote add #{name} #{url}`
|
26
|
+
puts "fetching #{url}"
|
27
|
+
`git fetch #{name}`
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def repo
|
32
|
+
@repo ||= repo_from_remote_path(origin_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
def repo_from_remote_path(path)
|
36
|
+
@regex ||= /\s*(?:Fetch URL: )?(?:https:\/\/|git@)github\.com(?::|\/)?(.*\/.*).git/
|
37
|
+
@regex.match(path).captures.first
|
38
|
+
end
|
39
|
+
|
40
|
+
def include_open?
|
41
|
+
OPEN_SWITCHES.include? filter
|
42
|
+
end
|
43
|
+
|
44
|
+
def include_closed?
|
45
|
+
CLOSED_SWITCHES.include? filter
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def open_pull_requests
|
51
|
+
puts "fetching open pull requests from #{repo}..."
|
52
|
+
client.pull_requests repo, state: 'open', per_page: 100
|
53
|
+
end
|
54
|
+
|
55
|
+
def closed_pull_requests
|
56
|
+
puts "fetching closed pull requests from #{repo}..."
|
57
|
+
pulls = client.pull_requests repo, state: 'closed', per_page: 100
|
58
|
+
pulls.concat client.last_response.rels[:next].get.data
|
59
|
+
end
|
60
|
+
|
61
|
+
def origin_path
|
62
|
+
@origin_path ||= `git remote show origin | grep 'Fetch URL:'`
|
63
|
+
end
|
64
|
+
|
65
|
+
def client
|
66
|
+
@client ||= Octokit::Client.new client_id: ENV['GITHUB_CLIENT_ID'], client_secret: ENV['GITHUB_CLIENT_SECRET']
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: makers_toolbelt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Forrest
|
8
|
+
- Sam Joseph
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-09-25 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description:
|
15
|
+
email:
|
16
|
+
executables:
|
17
|
+
- makers
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- bin/makers
|
22
|
+
- command_map.yml
|
23
|
+
- lib/makers_toolbelt.rb
|
24
|
+
- lib/makers_toolbelt/fetch_pull_requests.rb
|
25
|
+
homepage:
|
26
|
+
licenses: []
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.4.5.1
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Makers Academy command toolbelt
|
48
|
+
test_files: []
|