github-issues 0.0.1

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.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,25 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ github-issues (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ rspec (2.7.0)
11
+ rspec-core (~> 2.7.0)
12
+ rspec-expectations (~> 2.7.0)
13
+ rspec-mocks (~> 2.7.0)
14
+ rspec-core (2.7.1)
15
+ rspec-expectations (2.7.0)
16
+ diff-lcs (~> 1.1.2)
17
+ rspec-mocks (2.7.0)
18
+
19
+ PLATFORMS
20
+ java
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ github-issues!
25
+ rspec (~> 2.1)
@@ -0,0 +1,45 @@
1
+ # Github Issues
2
+
3
+ This is a little API that gives easy access to the github issues. I started the project because I had to move tickets from github to redmine.
4
+
5
+ The API is called using ``URI.open`` and YAML for serialization.
6
+
7
+ **Note: this is currently a read-only API, also this just covers version 2 of the API**
8
+
9
+ ## Installing
10
+
11
+ gem install github-issues
12
+
13
+ ## Usage
14
+
15
+ ### Connecting to the issues host
16
+
17
+ In order to access the information on the github repository one has to make a connection to the remote repository.
18
+
19
+ repo = Github.connect("threez", "github-issues")
20
+
21
+ ### Reading all issues
22
+
23
+ This will return all issues found on the repository.
24
+
25
+ repo.issues.all # => [Github::Issue, ...]
26
+
27
+ ### Reading just open or closed issues
28
+
29
+ Filter which issues should be displayed.
30
+
31
+ repo.issues.all(:open) # => [Github::Issue, ...]
32
+ repo.issues.all(:closed) # => [Github::Issue, ...]
33
+
34
+ ### Getting informations about a issue
35
+
36
+ access all the information of an issue easily:
37
+
38
+ issue.number # => 64
39
+ issue.createt_at # => Time
40
+ issue.comments # => [Github::Issue::Comment, ...]
41
+
42
+ ### Comments in an issue
43
+
44
+ comment.user # => "threez"
45
+ comment.body # => "close #34 (implemented read-only part)"
@@ -0,0 +1,7 @@
1
+ require "rspec/core/rake_task"
2
+ RSpec::Core::RakeTask.new(:spec) do |spec|
3
+ spec.pattern = 'spec/*_spec.rb'
4
+ spec.rspec_opts = ['--backtrace']
5
+ end
6
+
7
+ task :default => :spec
@@ -0,0 +1,43 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push('lib')
3
+ require "github-issues/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "github-issues"
7
+ s.version = Github::Issues::VERSION.dup
8
+ s.date = "2011-12-04"
9
+ s.summary = "An api to githubs issues system"
10
+ s.email = "vilandgr+github@googlemail.com "
11
+ s.homepage = "https://github.com/threez/github-issues"
12
+ s.authors = ['Vincent Landgraf']
13
+
14
+ s.description = <<-EOF
15
+ This is a little API that gives easy access to the github issues. It is
16
+ currently a read-only API.
17
+ EOF
18
+
19
+ dependencies = [
20
+ # Examples:
21
+ # [:runtime, "rack", "~> 1.1"],
22
+ [:development, "rspec", "~> 2.1"],
23
+ ]
24
+
25
+ s.files = Dir['**/*']
26
+ s.test_files = Dir['test/**/*'] + Dir['spec/**/*']
27
+ s.executables = Dir['bin/*'].map { |f| File.basename(f) }
28
+ s.require_paths = ["lib"]
29
+
30
+
31
+ ## Make sure you can build the gem on older versions of RubyGems too:
32
+ s.rubygems_version = "1.8.9"
33
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
34
+ s.specification_version = 3 if s.respond_to? :specification_version
35
+
36
+ dependencies.each do |type, name, version|
37
+ if s.respond_to?("add_#{type}_dependency")
38
+ s.send("add_#{type}_dependency", name, version)
39
+ else
40
+ s.add_dependency(name, version)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ lib = File.join(File.dirname(__FILE__), "github-issues")
2
+
3
+ require "open-uri"
4
+ require "yaml"
5
+ require File.join(lib, "github")
6
+ require File.join(lib, "issue")
7
+ require File.join(lib, "comment")
@@ -0,0 +1,9 @@
1
+ class Github::Issue::Comment
2
+ attr_accessor :gravatar_id, :created_at, :body, :updated_at, :id, :user
3
+
4
+ # Initialize the comment using the passed fields.
5
+ # @param [Hash] fields the fields that will initialize the comment.
6
+ def initialize(fields = {})
7
+ fields.each { |name, value| self.send("#{name}=", value) }
8
+ end
9
+ end
@@ -0,0 +1,67 @@
1
+ class Github < Struct.new(:username, :repository_name, :protocol)
2
+ # Connects to the remote repository
3
+ # @param [String, Symbol] username the name of the user or organization
4
+ # @param [String, Symbol] repository_name the name of the repository
5
+ # @param [Boolean] secure the connection using https
6
+ # @return a new github instance for that repository
7
+ def self.connect(username, repository_name, secure = false)
8
+ new(username.to_s, repository_name.to_s, secure ? "https" : "http")
9
+ end
10
+
11
+ # This class handles the requests on the list of issues
12
+ # @visibility private
13
+ class IssuesProxy
14
+ # Initializes the issues proxy with the passed repository.
15
+ # @param [Github] repository the repository to connect to
16
+ def initialize(repository)
17
+ @repository = repository
18
+ end
19
+
20
+ # Returns all the tickets of a repository. A filter can be passed to reduce
21
+ # the number of tickets.
22
+ # @param [Symbol] state the state to filter for (:open or :close)
23
+ def all(state = :all)
24
+ if state == :all
25
+ all(:open) + all(:closed)
26
+ else
27
+ @repository.load(:list, state, :issues).map do |fields|
28
+ issue = Github::Issue.new(fields)
29
+ issue.repository = @repository
30
+ issue
31
+ end
32
+ end
33
+ end
34
+
35
+ # Returns the issue identified by the passed id.
36
+ # @param [Fixnum] issue_id the issue to find
37
+ def find(issue_id)
38
+ issue = Github::Issue.new(@repository.load(:show, issue_id, :issue))
39
+ issue.repository = @repository
40
+ issue
41
+ end
42
+ end
43
+
44
+ # Returns the general url to the repository.
45
+ # @param [String] action the action that should be inserted into the url
46
+ # @param [String, Fixnum, Symbol] filter the filter for the url
47
+ # @return [String] the url for the issue
48
+ def url(action, filter = nil)
49
+ "#{protocol}://github.com/api/v2/yaml/issues/#{action}/" \
50
+ "#{username}/#{repository_name}" + (filter ? "/#{filter}" : "")
51
+ end
52
+
53
+ # Returns the structure (the hash) found by the resource criteria.
54
+ # @param [String] action the action that should be inserted into the url
55
+ # @param [String, Fixnum, Symbol] filter the filter for the url
56
+ # @param [Symbol] name of the resource by default the action name
57
+ # @return [Hash] the structure of the remote resource
58
+ def load(action, filter = nil, name = nil)
59
+ YAML.load(open(url(action, filter)))[(name || action).to_s]
60
+ end
61
+
62
+ # Returns an issues proxy object
63
+ # @return [IssuesProxy] the proxy
64
+ def issues
65
+ IssuesProxy.new(self)
66
+ end
67
+ end
@@ -0,0 +1,47 @@
1
+ class Github::Issue
2
+ attr_accessor :position, :number, :votes, :created_at, :body, :labels, :state,
3
+ :title, :updated_at, :closed_at, :gravatar_id, :html_url, :user,
4
+ :comments_count, :diff_url, :patch_url, :pull_request_url,
5
+ :repository
6
+
7
+ # Initialize the issue using the passed fields.
8
+ # @param [Hash] fields the fields that will initialize the comment.
9
+ def initialize(fields = {})
10
+ fields.each { |name, value| self.send("#{name}=", value) }
11
+ end
12
+
13
+ # Returns true if the issue is closed
14
+ def closed?
15
+ state == "closed"
16
+ end
17
+
18
+ # Returns true if the issue is open
19
+ def open?
20
+ state == "open"
21
+ end
22
+
23
+ # This updates the comments on an issue. The API returns here the number of
24
+ # comments. Not the actual comments.
25
+ # @param [Fixnum] count the count of existing comments
26
+ def comments=(count)
27
+ @comments_count = count
28
+ end
29
+
30
+ # Returns true if the issue has comments.
31
+ def has_comments?
32
+ @comments_count > 0
33
+ end
34
+
35
+ # Fetches the comments only if the issue has some.
36
+ # @return [Array<Github::Issue::Comment>] the comments that belong to that
37
+ # issue
38
+ def comments
39
+ if has_comments?
40
+ @repository.load(:comments, number).map do |item|
41
+ Github::Issue::Comment.new(item)
42
+ end
43
+ else
44
+ []
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ module Github
2
+ module Issues
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Github::Issue::Comment do
4
+ it "should be possible to parse a comment" do
5
+ comment = Github::Issue::Comment.new(
6
+ "gravatar_id" => "8194993afda83d34c94928134b729276",
7
+ "created_at" => Time.parse("2010/05/05 15:15:53 -0700"),
8
+ "body" => "Showing off the issues app.",
9
+ "updated_at" => Time.parse("2010/05/05 15:15:53 -0700"),
10
+ "id" => 230935,
11
+ "user" => "280north"
12
+ )
13
+ comment.user.should == "280north"
14
+ comment.body.should == "Showing off the issues app."
15
+ end
16
+ end
@@ -0,0 +1,43 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Github do
4
+ it "should connect to the remote rails repository" do
5
+ repo = Github.connect(USERNAME, REPO)
6
+ repo.username.should == USERNAME
7
+ repo.repository_name.should == REPO
8
+ end
9
+
10
+ context "with rails repo" do
11
+ before(:each) do
12
+ @repo = Github.connect(USERNAME, REPO)
13
+ end
14
+
15
+ it "should return the correct repo path" do
16
+ @repo.url(:list).should == \
17
+ "http://github.com/api/v2/yaml/issues/list/#{USERNAME}/#{REPO}"
18
+ end
19
+
20
+ it "should return an issues proxy object" do
21
+ @repo.issues.should be_a(Github::IssuesProxy)
22
+ end
23
+
24
+ it "should find tickets" do
25
+ @repo.issues.all.should_not be_empty
26
+ end
27
+
28
+ it "should filter tickets by state" do
29
+ open = @repo.issues.all(:open)
30
+ closed = @repo.issues.all(:closed)
31
+ open.should_not be_empty
32
+ closed.should_not be_empty
33
+ open.should_not == closed
34
+ end
35
+
36
+ it "should be possible to fetch an issue" do
37
+ issue = @repo.issues.find(10)
38
+ issue.has_comments?.should be_true
39
+ issue.comments_count.should > 0
40
+ issue.comments.should_not be_empty
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,42 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe Github::Issue do
4
+ it "should be possible to parse an issue" do
5
+ issue = Github::Issue.new("position" => 1.0,
6
+ "number" => 1,
7
+ "votes" => 0,
8
+ "created_at" => Time.parse("2011-04-18 21:00:31 +0200"),
9
+ "comments" => 0,
10
+ "body" => "",
11
+ "title" => "General Layout",
12
+ "updated_at" => Time.parse("2011-04-18 22:56:17 +0200"),
13
+ "closed_at" => Time.parse("2011-04-18 22:56:17 +0200"),
14
+ "gravatar_id" => "e372514c922684dfb07578aa59e5a2b8",
15
+ "html_url" => "https://github.com/inovex/inovex.de/issues/1",
16
+ "user" => "threez",
17
+ "labels" => [],
18
+ "state" => "closed")
19
+ issue.title.should == "General Layout"
20
+ issue.closed?.should == true
21
+ end
22
+
23
+ it "should be possible to handle the comments correctly" do
24
+ issue = Github::Issue.new("position" => 1.0,
25
+ "number" => 1,
26
+ "votes" => 0,
27
+ "created_at" => Time.parse("2011-04-18 21:00:31 +0200"),
28
+ "comments" => 0,
29
+ "body" => "",
30
+ "title" => "General Layout",
31
+ "updated_at" => Time.parse("2011-04-18 22:56:17 +0200"),
32
+ "closed_at" => Time.parse("2011-04-18 22:56:17 +0200"),
33
+ "gravatar_id" => "e372514c922684dfb07578aa59e5a2b8",
34
+ "html_url" => "https://github.com/inovex/inovex.de/issues/1",
35
+ "user" => "threez",
36
+ "labels" => [],
37
+ "state" => "closed")
38
+ issue.comments_count.should == 0
39
+ issue.comments.should == []
40
+ issue.has_comments?.should be_false
41
+ end
42
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
2
+
3
+ USERNAME = "rails"
4
+ REPO = "arel"
5
+
6
+ require "github-issues"
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github-issues
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Vincent Landgraf
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-12-04 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "2.1"
24
+ type: :development
25
+ version_requirements: *id001
26
+ description: |
27
+ This is a little API that gives easy access to the github issues. It is
28
+ currently a read-only API.
29
+
30
+ email: "vilandgr+github@googlemail.com "
31
+ executables: []
32
+
33
+ extensions: []
34
+
35
+ extra_rdoc_files: []
36
+
37
+ files:
38
+ - Gemfile
39
+ - Gemfile.lock
40
+ - github-issues.gemspec
41
+ - Rakefile
42
+ - README.md
43
+ - lib/github-issues.rb
44
+ - lib/github-issues/comment.rb
45
+ - lib/github-issues/github.rb
46
+ - lib/github-issues/issue.rb
47
+ - lib/github-issues/version.rb
48
+ - spec/comment_spec.rb
49
+ - spec/github_spec.rb
50
+ - spec/issue_spec.rb
51
+ - spec/spec_helper.rb
52
+ homepage: https://github.com/threez/github-issues
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.9
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: An api to githubs issues system
79
+ test_files:
80
+ - spec/comment_spec.rb
81
+ - spec/github_spec.rb
82
+ - spec/issue_spec.rb
83
+ - spec/spec_helper.rb