github_organizations_scraper 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,168 @@
1
+ Given /^this project is active project folder/ do
2
+ @active_project_folder = File.expand_path(File.dirname(__FILE__) + "/../..")
3
+ end
4
+
5
+ Given /^env variable \$([\w_]+) set to "(.*)"/ do |env_var, value|
6
+ ENV[env_var] = value
7
+ end
8
+
9
+ Given /"(.*)" folder is deleted/ do |folder|
10
+ in_project_folder { FileUtils.rm_rf folder }
11
+ end
12
+
13
+ When /^I invoke "(.*)" generator with arguments "(.*)"$/ do |generator, arguments|
14
+ @stdout = StringIO.new
15
+ in_project_folder do
16
+ if Object.const_defined?("APP_ROOT")
17
+ APP_ROOT.replace(FileUtils.pwd)
18
+ else
19
+ APP_ROOT = FileUtils.pwd
20
+ end
21
+ run_generator(generator, arguments.split(' '), SOURCES, :stdout => @stdout)
22
+ end
23
+ File.open(File.join(@tmp_root, "generator.out"), "w") do |f|
24
+ @stdout.rewind
25
+ f << @stdout.read
26
+ end
27
+ end
28
+
29
+ When /^I run executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
30
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
31
+ in_project_folder do
32
+ system "#{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
33
+ end
34
+ end
35
+
36
+ When /^I run project executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
37
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
38
+ in_project_folder do
39
+ system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
40
+ end
41
+ end
42
+
43
+ When /^I run local executable "(.*)" with arguments "(.*)"/ do |executable, arguments|
44
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
45
+ executable = File.expand_path(File.join(File.dirname(__FILE__), "/../../bin", executable))
46
+ in_project_folder do
47
+ system "ruby #{executable} #{arguments} > #{@stdout} 2> #{@stdout}"
48
+ end
49
+ end
50
+
51
+ When /^I invoke task "rake (.*)"/ do |task|
52
+ @stdout = File.expand_path(File.join(@tmp_root, "tests.out"))
53
+ in_project_folder do
54
+ system "rake #{task} --trace > #{@stdout} 2> #{@stdout}"
55
+ end
56
+ end
57
+
58
+ Then /^folder "(.*)" (is|is not) created/ do |folder, is|
59
+ in_project_folder do
60
+ File.exists?(folder).should(is == 'is' ? be_true : be_false)
61
+ end
62
+ end
63
+
64
+ Then /^file "(.*)" (is|is not) created/ do |file, is|
65
+ in_project_folder do
66
+ File.exists?(file).should(is == 'is' ? be_true : be_false)
67
+ end
68
+ end
69
+
70
+ Then /^file with name matching "(.*)" is created/ do |pattern|
71
+ in_project_folder do
72
+ Dir[pattern].should_not be_empty
73
+ end
74
+ end
75
+
76
+ Then /^file "(.*)" contents (does|does not) match \/(.*)\// do |file, does, regex|
77
+ in_project_folder do
78
+ actual_output = File.read(file)
79
+ (does == 'does') ?
80
+ actual_output.should(match(/#{regex}/)) :
81
+ actual_output.should_not(match(/#{regex}/))
82
+ end
83
+ end
84
+
85
+ Then /gem file "(.*)" and generated file "(.*)" should be the same/ do |gem_file, project_file|
86
+ File.exists?(gem_file).should be_true
87
+ File.exists?(project_file).should be_true
88
+ gem_file_contents = File.read(File.dirname(__FILE__) + "/../../#{gem_file}")
89
+ project_file_contents = File.read(File.join(@active_project_folder, project_file))
90
+ project_file_contents.should == gem_file_contents
91
+ end
92
+
93
+ Then /^(does|does not) invoke generator "(.*)"$/ do |does_invoke, generator|
94
+ actual_output = File.read(@stdout)
95
+ does_invoke == "does" ?
96
+ actual_output.should(match(/dependency\s+#{generator}/)) :
97
+ actual_output.should_not(match(/dependency\s+#{generator}/))
98
+ end
99
+
100
+ Then /help options "(.*)" and "(.*)" are displayed/ do |opt1, opt2|
101
+ actual_output = File.read(@stdout)
102
+ actual_output.should match(/#{opt1}/)
103
+ actual_output.should match(/#{opt2}/)
104
+ end
105
+
106
+ Then /^I should see "([^\"]*)"$/ do |text|
107
+ actual_output = File.read(@stdout)
108
+ actual_output.should contain(text)
109
+ end
110
+
111
+ Then /^I should see$/ do |text|
112
+ actual_output = File.read(@stdout)
113
+ actual_output.should contain(text)
114
+ end
115
+
116
+ Then /^I should not see$/ do |text|
117
+ actual_output = File.read(@stdout)
118
+ actual_output.should_not contain(text)
119
+ end
120
+
121
+ Then /^I should see exactly$/ do |text|
122
+ actual_output = File.read(@stdout)
123
+ actual_output.should == text
124
+ end
125
+
126
+ Then /^I should see all (\d+) tests pass/ do |expected_test_count|
127
+ expected = %r{^#{expected_test_count} tests, \d+ assertions, 0 failures, 0 errors}
128
+ actual_output = File.read(@stdout)
129
+ actual_output.should match(expected)
130
+ end
131
+
132
+ Then /^I should see all (\d+) examples pass/ do |expected_test_count|
133
+ expected = %r{^#{expected_test_count} examples?, 0 failures}
134
+ actual_output = File.read(@stdout)
135
+ actual_output.should match(expected)
136
+ end
137
+
138
+ Then /^yaml file "(.*)" contains (\{.*\})/ do |file, yaml|
139
+ in_project_folder do
140
+ yaml = eval yaml
141
+ YAML.load(File.read(file)).should == yaml
142
+ end
143
+ end
144
+
145
+ Then /^Rakefile can display tasks successfully/ do
146
+ @stdout = File.expand_path(File.join(@tmp_root, "rakefile.out"))
147
+ in_project_folder do
148
+ system "rake -T > #{@stdout} 2> #{@stdout}"
149
+ end
150
+ actual_output = File.read(@stdout)
151
+ actual_output.should match(/^rake\s+\w+\s+#\s.*/)
152
+ end
153
+
154
+ Then /^task "rake (.*)" is executed successfully/ do |task|
155
+ @stdout.should_not be_nil
156
+ actual_output = File.read(@stdout)
157
+ actual_output.should_not match(/^Don't know how to build task '#{task}'/)
158
+ actual_output.should_not match(/Error/i)
159
+ end
160
+
161
+ Then /^gem spec key "(.*)" contains \/(.*)\// do |key, regex|
162
+ in_project_folder do
163
+ gem_file = Dir["pkg/*.gem"].first
164
+ gem_spec = Gem::Specification.from_yaml(`gem spec #{gem_file}`)
165
+ spec_value = gem_spec.send(key.to_sym)
166
+ spec_value.to_s.should match(/#{regex}/)
167
+ end
168
+ end
@@ -0,0 +1,12 @@
1
+ # a version of the bin/tweet-tail file
2
+ When /^I run the executable with arguments "([^\"]*)"$/ do |args|
3
+ require 'rubygems'
4
+ require File.dirname(__FILE__) + "/../../lib/github_organizations_scraper"
5
+ require "github_organizations_scraper/cli"
6
+ @stdout = File.expand_path(File.join(@tmp_root, "executable.out"))
7
+ in_project_folder do
8
+ GithubOrganizationsScraper::CLI.execute(@stdout_io = StringIO.new, args.split(" "))
9
+ @stdout_io.rewind
10
+ File.open(@stdout, "w") { |f| f << @stdout_io.read }
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ Given /^a github (organization|user) "([^"]*)"$/ do |account_type, account|
2
+ body = File.read(File.dirname(__FILE__) + "/../fixtures/#{account}.html")
3
+ FakeWeb.register_uri(:get, "http://github.com/#{account}", :body => body)
4
+ end
@@ -0,0 +1,5 @@
1
+ Then /^I should see valid JSON$/ do
2
+ actual_output = File.read(@stdout)
3
+ lambda { JSON.parse(actual_output) }.should_not raise_error(JSON::ParserError)
4
+ puts actual_output
5
+ end
@@ -0,0 +1,29 @@
1
+ module CommonHelpers
2
+ def in_tmp_folder(&block)
3
+ FileUtils.chdir(@tmp_root, &block)
4
+ end
5
+
6
+ def in_project_folder(&block)
7
+ project_folder = @active_project_folder || @tmp_root
8
+ FileUtils.chdir(project_folder, &block)
9
+ end
10
+
11
+ def in_home_folder(&block)
12
+ FileUtils.chdir(@home_path, &block)
13
+ end
14
+
15
+ def force_local_lib_override(project_name = @project_name)
16
+ rakefile = File.read(File.join(project_name, 'Rakefile'))
17
+ File.open(File.join(project_name, 'Rakefile'), "w+") do |f|
18
+ f << "$:.unshift('#{@lib_path}')\n"
19
+ f << rakefile
20
+ end
21
+ end
22
+
23
+ def setup_active_project_folder project_name
24
+ @active_project_folder = File.join(@tmp_root, project_name)
25
+ @project_name = project_name
26
+ end
27
+ end
28
+
29
+ World(CommonHelpers)
@@ -0,0 +1,14 @@
1
+ require "bundler" # bundler 0.9.26
2
+ Bundler.setup
3
+
4
+ require "rspec"
5
+ require "cucumber"
6
+
7
+ Before do
8
+ @tmp_root = File.dirname(__FILE__) + "/../../tmp"
9
+ @home_path = File.expand_path(File.join(@tmp_root, "home"))
10
+ @lib_path = File.expand_path(File.dirname(__FILE__) + "/../../lib")
11
+ FileUtils.rm_rf @tmp_root
12
+ FileUtils.mkdir_p @home_path
13
+ ENV['HOME'] = @home_path
14
+ end
@@ -0,0 +1,5 @@
1
+ require "fakeweb"
2
+
3
+ Before do
4
+ FakeWeb.allow_net_connect = false
5
+ end
@@ -0,0 +1,9 @@
1
+ RSpec::Matchers.define :contain do |expected|
2
+ match do |actual|
3
+ actual.index expected
4
+ end
5
+
6
+ failure_message_for_should do |actual|
7
+ "expected #{actual.inspect} to contain #{expected.inspect}"
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module GithubOrganizationsScraper
5
+ VERSION = '0.5.0'
6
+ end
@@ -0,0 +1,59 @@
1
+ require 'optparse'
2
+ require 'net/http'
3
+ require 'nokogiri'
4
+
5
+ module GithubOrganizationsScraper
6
+ class CLI
7
+ def self.execute(stdout, arguments=[])
8
+
9
+ options = {}
10
+
11
+ parser = OptionParser.new do |opts|
12
+ opts.banner = <<-BANNER.gsub(/^ /,'')
13
+ Display the members of an organisation account on GitHub.
14
+
15
+ Usage: #{File.basename($0)} [options]
16
+
17
+ Options are:
18
+ BANNER
19
+ opts.separator ""
20
+ opts.on("-j", "--json",
21
+ "Display results in JSON format") { options[:json] = true }
22
+ opts.on("-h", "--help",
23
+ "Show this help message.") { stdout.puts opts; exit }
24
+ opts.parse!(arguments)
25
+
26
+ end
27
+
28
+ account = arguments.shift
29
+ html = Net::HTTP.get(URI.parse("http://github.com/#{account}"))
30
+ doc = Nokogiri::HTML(html)
31
+ members = doc.search("ul.org-members li").map do |member|
32
+ login = member.search("h4 a").text
33
+ if member.search("h4 em").text =~ /\((.*)\)/
34
+ name = $1
35
+ end
36
+ repo_summary = member.search("p").text
37
+ { :login => login, :name => name, :repo_summary => repo_summary }
38
+ end
39
+
40
+ if options[:json]
41
+ display_members_json(stdout, members)
42
+ else
43
+ display_members_tty(stdout, members)
44
+ end
45
+ end
46
+
47
+ def self.display_members_tty(stdout, members)
48
+ members.each do |member|
49
+ details = [member[:login], member[:name], member[:repo_summary]].reject { |d| d.nil? }
50
+ stdout.puts details.join(", ")
51
+ end
52
+ end
53
+
54
+ def self.display_members_json(stdout, members)
55
+ require "json"
56
+ stdout.print members.map { |mem| { "user" => mem } }.to_json
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/github_organizations_scraper.rb'}"
9
+ puts "Loading github_organizations_scraper gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,15 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'github_organizations_scraper/cli'
3
+
4
+ describe GithubOrganizationsScraper::CLI, "execute" do
5
+ before(:each) do
6
+ @stdout_io = StringIO.new
7
+ GithubOrganizationsScraper::CLI.execute(@stdout_io, [])
8
+ @stdout_io.rewind
9
+ @stdout = @stdout_io.read
10
+ end
11
+
12
+ it "should print default output" do
13
+ @stdout.should =~ /To update this executable/
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ # Time to add your specs!
4
+ # http://rspec.info/
5
+ describe "Place your specs here" do
6
+
7
+ it "find this spec in spec directory" do
8
+ # violated "Be sure to write your specs"
9
+ end
10
+
11
+ end
@@ -0,0 +1,6 @@
1
+ require "bundler"
2
+ Bundler.setup
3
+ Bundler.require :spec
4
+
5
+ $:.unshift(File.dirname(__FILE__) + '/../../lib')
6
+ require 'github_organizations_scraper'
metadata ADDED
@@ -0,0 +1,239 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github_organizations_scraper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 11
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 5
9
+ - 0
10
+ version: 0.5.0
11
+ platform: ruby
12
+ authors:
13
+ - Dr Nic Williams
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-11 00:00:00 +10:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 7
28
+ segments:
29
+ - 2
30
+ - 0
31
+ - 4
32
+ version: 2.0.4
33
+ type: :development
34
+ prerelease: false
35
+ name: rubyforge
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 21
44
+ segments:
45
+ - 2
46
+ - 6
47
+ - 1
48
+ version: 2.6.1
49
+ type: :development
50
+ prerelease: false
51
+ name: hoe
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - "="
58
+ - !ruby/object:Gem::Version
59
+ hash: 21
60
+ segments:
61
+ - 0
62
+ - 2
63
+ - 1
64
+ version: 0.2.1
65
+ type: :runtime
66
+ prerelease: false
67
+ name: awesome_print
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - "="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 1
78
+ - 4
79
+ - 2
80
+ version: 1.4.2
81
+ type: :runtime
82
+ prerelease: false
83
+ name: nokogiri
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - "="
90
+ - !ruby/object:Gem::Version
91
+ hash: 1
92
+ segments:
93
+ - 1
94
+ - 4
95
+ - 3
96
+ version: 1.4.3
97
+ type: :runtime
98
+ prerelease: false
99
+ name: json
100
+ version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ requirement: &id006 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ type: :development
112
+ prerelease: false
113
+ name: bundler
114
+ version_requirements: *id006
115
+ - !ruby/object:Gem::Dependency
116
+ requirement: &id007 !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 31098209
122
+ segments:
123
+ - 2
124
+ - 0
125
+ - 0
126
+ - beta
127
+ version: 2.0.0.beta
128
+ type: :development
129
+ prerelease: false
130
+ name: rspec
131
+ version_requirements: *id007
132
+ - !ruby/object:Gem::Dependency
133
+ requirement: &id008 !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - "="
137
+ - !ruby/object:Gem::Version
138
+ hash: 57
139
+ segments:
140
+ - 0
141
+ - 8
142
+ - 3
143
+ version: 0.8.3
144
+ type: :development
145
+ prerelease: false
146
+ name: cucumber
147
+ version_requirements: *id008
148
+ - !ruby/object:Gem::Dependency
149
+ requirement: &id009 !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - "="
153
+ - !ruby/object:Gem::Version
154
+ hash: 15
155
+ segments:
156
+ - 1
157
+ - 2
158
+ - 8
159
+ version: 1.2.8
160
+ type: :development
161
+ prerelease: false
162
+ name: fakeweb
163
+ version_requirements: *id009
164
+ description: Scrape Github Organization member information. Currently, the Github API doesn't support the new Organizations feature. This CLI scrapes the list of members for an Organization.
165
+ email:
166
+ - drnicwilliams@gmail.com
167
+ executables:
168
+ - github_organizations_scraper
169
+ extensions: []
170
+
171
+ extra_rdoc_files:
172
+ - History.txt
173
+ - Manifest.txt
174
+ files:
175
+ - .bundle/config
176
+ - .rspec
177
+ - Gemfile
178
+ - History.txt
179
+ - Manifest.txt
180
+ - README.rdoc
181
+ - Rakefile
182
+ - bin/github_organizations_scraper
183
+ - features/cli.feature
184
+ - features/development.feature
185
+ - features/fixtures/drnic.html
186
+ - features/fixtures/engineyard.html
187
+ - features/step_definitions/common_steps.rb
188
+ - features/step_definitions/executable_steps.rb
189
+ - features/step_definitions/github_steps.rb
190
+ - features/step_definitions/json_steps.rb
191
+ - features/support/common.rb
192
+ - features/support/env.rb
193
+ - features/support/fakeweb.rb
194
+ - features/support/matchers.rb
195
+ - lib/github_organizations_scraper.rb
196
+ - lib/github_organizations_scraper/cli.rb
197
+ - script/console
198
+ - script/destroy
199
+ - script/generate
200
+ - spec/github_organizations_scraper_cli_spec.rb
201
+ - spec/github_organizations_scraper_spec.rb
202
+ - spec/spec_helper.rb
203
+ has_rdoc: true
204
+ homepage: http://github.com/drnic/github_organizations_scraper
205
+ licenses: []
206
+
207
+ post_install_message:
208
+ rdoc_options:
209
+ - --main
210
+ - README.rdoc
211
+ require_paths:
212
+ - lib
213
+ required_ruby_version: !ruby/object:Gem::Requirement
214
+ none: false
215
+ requirements:
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ hash: 3
219
+ segments:
220
+ - 0
221
+ version: "0"
222
+ required_rubygems_version: !ruby/object:Gem::Requirement
223
+ none: false
224
+ requirements:
225
+ - - ">="
226
+ - !ruby/object:Gem::Version
227
+ hash: 3
228
+ segments:
229
+ - 0
230
+ version: "0"
231
+ requirements: []
232
+
233
+ rubyforge_project: github_organizations_scraper
234
+ rubygems_version: 1.3.7
235
+ signing_key:
236
+ specification_version: 3
237
+ summary: Scrape Github Organization member information
238
+ test_files: []
239
+