octospy 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a73c640fd360e1e16615586c052e08e38c88303
4
- data.tar.gz: f7b6ea37bb938458d8222293e2866b252155d689
3
+ metadata.gz: f7923492e57e7a32c5d3c16e4eeeecdecd1888d8
4
+ data.tar.gz: 6b7ed648db808d49a433732875d47a3478419976
5
5
  SHA512:
6
- metadata.gz: 7fc62aa57019b25d910d998669a21ac23fdbaf745eec989ff167d2f68fa81639a86986081403760a3adfb5668fab17be10c36c1734e62f35048930983bbe115c
7
- data.tar.gz: b23ca9be2d3ce6ca52a2eea1e41fe9a1cd6d64e250b1db8218ef92d081da66140a1cd07a3efb2cf51294d84cce04060c302af97ce49721b84abc191419ea9570
6
+ metadata.gz: c811098f2c8a11f3f04246cede91a5e2dc14383a17b8834ce92a967d1c7c0a3c226e0b83cfca48b029f0a2b027684ed3f5b9a10e3caab7533eb02b690542d54c
7
+ data.tar.gz: 031ff920915e73b8053690b94d0ef02bc3c3d8ab42d907cb688d4b16b117405a907b8e689e2df60813bde9e0a1ec5e78f381651ce77418de3073f8639abcc6c4
@@ -1,21 +1,12 @@
1
1
  language: ruby
2
-
3
2
  rvm:
4
- - 1.9.3
5
3
  - 2.0.0
6
-
4
+ - 2.1.1
7
5
  before_install:
8
6
  - gem update bundler
9
-
10
7
  script:
11
- - bundle exec rake spec
12
-
8
+ - bundle exec rspec
13
9
  notifications:
14
- email:
15
- recipients:
16
- - linyows@gmail.com
17
- on_success: change
18
- on_failure: always
19
10
  irc:
20
11
  on_success: change
21
12
  on_failure: always
data/README.md CHANGED
@@ -13,7 +13,7 @@ Octospy
13
13
  [codeclimate]: https://codeclimate.com/github/linyows/octospy
14
14
  [coveralls]: https://coveralls.io/r/linyows/octospy
15
15
 
16
- Octospy notifies eventsf github repositories to IRC channels.
16
+ Octospy notifies events of github repositories to IRC channels.
17
17
 
18
18
  <div align="center">
19
19
  <img src="http://octodex.github.com/images/daftpunktocat-thomas.gif" width="300">
@@ -77,6 +77,12 @@ GITHUB_WEB_ENDPOINT=http://your.enterprise.domain
77
77
  env DOTENV=".env.myserver" octospy
78
78
  ```
79
79
 
80
+ ### Debug
81
+
82
+ ```sh
83
+ env DEBUG=true octospy
84
+ ```
85
+
80
86
  Commands
81
87
  --------
82
88
 
@@ -87,12 +93,14 @@ Command | Description
87
93
  `watch <repository>` | add repository to watch list (ex: watch rails/rails)
88
94
  `unwatch <repository>` | remove repository to watch list
89
95
  `watch <user or organization>` | add user's repositories to watch list (ex: watch dotcloud)
90
- `unwatch <user or organization>` | remove user's repositories to watch list
96
+ `unwatch <user or organization>` | remove user's repositories from watch list
97
+ `clear watched` | remove all repositories from watch list
91
98
  `start` | start the repository event monitoring
92
99
  `stop` | stop the repository event monitoring
93
100
  `join <channel>` | invite octospy to another channel
94
101
  `show watched` | display the watch list
95
102
  `show status` | display the joined channels
103
+ `help` | display the commands
96
104
 
97
105
  Contributing
98
106
  ------------
@@ -8,7 +8,7 @@ module Cinch
8
8
  include Octospy::Recording
9
9
  include Octospy::Job
10
10
 
11
- set :prefix, ->(m) { %r(^#{Regexp.escape "#{m.bot.nick}: "}) }
11
+ set :prefix, ->(m) { %r(^ ?#{Regexp.escape "#{m.bot.nick}"}:? ) }
12
12
 
13
13
  match(/hello|hi|hey/, method: :greet)
14
14
  match('ping', method: :pong)
@@ -16,7 +16,7 @@ module Cinch
16
16
  match(/join (.+)/, method: :join)
17
17
  match(/part(?: (.+))?/, method: :part)
18
18
  match(/show status/, method: :show_status)
19
- match(/show commands/, method: :show_commands)
19
+ match(/show commands|help/, method: :show_commands)
20
20
 
21
21
  listen_to :invite, method: :join_on_invite
22
22
 
@@ -50,14 +50,20 @@ module Cinch
50
50
  def show_status(m)
51
51
  @bot.channels.each.with_index(1) do |channel, i|
52
52
  number = ::Octospy::Recordable.channel(channel).repos.count
53
- m.reply "#{"%02d" % i} #{channel}: #{number} repo"
53
+ m.reply "#{"%02d" % i} #{channel}: #{number} repo#{'s' unless number.zero?}"
54
54
  end
55
55
  end
56
56
 
57
57
  def show_commands(m)
58
- # @matchers.each.with_index(1) do |matcher, i|
59
- # m.reply "#{"%02d" % i} #{matcher}"
60
- # end
58
+ m.reply "#{m.bot.name}:"
59
+ @handlers.each do |handler|
60
+ pattern = handler.pattern.pattern
61
+ command = case pattern.class.name
62
+ when 'Regexp' then pattern.source unless pattern.source == ''
63
+ when 'String' then pattern unless pattern.empty?
64
+ end
65
+ m.reply " #{command}" if command
66
+ end
61
67
  end
62
68
 
63
69
  def join_on_invite(m)
@@ -8,6 +8,7 @@ module Cinch
8
8
  match(/unwatch ([\w\-\.]+)\/([\w\-\.]+)$/, method: :unwatch_repository)
9
9
  match(/watch ([\w\-\.]+)$/, method: :watch_repositories)
10
10
  match(/unwatch ([\w\-\.]+)$/, method: :unwatch_repositories)
11
+ match(/clear watched( repos(itories)?)?/, method: :clear_watched_repositories)
11
12
  match(/show watched( repos(itories)?)?/, method: :show_watched_repositories)
12
13
  end
13
14
  end
@@ -37,11 +38,12 @@ module Cinch
37
38
 
38
39
  ::Octospy::Recordable.add_channel m.channel.name
39
40
  method = "#{'org_' if user.type == 'Organization'}repos".to_sym
40
- repos = ::Octokit.send(method, owner).map { |repo|
41
- ::Octospy::Recordable.channel(m.channel.name).add_repo(repo.full_name)
41
+ repos = ::Octokit.send(method, owner, per_page: 100).map { |repo|
42
42
  repo.full_name
43
43
  }
44
44
 
45
+ ::Octospy::Recordable.channel(m.channel.name).add_repos(repos)
46
+
45
47
  if repos.count > 0
46
48
  m.reply "started to watch events of #{repos.count} repositories"
47
49
  restart(m)
@@ -64,11 +66,11 @@ module Cinch
64
66
 
65
67
  def unwatch_repositories(m, owner)
66
68
  repos = ::Octospy::Recordable.channel(m.channel.name).repos.each_with_object([]) do |repo, obj|
67
- next unless repo.split('/').first == owner
68
- ::Octospy::Recordable.channel(m.channel.name).remove_repo(repo)
69
- opj << repo
69
+ obj << repo if repo.to_s.split('/').first == owner
70
70
  end
71
71
 
72
+ ::Octospy::Recordable.channel(m.channel.name).remove_repos(repos)
73
+
72
74
  if repos.count > 0
73
75
  if ::Octospy::Recordable.channel(m.channel.name).repos.count > 0
74
76
  m.reply "stopped to watch events of #{repos.count} repositories"
@@ -80,8 +82,9 @@ module Cinch
80
82
  end
81
83
  end
82
84
 
83
- def unwatch_all(m)
85
+ def clear_watched_repositories(m)
84
86
  ::Octospy::Recordable.remove_channel(m.channel.name)
87
+ m.reply 'cleared'
85
88
  end
86
89
 
87
90
  def show_watched_repositories(m)
@@ -7,6 +7,7 @@ module Octospy
7
7
  ssl
8
8
  password
9
9
  nick
10
+ debug
10
11
  worker_interval
11
12
  api_request_interval
12
13
  cinch_config_block
@@ -45,6 +46,7 @@ module Octospy
45
46
  @server = ENV['SERVER']
46
47
  @port = ENV['PORT']
47
48
  @ssl = !!ENV['SSL']
49
+ @debug = !!ENV['DEBUG']
48
50
  @password = ENV['PASSWORD']
49
51
  @worker_interval = ENV['WORKER_INTERVAL'] ? ENV['WORKER_INTERVAL'].to_i : 30 #sec
50
52
  # you can make up to 20 requests per minute.
@@ -17,6 +17,10 @@ module Octospy
17
17
  end
18
18
  alias_method :split_lfbl, :split_by_linefeed_except_blankline
19
19
 
20
+ def compact
21
+ self.gsub(/\s+/, ' ').strip
22
+ end
23
+
20
24
  def colorize_for_irc
21
25
  StringIrc.new(self)
22
26
  end
@@ -27,7 +27,8 @@ module Octospy
27
27
  if channels_include? name
28
28
  find_channel name
29
29
  else
30
- Channel.new(name)
30
+ add_channel name
31
+ find_channel name
31
32
  end
32
33
  end
33
34
  end
@@ -12,11 +12,22 @@ module Octospy
12
12
  end
13
13
 
14
14
  def add_repo(name)
15
- @repos << name if repos.empty? || !repos.include?(name)
15
+ repos << name.to_sym if !repos.include?(name.to_sym)
16
+ end
17
+
18
+ def add_repos(names = nil)
19
+ return if names.nil? || names.empty?
20
+ repos.concat(names.map { |repo|
21
+ repo.to_sym unless repos.include?(repo.to_sym) }.compact)
16
22
  end
17
23
 
18
24
  def remove_repo(name)
19
- @repos.delete(name.to_sym) if !repos.empty? && repos.include?(name)
25
+ repos.delete(name.to_sym) if repos.include?(name.to_sym)
26
+ end
27
+
28
+ def remove_repos(names = nil)
29
+ return if names.nil? || names.empty?
30
+ repos.delete_if { |repo| names.include? repo.to_s }
20
31
  end
21
32
  end
22
33
  end
@@ -1,3 +1,3 @@
1
1
  module Octospy
2
- VERSION = '0.0.8'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -9,52 +9,133 @@ module Octospy
9
9
  thread_loop
10
10
  end
11
11
 
12
+ def work_interval
13
+ (Octospy.api_request_interval * @repositories.count) + Octospy.worker_interval
14
+ end
15
+
12
16
  def thread_loop
13
- @thread = Thread.start do
14
- loop do
15
- begin
16
- watch_repositories
17
- sleep Octospy.worker_interval
18
- rescue => e
19
- @block.call "Octospy Error: #{e.message}"
20
- sleep Octospy.worker_interval
21
- end
22
- end
17
+ debug 'thread_start', <<-MSG.compact
18
+ api_request_interval(A): #{Octospy.api_request_interval},
19
+ repoisitory_count(R): #{@repositories.count},
20
+ worker_interval(W): #{Octospy.worker_interval},
21
+ work_interval(A*R+W): #{work_interval}
22
+ MSG
23
+
24
+ @thread = Thread.start { loop { work } }
25
+ end
26
+
27
+ def work
28
+ notify_recent_envets
29
+ debug 'sleep', work_interval
30
+ sleep work_interval
31
+ rescue => e
32
+ error e.message
33
+ debug 'sleep', work_interval
34
+ sleep worker_interval
35
+ end
36
+
37
+ def api_requestable?
38
+ limit = Octokit.rate_limit
39
+ if limit.remaining.zero?
40
+ notify "ヾ(;´Д`)ノ #{limit}"
41
+ false
42
+ else
43
+ true
23
44
  end
45
+ # No rate limit for white listed users
46
+ rescue Octokit::NotFound
47
+ true
24
48
  end
25
49
 
26
- def events
50
+ def repository_events
27
51
  @repositories.each_with_object([]) do |repo, arr|
28
- if Octokit.rate_limit.remaining.zero?
29
- @block.call "ヾ(;´Д`)ノ #{::Octokit.rate_limit}"
30
- break
31
- end
52
+ break unless api_requestable?
32
53
 
33
54
  sleep Octospy.api_request_interval
34
- arr.concat ::Octokit.repository_events(repo)
55
+ events = ::Octokit.repository_events(repo.to_s)
56
+ arr.concat events
57
+
58
+ debug_attrs = <<-MSG.compact
59
+ repo: #{repo},
60
+ limit: #{Octokit.rate_limit.remaining}/#{Octokit.rate_limit.limit},
61
+ reset: #{Octokit.rate_limit.resets_at.strftime('%H:%M:%S')} *after #{Octokit.rate_limit.resets_in}sec,
62
+ MSG
63
+
64
+ if !events.nil? && !events.empty?
65
+ debug_attrs << ' ' + <<-MSG.compact
66
+ first: #{events.first.type},
67
+ last: #{events.last.type}
68
+ MSG
69
+ end
70
+
71
+ debug 'get_event', debug_attrs
35
72
  end
36
73
  end
37
74
 
38
- def while_ago
39
- Time.now.utc - (60 * 30)
75
+ def skipping?(event)
76
+ case
77
+ when event.nil?,
78
+ @last_event_id.nil? && while_ago >= event.created_at,
79
+ !@last_event_id.nil? && @last_event_id >= event.id.to_i
80
+ true
81
+ else
82
+ false
83
+ end
40
84
  end
41
85
 
42
- def watch_repositories
86
+ def notify_recent_envets
87
+ events = repository_events
88
+ return if events.count.zero?
89
+
90
+ last_event = events.sort_by(&:id).last
91
+ debug 'last_event', <<-MSG.compact
92
+ repo: #{last_event.repo.name},
93
+ event_type: #{last_event.type},
94
+ #{@last_event_id.nil? ?
95
+ "while_ago: #{while_ago}, created_at: #{last_event.created_at}" :
96
+ "last_id: #{@last_event_id}, current_id: #{last_event.id}"}
97
+ MSG
98
+
43
99
  # ascending by event.id
44
100
  events.sort_by(&:id).each { |event|
45
- case
46
- when @last_event_id.nil? && while_ago >= event.created_at
47
- next
48
- when !@last_event_id.nil? && @last_event_id >= event.id.to_i
49
- next
50
- end
101
+ next if skipping?(event)
51
102
 
52
103
  parsed_event = Octospy.parse(event)
53
- next unless parsed_event
104
+
105
+ unless parsed_event
106
+ debug 'could_not_parse', <<-MSG.compact
107
+ repo: #{event.repo.name},
108
+ event: #{event.type}
109
+ MSG
110
+ next
111
+ end
54
112
 
55
113
  @last_event_id = event.id.to_i
56
- parsed_event.each { |p| @block.call p[:message] }
114
+ parsed_event.each { |p| notify p[:message] }
57
115
  }
58
116
  end
117
+
118
+ private
119
+
120
+ def while_ago
121
+ Time.now.utc - (60 * 30)
122
+ end
123
+
124
+ def notify(message)
125
+ @block.call message
126
+ end
127
+
128
+ def debug(name, message = nil)
129
+ return unless Octospy.debug
130
+
131
+ prefix = '[DEBUG]'.colorize_for_irc.orange
132
+ info = name.colorize_for_irc.bold
133
+ @block.call "#{prefix} #{info} #{message}"
134
+ end
135
+
136
+ def error(message)
137
+ prefix = '[ERROR]'.colorize_for_irc.red
138
+ @block.call "#{prefix} #{message}"
139
+ end
59
140
  end
60
141
  end
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Octospy::VERSION
9
9
  spec.authors = ['linyows']
10
10
  spec.email = ['linyows@gmail.com']
11
- spec.description = %q{Octospy notifies eventsf github repositories to IRC channels.}
12
- spec.summary = %q{Octospy notifies eventsf github repositories to IRC channels.}
11
+ spec.description = %q{Octospy notifies events of github repositories to IRC channels.}
12
+ spec.summary = %q{Octospy notifies events of github repositories to IRC channels.}
13
13
  spec.homepage = 'https://github.com/linyows/octospy'
14
14
  spec.license = 'MIT'
15
15
 
@@ -4,11 +4,9 @@ require 'simplecov'
4
4
  require 'coveralls'
5
5
  require 'octospy'
6
6
  require 'rspec'
7
- require 'json'
8
- require 'hashie'
9
- require 'awesome_print'
10
- require 'webmock/rspec'
7
+ require 'ap'
11
8
  require 'vcr'
9
+ require 'webmock/rspec'
12
10
 
13
11
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
14
12
  SimpleCov::Formatter::HTMLFormatter,
@@ -20,8 +18,15 @@ WebMock.disable_net_connect!(allow: 'coveralls.io')
20
18
  RSpec.configure { |c| c.include WebMock::API }
21
19
 
22
20
  VCR.configure do |c|
21
+ c.configure_rspec_metadata!
23
22
  c.cassette_library_dir = 'spec/cassettes'
24
23
  c.hook_into :webmock
24
+ c.default_cassette_options = {
25
+ serialize_with: :json,
26
+ preserve_exact_body_bytes: true,
27
+ decode_compressed_response: true,
28
+ record: :once
29
+ }
25
30
  end
26
31
 
27
32
  class String
@@ -71,9 +76,3 @@ def method_missing(method, *args, &block)
71
76
  super
72
77
  end
73
78
  end
74
-
75
- def support_path
76
- File.expand_path('../support', __FILE__)
77
- end
78
-
79
- Dir["#{support_path}/**/*.rb"].each { |f| require f }
@@ -24,7 +24,6 @@ describe Octospy::Extensions::String do
24
24
  }
25
25
 
26
26
  it { expect(subject).to be_instance_of Array }
27
- it { expect(subject).to have(4).items }
28
27
  it { expect(subject[1]).to include 'Blue sky' }
29
28
  end
30
29
 
@@ -32,18 +31,13 @@ describe Octospy::Extensions::String do
32
31
  let(:sentence) { 'hi, hello world.' }
33
32
 
34
33
  it { expect(subject).to be_instance_of Array }
35
- it { expect(subject).to have(1).items }
36
- end
37
-
38
- it 'have alias_method' do
39
- expect(''.respond_to? :split_lfbl).to be_true
40
34
  end
41
35
  end
42
36
 
43
37
  describe '#colorize_for_irc' do
44
38
  let(:word) { 'hello world' }
45
39
 
46
- it 'call StringIrc#new' do
40
+ it 'calls StringIrc#new' do
47
41
  expect(StringIrc).to receive(:new).with(word).once.and_call_original
48
42
  expect(word.colorize_for_irc).to be_instance_of StringIrc
49
43
  end
@@ -54,8 +48,8 @@ describe Octospy::Extensions::String do
54
48
  let(:url) { 'https://github.com/linyows/octospy' }
55
49
  let(:result) { 'http://git.io/aaaaa' }
56
50
 
57
- it 'call Octospy::Shortener.shorten_by_github' do
58
- expect(Octospy::Shortener).to receive(:shorten_by_github).and_return result
51
+ it 'calls Octospy::Url.shorten_by_github' do
52
+ expect(Octospy::Url).to receive(:shorten_by_github).and_return result
59
53
  expect(url.shorten_url).to eq result
60
54
  end
61
55
  end
@@ -64,8 +58,8 @@ describe Octospy::Extensions::String do
64
58
  let(:url) { 'http://www.google.com/search?q=octospy' }
65
59
  let(:result) { 'http://goo.gl/aaaaa' }
66
60
 
67
- it 'call Octospy::Shortener.shorten_by_google' do
68
- expect(Octospy::Shortener).to receive(:shorten_by_google).and_return result
61
+ it 'calls Octospy::Url.shorten_by_google' do
62
+ expect(Octospy::Url).to receive(:shorten_by_google).and_return result
69
63
  expect(url.shorten_url).to eq result
70
64
  end
71
65
  end
@@ -74,9 +68,9 @@ describe Octospy::Extensions::String do
74
68
  let(:url) { 'hello world' }
75
69
  let(:result) { url }
76
70
 
77
- it 'not call Octospy::Shortener' do
78
- expect(Octospy::Shortener).to_not receive(:shorten_by_github)
79
- expect(Octospy::Shortener).to_not receive(:shorten_by_google)
71
+ it 'not calls Octospy::Url' do
72
+ expect(Octospy::Url).to_not receive(:shorten_by_github)
73
+ expect(Octospy::Url).to_not receive(:shorten_by_google)
80
74
  expect(url.shorten_url).to eq result
81
75
  end
82
76
  end
@@ -1,9 +1,6 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Octospy::Parser do
4
- include_context :parser_params
5
-
6
4
  describe '#parse_download_event' do
7
- it {}
8
5
  end
9
6
  end
@@ -1,17 +1,6 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Octospy::Parser do
4
- include_context :parser_params
5
-
6
4
  describe '#parse_gist_event' do
7
- let(:event_name) { 'gist_event' }
8
- before { parser.instance_variable_set(:@event, event) }
9
-
10
- subject { parser.parse_gist_event }
11
-
12
- it { expect(subject[:status]).to eq 'created gist' }
13
- it { expect(subject[:title]).to eq 'testing activegist' }
14
- it { expect(subject[:body]).to be_nil }
15
- it { expect(subject[:link]).to eq 'https://gist.github.com/5993603' }
16
5
  end
17
6
  end
@@ -1,33 +1,9 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Octospy::Parser do
4
- include_context :parser_params
5
-
6
4
  describe '#parse_issues_event' do
7
- let(:event_name) { 'issues_event' }
8
- before { parser.instance_variable_set(:@event, event) }
9
-
10
- subject { parser.parse_issues_event }
11
-
12
- it { expect(subject[:status]).to eq 'opened issue #430' }
13
- it { expect(subject[:title]).to eq 'mismatching hashes for css' }
14
- it { expect(subject[:body]).to be_an_instance_of Array }
15
- it { expect(subject[:body]).to include 'Server: nginx/1.4.1' }
16
- it { expect(subject[:body]).to have(40).items }
17
- it { expect(subject[:link]).to eq 'https://github.com/pagespeed/ngx_pagespeed/issues/430' }
18
5
  end
19
6
 
20
7
  describe '#parse_issue_comment_event' do
21
- let(:event_name) { 'issue_comment_event' }
22
- before { parser.instance_variable_set(:@event, event) }
23
-
24
- subject { parser.parse_issue_comment_event }
25
-
26
- it { expect(subject[:status]).to eq 'commented on issue #582' }
27
- it { expect(subject[:title]).to eq 'Remove `engines` from package.json.' }
28
- it { expect(subject[:body]).to be_an_instance_of Array }
29
- it { expect(subject[:body][0]).to include 'anything?' }
30
- it { expect(subject[:body]).to have(1).items }
31
- it { expect(subject[:link]).to eq 'https://github.com/bower/bower/issues/582#issuecomment-20416296' }
32
8
  end
33
9
  end
@@ -1,33 +1,9 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Octospy::Parser do
4
- include_context :parser_params
5
-
6
4
  describe '#parse_team_add_event' do
7
- let(:event_name) { 'team_add_event' }
8
- before { parser.instance_variable_set(:@event, event) }
9
-
10
- subject { parser.parse_team_add_event }
11
-
12
- it { expect(subject[:status]).to eq 'add team' }
13
- it { expect(subject[:title]).to eq 'dev' }
14
- it { expect(subject[:body]).to be_nil }
15
- it { expect(subject[:link]).to be_nil }
16
5
  end
17
6
 
18
7
  describe '#parse_member_event' do
19
- let(:event_name) { 'member_event' }
20
-
21
- before do
22
- client.stub(:web_endpoint).and_return Octokit.web_endpoint
23
- parser.instance_variable_set(:@event, event)
24
- end
25
-
26
- subject { parser.parse_member_event }
27
-
28
- it { expect(subject[:status]).to eq 'added member' }
29
- it { expect(subject[:title]).to eq 'jamiesarahg' }
30
- it { expect(subject[:body]).to be_nil }
31
- it { expect(subject[:link]).to eq 'https://github.com//jamiesarahg' }
32
8
  end
33
9
  end
@@ -1,33 +1,9 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Octospy::Parser do
4
- include_context :parser_params
5
-
6
4
  describe '#parse_pull_request_event' do
7
- let(:event_name) { 'pull_request_event' }
8
- before { parser.instance_variable_set(:@event, event) }
9
-
10
- subject { parser.parse_pull_request_event }
11
-
12
- it { expect(subject[:status]).to eq 'closed pull request #11363' }
13
- it { expect(subject[:title]).to eq 'Fix 2 grammatical errors/typos in Active Record Basics guide.' }
14
- it { expect(subject[:body]).to eq [] }
15
- it { expect(subject[:link]).to eq 'https://github.com/rails/rails/pull/11363' }
16
5
  end
17
6
 
18
7
  describe '#parse_pull_request_review_comment_event' do
19
- let(:pull) { double(Octokit::Client, title: 'Mocking title') }
20
- let(:client) { double(Octokit::Client, pull: pull) }
21
- let(:event_name) { 'pull_request_review_comment_event' }
22
- before { parser.instance_variable_set(:@event, event) }
23
-
24
- subject { parser.parse_pull_request_review_comment_event }
25
-
26
- it { expect(subject[:status]).to eq 'commented on pull request' }
27
- it { expect(subject[:title]).to eq 'Mocking title: packages/ember-handlebars/lib/helpers/collection.js' }
28
- it { expect(subject[:body]).to be_an_instance_of Array }
29
- it { expect(subject[:body][0]).to include 'Of course.' }
30
- it { expect(subject[:body]).to have(1).items }
31
- it { expect(subject[:link]).to eq 'https://github.com/emberjs/ember.js/pull/2930#discussion_r5064430' }
32
8
  end
33
9
  end
@@ -1,101 +1,24 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Octospy::Parser do
4
- include_context :parser_params
5
-
6
4
  describe '#parse_push_event' do
7
- let(:shorten_url) { 'http://git.io/Qq_ufw' }
8
- let(:client) {
9
- client = double(Octokit::Client)
10
- client.stub_chain(:commit, :author, :login).and_return('mockingname')
11
- client.stub(:web_endpoint).and_return(Octokit.web_endpoint)
12
- String.any_instance.stub(:shorten).and_return shorten_url
13
- client
14
- }
15
- let(:event_name) { 'push_event' }
16
-
17
- before { parser.instance_variable_set(:@event, event) }
18
-
19
- subject { parser.parse_push_event }
20
-
21
- it { expect(subject[:status]).to eq 'pushed to master' }
22
- it { expect(subject[:title]).to be_nil }
23
- it { expect(subject[:body]).to be_an_instance_of Array }
24
- it {
25
- expect(subject[:body][0]).to eq <<-BODY.pretty_heredoc
26
- \u000315mockingname\u000F:
27
- update send and connect - \u000302#{shorten_url}\u000F
28
- BODY
29
- }
30
- it { expect(subject[:body]).to have(2).items }
31
- it { expect(subject[:link]).to eq 'https://github.com//visionmedia/express' }
32
5
  end
33
6
 
34
7
  describe '#parse_create_event' do
35
- let(:client) { double(Octokit::Client, web_endpoint: Octokit.web_endpoint) }
36
- let(:event_name) { 'create_event' }
37
- before { parser.instance_variable_set(:@event, event) }
38
-
39
- subject { parser.parse_create_event }
40
-
41
- it { expect(subject[:status]).to eq 'created tag:3.3.3' }
42
- it {
43
- expect(subject[:title]).to eq <<-TITLE.pretty_heredoc
44
- Sinatra inspired web development framework for node.js -- insanely fast,
45
- flexible, and simple
46
- TITLE
47
- }
48
- it { expect(subject[:body]).to be_nil }
49
- it { expect(subject[:link]).to eq 'https://github.com//visionmedia/express' }
50
8
  end
51
9
 
52
10
  describe '#parse_commit_comment_event' do
53
- let(:event_name) { 'commit_comment_event' }
54
- before { parser.instance_variable_set(:@event, event) }
55
-
56
- subject { parser.parse_commit_comment_event }
57
-
58
- it { expect(subject[:status]).to eq 'commented on commit' }
59
- it { expect(subject[:title]).to eq '' }
60
- it { expect(subject[:body]).to be_an_instance_of Array }
61
- it { expect(subject[:body][0]).to include 'AFAIK' }
62
- it { expect(subject[:body]).to have(1).items }
63
- it { expect(subject[:link]).to eq 'https://github.com/boxen/our-boxen/commit/08009e9b0718869d269d9b1c48383e6e145950db#commitcomment-3583654' }
64
11
  end
65
12
 
66
13
  describe '#parse_delete_event' do
67
- let(:client) { double(Octokit::Client, web_endpoint: Octokit.web_endpoint) }
68
- let(:event_name) { 'delete_event' }
69
- before { parser.instance_variable_set(:@event, event) }
70
-
71
- subject { parser.parse_delete_event }
72
-
73
- it { expect(subject[:status]).to eq 'deleted branch:jefftk-fix-beacon' }
74
- it { expect(subject[:title]).to be_nil }
75
- it { expect(subject[:body]).to be_nil }
76
- it { expect(subject[:link]).to eq 'https://github.com//pagespeed/ngx_pagespeed' }
77
14
  end
78
15
 
79
16
  describe '#parse_fork_event' do
80
17
  end
81
18
 
82
19
  describe '#parse_fork_apply_event' do
83
- it { expect(parser.parse_fork_apply_event).to eq({}) }
84
20
  end
85
21
 
86
22
  describe '#parse_public_event' do
87
- let(:event_name) { 'public_event' }
88
-
89
- before do
90
- client.stub(:web_endpoint).and_return Octokit.web_endpoint
91
- parser.instance_variable_set(:@event, event)
92
- end
93
-
94
- subject { parser.parse_public_event }
95
-
96
- it { expect(subject[:status]).to eq 'published JustinBeaudry/brudniakbook' }
97
- it { expect(subject[:title]).to be_nil }
98
- it { expect(subject[:body]).to be_nil }
99
- it { expect(subject[:link]).to eq 'https://github.com//JustinBeaudry/brudniakbook' }
100
23
  end
101
24
  end
@@ -1,44 +1,9 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Octospy::Parser do
4
- include_context :parser_params
5
-
6
4
  describe '#parse_watch_event' do
7
- let(:client) { double(Octokit::Client, web_endpoint: Octokit.web_endpoint) }
8
- let(:event_name) { 'watch_event' }
9
- before { parser.instance_variable_set(:@event, event) }
10
-
11
- subject { parser.parse_watch_event }
12
-
13
- it { expect(subject[:status]).to eq 'started repository' }
14
- it { expect(subject[:title]).to eq 'intridea/hashie' }
15
- it { expect(subject[:body]).to be_nil }
16
- it { expect(subject[:link]).to eq 'https://github.com//intridea/hashie' }
17
- it { expect(subject[:repository]).to be_nil }
18
5
  end
19
6
 
20
7
  describe '#parse_follow_event' do
21
- let(:client) { double(Octokit::Client, web_endpoint: Octokit.web_endpoint) }
22
- let(:event_name) { 'follow_event' }
23
- before { parser.instance_variable_set(:@event, event) }
24
-
25
- subject { parser.parse_follow_event }
26
-
27
- it { expect(subject[:status]).to eq 'followed' }
28
- it { expect(subject[:title]).to eq 'Watson1978 (Watson)' }
29
- it {
30
- expect(subject[:body]).to eq <<-BODY.pretty_heredoc
31
- \u000315repos\u000F: 66,
32
- \u000315followers\u000F: 101,
33
- \u000315following\u000F: 15,
34
- \u000315location\u000F: Japan,
35
- \u000315company\u000F: -,
36
- \u000315bio\u000F: -,
37
- \u000315blog\u000F: http://watson1978.github.io/
38
- BODY
39
- }
40
- it { expect(subject[:link]).to eq 'https://github.com//Watson1978' }
41
- it { expect(subject[:repository]).to be_nil }
42
- it { expect(subject[:notice]).to be_true }
43
8
  end
44
9
  end
@@ -1,17 +1,6 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Octospy::Parser do
4
- include_context :parser_params
5
-
6
4
  describe '#parse_gollum_event' do
7
- let(:event_name) { 'gollum_event' }
8
- before { parser.instance_variable_set(:@event, event) }
9
-
10
- subject { parser.parse_gollum_event }
11
-
12
- it { expect(subject[:status]).to eq 'edited the component/component wiki' }
13
- it { expect(subject[:title]).to eq 'Components' }
14
- it { expect(subject[:body]).to be_nil }
15
- it { expect(subject[:link]).to eq 'https://github.com/component/component/wiki/Components/_compare/3df147%5E...3df147' }
16
5
  end
17
6
  end
@@ -1,63 +1,21 @@
1
1
  require 'helper'
2
2
 
3
3
  describe Octospy::Parser do
4
- include_context :parser_params
5
-
6
4
  describe '#initialize' do
7
- it { expect(parser).to be_an_instance_of Octospy::Parser }
8
5
  end
9
6
 
10
7
  describe '#default_params' do
11
- it { expect(parser.default_params).to eq default_params }
12
8
  end
13
9
 
14
10
  describe '#parse' do
15
- it {
16
- expect(parser).to receive(:parsing_method).once.and_return(parsing_method)
17
- expect(parser).to receive(parsing_method).once.and_return(parsed_params)
18
- expect(parser).to receive(:build).once.with(merged_params).and_return(built_params)
19
- expect(parser.parse event).to eq built_params
20
- }
21
11
  end
22
12
 
23
13
  describe '#build' do
24
- it {
25
- expect_any_instance_of(String).to receive(:shorten).once.and_return('http://git.io/A0ARbg')
26
- expect(parser.build merged_params).to eq built_params
27
- }
28
14
  end
29
15
 
30
16
  describe '#parsing_method' do
31
- let(:event) { double(Octokit::Client, type: 'FooBarBaz') }
32
- before { parser.instance_variable_set(:@event, event) }
33
- it { expect(parser.parsing_method).to eq :parse_foo_bar_baz }
34
- end
35
-
36
- describe '#behavior_color' do
37
- {
38
- pink: 'created',
39
- yellow: 'commented',
40
- lime: 'pushed',
41
- orange: 'forked',
42
- brown: 'closed',
43
- red: 'deleted',
44
- green: 'edited',
45
- blue: 'published',
46
- rainbow: 'started',
47
- seven_eleven: 'followed',
48
- aqua: 'foobar'
49
- }.each { |color, word|
50
- it { expect(parser.behavior_color word).to eq color }
51
- }
52
17
  end
53
18
 
54
19
  describe '#colorize_to' do
55
- let(:sentence) { 'created issue' }
56
-
57
- it {
58
- expect_any_instance_of(StringIrc).to receive(:pink).
59
- once.with(no_args).and_call_original
60
- expect(parser.colorize_to sentence).to eq "\u000313#{sentence}\u000F"
61
- }
62
20
  end
63
21
  end
@@ -0,0 +1,19 @@
1
+ require 'helper'
2
+
3
+ describe Octospy::Url do
4
+ let(:url) { 'https://github.com/linyows/octospy' }
5
+
6
+ describe '.shorten_by_github', :vcr do
7
+ subject { described_class.shorten_by_github url }
8
+
9
+ it { expect(subject).to be_an_instance_of String }
10
+ it { expect(subject).to eq 'http://git.io/Pd8gXg' }
11
+ end
12
+
13
+ describe '.shorten_by_google', :vcr do
14
+ subject { described_class.shorten_by_google url }
15
+
16
+ it { expect(subject).to be_an_instance_of String }
17
+ it { expect(subject).to eq 'http://goo.gl/8vrLj' }
18
+ end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: octospy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - linyows
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-01 00:00:00.000000000 Z
11
+ date: 2014-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,7 +108,7 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0.10'
111
- description: Octospy notifies eventsf github repositories to IRC channels.
111
+ description: Octospy notifies events of github repositories to IRC channels.
112
112
  email:
113
113
  - linyows@gmail.com
114
114
  executables:
@@ -176,8 +176,7 @@ files:
176
176
  - spec/octospy/parser/user_spec.rb
177
177
  - spec/octospy/parser/wiki_spec.rb
178
178
  - spec/octospy/parser_spec.rb
179
- - spec/octospy/shortener_spec.rb
180
- - spec/support/shared_context.rb
179
+ - spec/octospy/url_spec.rb
181
180
  homepage: https://github.com/linyows/octospy
182
181
  licenses:
183
182
  - MIT
@@ -201,7 +200,7 @@ rubyforge_project:
201
200
  rubygems_version: 2.2.2
202
201
  signing_key:
203
202
  specification_version: 4
204
- summary: Octospy notifies eventsf github repositories to IRC channels.
203
+ summary: Octospy notifies events of github repositories to IRC channels.
205
204
  test_files:
206
205
  - spec/fixtures/commit_comment_event.json
207
206
  - spec/fixtures/create_event.json
@@ -230,5 +229,4 @@ test_files:
230
229
  - spec/octospy/parser/user_spec.rb
231
230
  - spec/octospy/parser/wiki_spec.rb
232
231
  - spec/octospy/parser_spec.rb
233
- - spec/octospy/shortener_spec.rb
234
- - spec/support/shared_context.rb
232
+ - spec/octospy/url_spec.rb
@@ -1,46 +0,0 @@
1
- require 'helper'
2
-
3
- describe Octospy::Shortener do
4
- let(:url) { 'https://github.com/linyows/octospy' }
5
-
6
- describe '.shorten_by_github' do
7
- subject {
8
- VCR.use_cassette "git.io/#{url.escaping}" do
9
- described_class.shorten_by_github url
10
- end
11
- }
12
-
13
- it { expect(subject).to be_an_instance_of String }
14
- it { expect(subject).to eq 'http://git.io/Pd8gXg' }
15
-
16
- context 'when it is not in the url of github' do
17
- let(:url) { 'https://www.google.co.jp/search?q=octospy' }
18
- it { expect(subject).to eq url }
19
- end
20
-
21
- context 'when raise error' do
22
- it 'return url of argument' do
23
- expect(Faraday).to receive(:new).and_raise Faraday::Error
24
- expect(described_class.shorten_by_github url).to eq url
25
- end
26
- end
27
- end
28
-
29
- describe '.shorten_by_google' do
30
- subject {
31
- VCR.use_cassette "googleapis.com/urlshortener/#{url.escaping}" do
32
- described_class.shorten_by_google url
33
- end
34
- }
35
-
36
- it { expect(subject).to be_an_instance_of String }
37
- it { expect(subject).to eq 'http://goo.gl/8vrLj' }
38
-
39
- context 'when raise error' do
40
- it 'return url of argument' do
41
- expect(Faraday).to receive(:new).and_raise Faraday::Error
42
- expect(described_class.shorten_by_google url).to eq url
43
- end
44
- end
45
- end
46
- end
@@ -1,60 +0,0 @@
1
- shared_context :parser_params do
2
- let(:client) { double Octokit::Client }
3
- let(:parser) { described_class.new client }
4
- let(:event_name) { 'issue_comment_event' }
5
- let(:parsing_method) { :"parse_#{event_name}" }
6
- let(:file) { "#{event_name}.json" }
7
- let(:event) { Hashie::Mash.new.deep_merge(decode file) }
8
-
9
- let(:default_params) do
10
- {
11
- notice_body: false,
12
- none_repository: false,
13
- nick: '',
14
- repository: '',
15
- status: '',
16
- link: '',
17
- title: '',
18
- body: []
19
- }
20
- end
21
-
22
- let(:parsed_params) do
23
- {
24
- status: 'commented on issue #582',
25
- title: 'Remove `engines` from package.json.',
26
- body: [
27
- <<-BODY.pretty_heredoc
28
- Has is ever done anything? It still has a purpose though;
29
- To warn users that they're using antdated version.
30
- BODY
31
- ],
32
- link: 'https://github.com/bower/bower/issues/582#issuecomment-20416296'
33
- }
34
- end
35
-
36
- let(:merged_params) do
37
- default_params.merge(parsed_params).merge(
38
- nick: 'sindresorhus',
39
- repository: 'bower/bower'
40
- )
41
- end
42
-
43
- let(:built_params) do
44
- [
45
- {
46
- nick: merged_params[:nick],
47
- type: :notice,
48
- message: <<-MSG.pretty_heredoc
49
- (bower/bower) \u0002sindresorhus\u000F \u000308commented on issue #582\u000F
50
- Remove `engines` from package.json. - \u000302http://git.io/A0ARbg\u000F
51
- MSG
52
- },
53
- {
54
- nick: merged_params[:nick],
55
- type: :private,
56
- message: parsed_params[:body]
57
- }
58
- ]
59
- end
60
- end