cinch-github_notifications 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +58 -0
- data/Rakefile +1 -0
- data/cinch-github_notifications.gemspec +26 -0
- data/lib/cinch/plugins/github_notifications.rb +2 -0
- data/lib/cinch/plugins/github_notifications/checker.rb +73 -0
- data/lib/cinch/plugins/github_notifications/poster.rb +66 -0
- data/lib/cinch/plugins/github_notifications/version.rb +7 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b5b5667b1a693ccd303660fc012ef0950607fc0d
|
4
|
+
data.tar.gz: c430c2dec691fce6adcaf4f30865c7de50f28572
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5154d0dbaa29fe391606bf91f43852529fbd06c7661b40b99af20fc36876209c244c060c5bb32aa52c7030ebd79c32424369e5253ec985eea39369db84090182
|
7
|
+
data.tar.gz: 5a2297bfdc6bf9b13a183196817dca2ddffdf4c0411ff13aa6a4256014e173bc9012489dc0b7aa2c3197fd7f8191acf6efd5a2fd1b3b8ef4c7ee7e8e8cbd78eb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Github plugin for Cinch
|
2
|
+
|
3
|
+
This [Cinch](https://github.com/cinchrb/cinch) plugin will allow you to post to channels with notifications from github.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'cinch-github_notifications'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Add the plugin class to your bot setup and put some settings in there:
|
18
|
+
|
19
|
+
require 'cinch'
|
20
|
+
require 'cinch/plugins/github_notifications'
|
21
|
+
|
22
|
+
bot = Cinch::Bot.new do
|
23
|
+
configure do |c|
|
24
|
+
c.nick = "githubbot"
|
25
|
+
c.realname = "Tik-Tok"
|
26
|
+
c.server = "irc.freenode.net"
|
27
|
+
c.channels = %w{#channel1 #channel2}
|
28
|
+
c.plugins.plugins = [Cinch::Plugins::GithubNotifications::Poster]
|
29
|
+
c.plugins.options = {
|
30
|
+
Cinch::Plugins::GithubNotifications::Poster => {
|
31
|
+
:bot => self, # This is vital
|
32
|
+
:github_credentials => {
|
33
|
+
# These are the arguments to Octokit::Client.new
|
34
|
+
# You can use oauth tokens too
|
35
|
+
:login => "bob",
|
36
|
+
:password => "password"
|
37
|
+
},
|
38
|
+
:announce => {
|
39
|
+
# List of regular expressions matched against the repo the notification came from
|
40
|
+
# Notifications relating to repos with the name starting "jphastings/" should have events posted to #channel1
|
41
|
+
%r{^jphastings/} => %w{#channel1},
|
42
|
+
# All events will post to #channel2
|
43
|
+
%r{} => %w{#channel2}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
bot.start
|
51
|
+
|
52
|
+
## Contributing
|
53
|
+
|
54
|
+
1. Fork it
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cinch/plugins/github_notifications/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cinch-github_notifications"
|
8
|
+
spec.version = Cinch::Plugins::GithubNotifications::VERSION
|
9
|
+
spec.authors = ["JP Hastings-Spital"]
|
10
|
+
spec.email = ["jphastings@gmail.com"]
|
11
|
+
spec.description = %q{Allow your cinch IRC bot to alert channels of rull requests}
|
12
|
+
spec.summary = %q{Github functionality for Cinch IRC bots}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "cinch", "~>2.0"
|
22
|
+
spec.add_dependency "octokit"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "octokit"
|
2
|
+
|
3
|
+
# FIXME: This is a DIRTY HACK until I can get certificates to work
|
4
|
+
require 'openssl'
|
5
|
+
$stderr.puts "Seriously, FIX THIS CODE #{__FILE__}:#{__LINE__}"
|
6
|
+
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
7
|
+
|
8
|
+
|
9
|
+
module Cinch
|
10
|
+
module Plugins
|
11
|
+
module GithubNotifications
|
12
|
+
class Checker
|
13
|
+
def initialize(args = {})
|
14
|
+
raise RuntimeError, "args[:bot] must be a cinch bot" unless args[:bot].is_a?(Cinch::Bot)
|
15
|
+
@cinch_bot = args[:bot]
|
16
|
+
@sequence = args[:sequence] || "cinch-github-event.seq"
|
17
|
+
|
18
|
+
if args[:github_enterprise]
|
19
|
+
$stdout.puts "Using github enterprise at #{args[:github_enterprise]}"
|
20
|
+
Octokit.configure do |c|
|
21
|
+
c.api_endpoint = URI.join(args[:github_enterprise],"api/v3").to_s
|
22
|
+
c.web_endpoint = args[:github_enterprise]
|
23
|
+
end
|
24
|
+
else
|
25
|
+
p args
|
26
|
+
end
|
27
|
+
|
28
|
+
@octoclient ||= Octokit::Client.new(args[:github_credentials] || {})
|
29
|
+
end
|
30
|
+
|
31
|
+
def start
|
32
|
+
@thread = Thread.new do
|
33
|
+
begin
|
34
|
+
loop do
|
35
|
+
# Get the latest public events, and
|
36
|
+
@octoclient.public_events.reverse.each do |gh_event|
|
37
|
+
if gh_event['id'].to_i > get_seq
|
38
|
+
@cinch_bot.handlers.dispatch(:github_event, nil, gh_event)
|
39
|
+
set_seq(gh_event['id'])
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
sleep 60
|
44
|
+
end
|
45
|
+
rescue Octokit::Unauthorized => e
|
46
|
+
$stderr.puts "Github credentials are incorrect."
|
47
|
+
end
|
48
|
+
end
|
49
|
+
@thread.abort_on_exception = true
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def get_seq
|
55
|
+
return @seq if @seq
|
56
|
+
@seq = 0
|
57
|
+
open(@sequence,'r') do |f|
|
58
|
+
@seq = f.read.to_i
|
59
|
+
end
|
60
|
+
rescue
|
61
|
+
@seq = 0
|
62
|
+
end
|
63
|
+
|
64
|
+
def set_seq(num)
|
65
|
+
@seq = num.to_i
|
66
|
+
open(@sequence,'w') do |f|
|
67
|
+
f.write(@seq)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative "checker"
|
2
|
+
|
3
|
+
module Cinch
|
4
|
+
module Plugins
|
5
|
+
module GithubNotifications
|
6
|
+
class Poster
|
7
|
+
include Cinch::Plugin
|
8
|
+
|
9
|
+
def initialize(*args)
|
10
|
+
super
|
11
|
+
|
12
|
+
checker = Checker.new(config)
|
13
|
+
checker.start
|
14
|
+
end
|
15
|
+
|
16
|
+
listen_to :github_event
|
17
|
+
|
18
|
+
def listen(m, info)
|
19
|
+
event = info['type'].gsub(/([A-Z])/,"_\\1")[1..-7].downcase.to_sym
|
20
|
+
unless Messages.respond_to?(event)
|
21
|
+
debug "A github \"#{info['type']}\" was received, but Cinch::Plugins::Github::Messages.#{event} is not defined."
|
22
|
+
return nil
|
23
|
+
end
|
24
|
+
|
25
|
+
message = nil
|
26
|
+
|
27
|
+
config[:announce].each_pair do |match, channels|
|
28
|
+
if info['repo']['name'] =~ match
|
29
|
+
channels.each do |channel|
|
30
|
+
message ||= Messages.send(event,info)
|
31
|
+
Channel(channel).send(message) unless message.nil?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Messages
|
39
|
+
def self.pull_request(info)
|
40
|
+
if info['payload']['action'] != "closed"
|
41
|
+
"[#{info['actor']['login']}] #{info['payload']['action']} a pull request for #{info['repo']['name']}. #{info['payload']['pull_request']['html_url']}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.push(info)
|
46
|
+
"[#{info['actor']['login']}] pushed #{info['payload']['size']} commit#{info['payload']['size'] == 1 ? '' : 's'} to #{info['repo']['name']}. #{info['repo']['url']['html_url']}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.create(info)
|
50
|
+
"[#{info['actor']['login']}] created a #{info['payload']['ref_type']} called #{info['payload']['ref']} on #{info['repo']['name']}. #{info['repo']['url']['html_url']}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.commit_comment(info)
|
54
|
+
actors = info['payload']['comment']['body'].scan(/@([a-z0-9-]+)/i).first
|
55
|
+
|
56
|
+
if actors.length > 0
|
57
|
+
last_actor = actors.length == 1 ? nil : actors.pop
|
58
|
+
"[#{info['actor']['login']}] mentioned #{[actors.join(', '),last_actor].compact.join(' and ')} in a comment on #{info['repo']['name']}. #{info['payload']['comment']['url']}"
|
59
|
+
else
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cinch-github_notifications
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- JP Hastings-Spital
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cinch
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: octokit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Allow your cinch IRC bot to alert channels of rull requests
|
70
|
+
email:
|
71
|
+
- jphastings@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- cinch-github_notifications.gemspec
|
82
|
+
- lib/cinch/plugins/github_notifications.rb
|
83
|
+
- lib/cinch/plugins/github_notifications/checker.rb
|
84
|
+
- lib/cinch/plugins/github_notifications/poster.rb
|
85
|
+
- lib/cinch/plugins/github_notifications/version.rb
|
86
|
+
homepage: ''
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.0.3
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Github functionality for Cinch IRC bots
|
110
|
+
test_files: []
|