cinch-github 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/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in cinch-github.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Arthur Chiu
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.
data/README.md ADDED
@@ -0,0 +1,81 @@
1
+ Cinch-Github
2
+ ===========
3
+
4
+ The Cinch Github Plugin. Give your cinch bot abilities to interact with Github! This is still in its early phases!
5
+
6
+ Installation
7
+ ---------------------
8
+
9
+ if you haven't already...
10
+
11
+ $ gem install cinch
12
+
13
+ then install this gem.
14
+
15
+ $ gem install cinch-github
16
+
17
+ Cinch::Plugins::Github
18
+ ----------
19
+
20
+ ### Issues ###
21
+
22
+ This plugin manages interaction between Github issues via the Github API.
23
+
24
+ #### Configuration ####
25
+
26
+ To setup the Issue plugin to work with your cinch bot, we'll need to provide some info like so:
27
+
28
+ Cinch::Github::Issue.configure do |c|
29
+ c.user = 'achiu' # your github username
30
+ c.token = 'some_token' # your github API token
31
+ c.author = 'padrino' # your repository author
32
+ c.repo = 'padrino-framework' # your repository name
33
+ end
34
+
35
+ #### Commands ####
36
+
37
+ * !issue state [open|closed] [query] - returns issues that have state open or closed matching the query
38
+ * !issue find [query] - returns issues matching the query. defaults to state open
39
+ * !issue link [number] - returns issue link for issue number(must be digits)
40
+ * !help github issue - returns commands for Github Issue
41
+
42
+
43
+
44
+ ## Integration with Cinch ##
45
+
46
+ It's simple. follow the guide on cinch or do something like:
47
+
48
+ # mybot.rb
49
+ require 'cinch'
50
+ require 'cinch-github'
51
+
52
+ Cinch::Plugins::Github::Issue.configure do |c|
53
+ c.user = 'achiu' # your github username
54
+ c.token = 'some_token' # your github API token
55
+ c.author = 'padrino' # your repository author
56
+ c.repo = 'padrino-framework' # your repository name
57
+ end
58
+
59
+ bot = Cinch::Bot.new do
60
+ configure do |c|
61
+ c.server = "irc.freenode.net"
62
+ c.nick = "cinch"
63
+ c.channels = ["#padrino"]
64
+ c.plugins.plugins = [Cinch::Plugins::Github::Issue]
65
+ end
66
+
67
+ end
68
+
69
+ bot.start
70
+
71
+ Finally, run your bot.
72
+
73
+ ruby -rubygems mybot.rb
74
+
75
+ And there you go!
76
+
77
+
78
+ TODO
79
+ -----
80
+
81
+ * finish the other plugins for rest of Github API
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/*_test.rb'
8
+ test.verbose = true
9
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "cinch-github/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "cinch-github"
7
+ s.version = Cinch::Plugins::Github::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Arthur Chiu"]
10
+ s.email = ["mr.arthur.chiu@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/cinch-github"
12
+ s.summary = %q{Github Plugin for Cinch}
13
+ s.description = %q{Cinch Plugin to let bots interact with Github}
14
+
15
+ s.rubyforge_project = "cinch-github"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency 'cinch'
23
+ s.add_dependency 'octopi'
24
+ s.add_development_dependency 'riot', '~>0.12.0'
25
+ s.add_development_dependency 'mocha'
26
+ end
@@ -0,0 +1,7 @@
1
+ module Cinch
2
+ module Plugins
3
+ module Github
4
+ autoload :Issue, 'cinch-github/issue'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,69 @@
1
+ require 'octopi'
2
+ require 'cinch'
3
+
4
+ module Cinch
5
+ module Plugins
6
+ module Github
7
+ # Handles interaction with Issues API.
8
+ class Issue
9
+ include Cinch::Plugin
10
+ include Octopi
11
+
12
+ class << self
13
+ attr_accessor :user, :token, :author, :repo
14
+
15
+ def configure(&block)
16
+ yield self
17
+ end
18
+ end
19
+
20
+ match %r{help github issue}, :method => :display_help # !issue help gitub issue
21
+ match %r{issue state (open|closed) (.*)}, :method => :get_ticket # !issue state closed bugs
22
+ match %r{issue find (.*)}, :method => :get_ticket # !issue find sinatra
23
+ match %r{issue link (.*)}, :method => :reply_link # !issue link 35
24
+
25
+ # Display Github Issue Help
26
+ def display_help(m)
27
+ User(m.user.nick).send (<<-EOF).gsub(/^ {10}/,'')
28
+ !issue state [open|closed] [query] - query for a ticket with state closed
29
+ !issue find [query] - query for a ticket with state open
30
+ !issue link [number] - returns link for issue number.
31
+ EOF
32
+ end
33
+
34
+ # Find ticket with gieven
35
+ def get_ticket(m, *args)
36
+ query, state = args.reverse
37
+ results = search_issue CGI.escape(query), state
38
+ output m, results.first.last
39
+ end
40
+
41
+ # Return the link of the issue
42
+ def reply_link(m, arg)
43
+ arg =~ /\D+/ ? m.reply("You need to give me a number...") : m.reply(issue_link(arg))
44
+ end
45
+
46
+ # Use Github API and Search for the Issue
47
+ def search_issue(query, state = 'open')
48
+ authenticated_with :login => self.class.user, :token => self.class.token do
49
+ Octopi::Issue.search :user => self.class.author, :repo => self.class.repo, :state => state, :keyword => query
50
+ end
51
+ end
52
+
53
+ # Returns the issue as a link
54
+ def issue_link(number)
55
+ "https://www.github.com/#{self.class.author}/#{self.class.repo}/issues/#{number}"
56
+ end
57
+
58
+ private
59
+
60
+ # Outputs the reply back to screen
61
+ def output(m, results)
62
+ m.reply "#{results.size} Results"
63
+ results.each { |result| m.reply "#{result['title']} : #{issue_link(result['number'])}" }
64
+ end
65
+
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,7 @@
1
+ module Cinch
2
+ module Plugins
3
+ module Github
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
data/test.watchr ADDED
@@ -0,0 +1,70 @@
1
+ ENV["WATCHR"] = "1"
2
+ system 'clear'
3
+
4
+ def growl(message)
5
+ growlnotify = `which growlnotify`.chomp
6
+ title = "Watchr Test Results"
7
+ image = message.include?('0 failures, 0 errors') ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
8
+ options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
9
+ system %(#{growlnotify} #{options} &)
10
+ end
11
+
12
+ def run(cmd)
13
+ puts(cmd)
14
+ `#{cmd}`
15
+ end
16
+
17
+ def run_test_file(file)
18
+ system('clear')
19
+ result = run(%Q(ruby -I"lib:test" -rubygems #{file}))
20
+ growl result.split("\n").last rescue nil
21
+ puts result
22
+ end
23
+
24
+ def run_all_tests
25
+ system('clear')
26
+ result = run "rake test"
27
+ growl result.split("\n").last rescue nil
28
+ puts result
29
+ end
30
+
31
+ def run_all_features
32
+ system('clear')
33
+ run "cucumber"
34
+ end
35
+
36
+ def related_test_files(path)
37
+ Dir['test/**/*.rb'].select { |file| file =~ /#{File.basename(path).split(".").first}_test.rb/ }
38
+ end
39
+
40
+ def run_suite
41
+ run_all_tests
42
+ # run_all_features
43
+ end
44
+
45
+ watch('test/teststrap\.rb') { run_all_tests }
46
+ watch('test/(.*).*_test\.rb') { |m| run_test_file(m[0]) }
47
+ watch('lib/.*/.*\.rb') { |m| related_test_files(m[0]).map {|tf| run_test_file(tf) } }
48
+ # watch('features/.*/.*\.feature') { run_all_features }
49
+
50
+ # Ctrl-\
51
+ Signal.trap 'QUIT' do
52
+ puts " --- Running all tests ---\n\n"
53
+ run_all_tests
54
+ end
55
+
56
+ @interrupted = false
57
+
58
+ # Ctrl-C
59
+ Signal.trap 'INT' do
60
+ if @interrupted then
61
+ @wants_to_quit = true
62
+ abort("\n")
63
+ else
64
+ puts "Interrupt a second time to quit"
65
+ @interrupted = true
66
+ Kernel.sleep 1.5
67
+ # raise Interrupt, nil # let the run loop catch it
68
+ run_suite
69
+ end
70
+ end
@@ -0,0 +1,113 @@
1
+ require File.expand_path('../teststrap',__FILE__)
2
+
3
+ context "Issue Plugin" do
4
+ helper :issue do
5
+ Cinch::Plugins::Github::Issue.configure do |c|
6
+ c.user = 'achiu'
7
+ c.token = 'my_token'
8
+ c.author = 'achiu'
9
+ c.repo = 'cinch-github'
10
+ end
11
+ Cinch::Plugins::Github::Issue
12
+ end
13
+
14
+ context "#configure" do
15
+ setup { issue }
16
+ asserts(:user).equals 'achiu'
17
+ asserts(:token).equals 'my_token'
18
+ asserts(:author).equals 'achiu'
19
+ asserts(:repo).equals 'cinch-github'
20
+ end
21
+
22
+ context "matches" do
23
+ setup do
24
+ @issue = issue
25
+ mock_match @issue, %r{help github issue}, :display_help
26
+ mock_match @issue, %r{issue state (open|closed) (.*)}, :get_ticket
27
+ mock_match @issue, %r{issue find (.*)}, :get_ticket
28
+ mock_match @issue, %r{issue link (.*)}, :reply_link
29
+ end
30
+ asserts("that it has matches") { @issue.new(Cinch::Bot.new) }
31
+ end
32
+
33
+
34
+ context "#issue_link" do
35
+ setup { issue.new(Cinch::Bot.new) }
36
+ asserts("that returns the correct issue") do
37
+ topic.issue_link(135)
38
+ end.equals 'https://www.github.com/achiu/cinch-github/issues/135'
39
+ end
40
+
41
+ context "#reply_link" do
42
+ setup { @m = mock() }
43
+
44
+ context "with number" do
45
+ setup { @m.expects(:reply).with("https://www.github.com/achiu/cinch-github/issues/1").returns(true) }
46
+ asserts("that it returns link") { issue.new(Cinch::Bot.new).reply_link(@m, '1') }
47
+ end
48
+
49
+ context "not a number" do
50
+ setup { @m.expects(:reply).with("You need to give me a number...").returns(true) }
51
+ asserts("that it returns a message") { issue.new(Cinch::Bot.new).reply_link(@m,'ab1cx2d') }
52
+ end
53
+ end
54
+
55
+ context "#display_help" do
56
+ setup do
57
+ @user = mock() ; @user.expects(:send).with { |value| value =~ /\!issue/ }.returns(true)
58
+ @replier = mock() ; @replier.expects(:nick).returns("bob")
59
+ @message = mock() ; @message.expects(:user).returns(@replier)
60
+ @issue = issue.new(Cinch::Bot.new) ; @issue.expects(:User).with("bob").returns(@user)
61
+ end
62
+ asserts("that it displays message") { @issue.display_help(@message) }
63
+ end
64
+
65
+ context "#get_ticket" do
66
+
67
+ context "with closed state" do
68
+ setup do
69
+ @issue = issue.new(Cinch::Bot.new)
70
+ @message = mock()
71
+ @issue.expects(:search_issue).with('bob','open').returns([[false,true], true])
72
+ @issue.expects(:output).with(@message, true).returns(true)
73
+ end
74
+ asserts("that it searches") { @issue.get_ticket(@message, 'open', 'bob') }
75
+ end
76
+
77
+ context "without state" do
78
+ setup do
79
+ @issue = issue.new(Cinch::Bot.new)
80
+ @message = mock()
81
+ @issue.expects(:search_issue).with('what+bob', nil).returns([[false,true], true])
82
+ @issue.expects(:output).with(@message, true).returns(true)
83
+ end
84
+ asserts("that it searches") { @issue.get_ticket(@message, 'what bob') }
85
+ end
86
+
87
+ end
88
+
89
+ context "#search_issue" do
90
+
91
+ context "with default" do
92
+ setup do
93
+ @issue = issue.new(Cinch::Bot.new)
94
+ @issue.expects(:authenticated_with).with(:login => 'achiu',:token => 'my_token').returns(true)
95
+ params = {:user => 'achiu', :repo => 'cinch-github', :state => 'open', :keyword => 'bob'}
96
+ Octopi::Issue.expects(:search).with(params).returns(true)
97
+ end
98
+ asserts("that it searches with state open") { @issue.search_issue('bob') }
99
+ end
100
+
101
+ context "with state" do
102
+ setup do
103
+ @issue = issue.new(Cinch::Bot.new)
104
+ @issue.expects(:authenticated_with).with(:login => 'achiu', :token => 'my_token').returns(true)
105
+ params = { :user => 'achiu', :repo => 'cinch-github', :state => 'closed', :keyword => 'boo' }
106
+ Octopi::Issue.expects(:search).with(params).returns(true)
107
+ end
108
+ asserts("that it searches with state closed") { @issue.search_issue('bob', 'closed') }
109
+ end
110
+
111
+ end
112
+
113
+ end
data/test/teststrap.rb ADDED
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'riot'
3
+ require 'mocha'
4
+ require File.expand_path('../../lib/cinch-github',__FILE__)
5
+
6
+ class Riot::Situation
7
+ include Mocha::API
8
+
9
+ # Checks to see if plugin has the designated matches
10
+ # asserts_has_match @issue, /help/, :display_help
11
+ def mock_match(plugin, regex, method_name)
12
+ plugin.expects(:match).with(regex, :method => method_name).returns(true)
13
+ end
14
+
15
+
16
+ end
17
+
18
+ class Riot::Context
19
+ end
20
+
21
+ class Object
22
+ def capture(stream)
23
+ begin
24
+ stream = stream.to_s
25
+ eval "$#{stream} = StringIO.new"
26
+ yield
27
+ result = eval("$#{stream}").string
28
+ ensure
29
+ eval("$#{stream} = #{stream.upcase}")
30
+ end
31
+ result
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cinch-github
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Arthur Chiu
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-11-05 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: cinch
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: octopi
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: riot
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ - 12
57
+ - 0
58
+ version: 0.12.0
59
+ type: :development
60
+ version_requirements: *id003
61
+ - !ruby/object:Gem::Dependency
62
+ name: mocha
63
+ prerelease: false
64
+ requirement: &id004 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ type: :development
73
+ version_requirements: *id004
74
+ description: Cinch Plugin to let bots interact with Github
75
+ email:
76
+ - mr.arthur.chiu@gmail.com
77
+ executables: []
78
+
79
+ extensions: []
80
+
81
+ extra_rdoc_files: []
82
+
83
+ files:
84
+ - .gitignore
85
+ - Gemfile
86
+ - LICENSE
87
+ - README.md
88
+ - Rakefile
89
+ - cinch-github.gemspec
90
+ - lib/cinch-github.rb
91
+ - lib/cinch-github/issue.rb
92
+ - lib/cinch-github/version.rb
93
+ - test.watchr
94
+ - test/issue_test.rb
95
+ - test/teststrap.rb
96
+ has_rdoc: true
97
+ homepage: http://rubygems.org/gems/cinch-github
98
+ licenses: []
99
+
100
+ post_install_message:
101
+ rdoc_options: []
102
+
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ segments:
119
+ - 0
120
+ version: "0"
121
+ requirements: []
122
+
123
+ rubyforge_project: cinch-github
124
+ rubygems_version: 1.3.7
125
+ signing_key:
126
+ specification_version: 3
127
+ summary: Github Plugin for Cinch
128
+ test_files:
129
+ - test/issue_test.rb
130
+ - test/teststrap.rb