hubish 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Russell Garner
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ = hubish
2
+
3
+ Hubish is for exporting github issues in XML form (import to follow).
4
+
5
+ == Usage
6
+
7
+ gem install hubish
8
+
9
+ script/generate hubish <repo_name>
10
+
11
+ rake github:export[login, token]
12
+
13
+ Note you can supply login and token via GITHUB_LOGIN and GITHUB_TOKEN environment variables.
14
+
15
+ == Note on Patches/Pull Requests
16
+
17
+ * Fork the project.
18
+ * Make your feature addition or bug fix.
19
+ * Add tests for it. This is important so I don't break it in a
20
+ future version unintentionally.
21
+ * Commit, do not mess with rakefile, version, or history.
22
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
23
+ * Send me a pull request. Bonus points for topic branches.
24
+
25
+ == Copyright
26
+
27
+ Copyright (c) 2010 Russell Garner. See LICENSE for details.
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "hubish"
8
+ gem.summary = %Q{A rubbish github issues importer/exporter}
9
+ gem.description = %Q{Imports and exports issues from github per-project}
10
+ gem.email = "rgarner@zephyros-systems.co.uk"
11
+ gem.homepage = "http://github.com/rgarner/hubish"
12
+ gem.authors = ["Russell Garner"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_dependency "nokogiri", ">= 1.4.1"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+
17
+ gem.files = FileList["[A-Z]*", "{generators,lib,spec}/**/*"] - FileList["**/*.log"]
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
22
+ end
23
+
24
+ require 'spec/rake/spectask'
25
+ Spec::Rake::SpecTask.new(:spec) do |spec|
26
+ spec.libs << 'lib' << 'spec'
27
+ spec.spec_files = FileList['spec/**/*_spec.rb']
28
+ end
29
+
30
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
31
+ spec.libs << 'lib' << 'spec'
32
+ spec.pattern = 'spec/**/*_spec.rb'
33
+ spec.rcov = true
34
+ end
35
+
36
+ task :spec => :check_dependencies
37
+
38
+ task :default => :spec
39
+
40
+ require 'rake/rdoctask'
41
+ Rake::RDocTask.new do |rdoc|
42
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "hubish #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,15 @@
1
+ class HubishGenerator < Rails::Generator::NamedBase
2
+ attr_reader :repo
3
+
4
+ def initialize(runtime_args, runtime_options = {})
5
+ super
6
+ raise ArgumentError, "repo name expected as only argument" if name.nil?
7
+ @repo = name
8
+ end
9
+
10
+ def manifest
11
+ record do |m|
12
+ m.template('github.rb', 'lib/tasks/github.rake')
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ require 'github_exporter'
2
+
3
+ namespace :github do
4
+ desc "Export github issues (pass credentials through rake parameters or GITHUB_LOGIN=, GITHUB_TOKEN=)"
5
+ task :export, :login, :token, :needs => :environment do |t, args|
6
+ exporter = GitHub::Exporter.new('<%= repo %>', args.login || ENV['GITHUB_LOGIN'], args.token || ENV['GITHUB_TOKEN'])
7
+ exporter.export!
8
+ puts exporter.issues
9
+ end
10
+ end
@@ -0,0 +1,66 @@
1
+ require 'nokogiri'
2
+
3
+ module GitHub
4
+ GITHUB_XML_BASE = 'http://github.com/api/v2/xml'
5
+
6
+ class Exporter
7
+ def initialize(repo, login = nil, token = nil)
8
+ @login = login || ENV['GITHUB_LOGIN']
9
+ @token = token || ENV['GITHUB_TOKEN']
10
+
11
+ raise ArgumentError, "Login required (pass login)" unless @login
12
+ raise ArgumentError, "Token required (pass token)" unless @token
13
+
14
+ issues_base = File::join GITHUB_XML_BASE, "issues/list/#{@login}/#{repo}"
15
+ @open_issues = issues_base + '/open'
16
+ @closed_issues = issues_base + '/closed'
17
+ @comments_base = File::join GITHUB_XML_BASE, "issues/comments/#{@login}/#{repo}"
18
+ end
19
+
20
+ def export!
21
+ @issues_doc = consolidate(@open_issues, @closed_issues)
22
+ end
23
+
24
+ def issues
25
+ @issues_doc
26
+ end
27
+
28
+ private
29
+ def post(url)
30
+ $stderr.puts "Fetching #{url}"
31
+ Net::HTTP.post_form(URI.parse(url), {'login' => @login, 'token' => @token})
32
+ end
33
+
34
+ def fetch_doc(url)
35
+ response = nil
36
+ while true
37
+ response = post(url)
38
+ if response.code == '403'
39
+ $stderr.puts "Sleeping 10..."; sleep 10; next
40
+ end
41
+ break
42
+ end
43
+
44
+ raise RuntimeError, "Did not fetch #{url} successfully (#{response.code}) with " +
45
+ "#{@login}/#{@token}" unless response.is_a? Net::HTTPSuccess
46
+
47
+ Nokogiri::Slop(response.body)
48
+ end
49
+
50
+ def consolidate(*issue_uris)
51
+ result = Nokogiri::XML.parse '<issues />'
52
+ issue_uris.each do |url|
53
+ fetch_doc(url).css('issue').each do |issue|
54
+ if issue.comments.content.to_i > 0 then
55
+ issue.comments.unlink
56
+
57
+ comments_doc = fetch_doc("#{@comments_base}/#{issue.number.content}")
58
+ comments_doc.comments.parent = issue
59
+ end
60
+ result.root << issue
61
+ end
62
+ end
63
+ result
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require "github_exporter"
3
+
4
+ describe GitHub::Exporter do
5
+ TOKEN = '2eb23873fab2eb'
6
+ LOGIN = 'colin'
7
+
8
+ describe "Required credentials" do
9
+ it "needs a login" do
10
+ lambda {GitHub::Exporter.new('reponame', nil, TOKEN)}.should raise_error ArgumentError
11
+ end
12
+
13
+ it "needs a token" do
14
+ lambda {GitHub::Exporter.new('reponame', LOGIN, nil)}.should raise_error ArgumentError
15
+ end
16
+
17
+ it "needs both login and token" do
18
+ GitHub::Exporter.new('reponame', LOGIN, TOKEN)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'spec'
4
+ require 'spec/autorun'
5
+
6
+ Spec::Runner.configure do |config|
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hubish
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Russell Garner
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-07 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 13
30
+ segments:
31
+ - 1
32
+ - 2
33
+ - 9
34
+ version: 1.2.9
35
+ type: :development
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: nokogiri
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 5
46
+ segments:
47
+ - 1
48
+ - 4
49
+ - 1
50
+ version: 1.4.1
51
+ type: :runtime
52
+ version_requirements: *id002
53
+ description: Imports and exports issues from github per-project
54
+ email: rgarner@zephyros-systems.co.uk
55
+ executables: []
56
+
57
+ extensions: []
58
+
59
+ extra_rdoc_files:
60
+ - LICENSE
61
+ - README.rdoc
62
+ files:
63
+ - LICENSE
64
+ - README.rdoc
65
+ - Rakefile
66
+ - VERSION
67
+ - generators/hubish/hubish_generator.rb
68
+ - generators/hubish/templates/github.rb
69
+ - lib/github_exporter.rb
70
+ - spec/github_exporter_spec.rb
71
+ - spec/spec.opts
72
+ - spec/spec_helper.rb
73
+ has_rdoc: true
74
+ homepage: http://github.com/rgarner/hubish
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --charset=UTF-8
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ hash: 3
97
+ segments:
98
+ - 0
99
+ version: "0"
100
+ requirements: []
101
+
102
+ rubyforge_project:
103
+ rubygems_version: 1.3.7
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: A rubbish github issues importer/exporter
107
+ test_files:
108
+ - spec/github_exporter_spec.rb
109
+ - spec/spec_helper.rb