gitbot 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ config.yml
2
+ .bundle
3
+ coverage
4
+ rdoc
5
+ pkg
6
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gitbot (1.0.0)
5
+ cinch (~> 1.0.0)
6
+ json
7
+ sinatra (~> 1.1.0)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ cinch (1.0.2)
13
+ json (1.4.6)
14
+ rack (1.2.1)
15
+ sinatra (1.1.0)
16
+ rack (~> 1.1)
17
+ tilt (~> 1.1)
18
+ tilt (1.1)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler (~> 1.0.0)
25
+ cinch (~> 1.0.0)
26
+ gitbot!
27
+ json
28
+ sinatra (~> 1.1.0)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Emil Loer
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,28 @@
1
+ GitBot is a Ruby IRC bot that provides a builtin GitHub webhook server.
2
+
3
+ Installation
4
+ ============
5
+
6
+ GitBot will be provided as a Ruby gem when it's ready. Stay tuned.
7
+
8
+ Usage
9
+ =====
10
+
11
+ * First you must make a `config.yml` file so that GitBot knows where it should connect to. You can make a copy of the `config.yml.example` file and use that as a basis.
12
+
13
+ * After that just run `gitbot.rb`. This will start the bot and its built-in webhook server. Alternatively, you can specify a different location for the config file with `gitbot.rb [config_file]`.
14
+
15
+ * You can now add a webhook to a GitHub project. Use the following url: `http://server.com:5651/github`.
16
+
17
+ * Now do some commits and see the commit messages appearing on the IRC channel.
18
+
19
+ License
20
+ =======
21
+
22
+ Copyright (c) 2010 Emil Loer <http://koffietijd.net>
23
+
24
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
25
+
26
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
27
+
28
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "date"
4
+ require "cinch"
5
+ require "sinatra"
6
+ require "yaml"
7
+ require "json"
8
+
9
+ config_file = ARGV.shift || "config.yml"
10
+ if not File.exists? config_file
11
+ puts "can't find config file #{config_file}"
12
+ puts "either create it or specify another config file with #{File.basename $0} [filename]"
13
+ exit
14
+ end
15
+
16
+ $config = YAML.load_file config_file
17
+ puts $config["host"]
18
+
19
+ $bot = Cinch::Bot.new do
20
+ configure do |c|
21
+ c.nick = $config["irc"]["nick"]
22
+ c.user = "gitbot"
23
+ c.realname = "GitBot (c) piet"
24
+ c.server = $config["irc"]["server"]
25
+ c.port = $config["irc"]["port"]
26
+ c.channels = $config["irc"]["channels"]
27
+ end
28
+ end
29
+
30
+ Thread.new do
31
+ $bot.start
32
+ end
33
+
34
+ def say(repo,msg)
35
+ $config["irc"]["channels"].each do |chan|
36
+ unless $config["filters"].include? chan and not $config["filters"][chan].include? repo
37
+ $bot.Channel(chan).send msg
38
+ end
39
+ end
40
+ end
41
+
42
+ configure do
43
+ set :bind, $config["http"]["host"]
44
+ set :port, $config["http"]["port"]
45
+ set :logging, false
46
+ set :lock, true
47
+ end
48
+
49
+ get "/" do
50
+ "GITBOT FOO"
51
+ end
52
+
53
+ post "/github" do
54
+ p params[:payload]
55
+ push = JSON.parse(params[:payload])
56
+
57
+ repo = push["repository"]["name"]
58
+ branch = push["ref"].gsub(/^refs\/heads\//,"")
59
+
60
+ # sort commits by timestamp
61
+ push["commits"].sort! do |a,b|
62
+ DateTime.parse(a["timestamp"]) <=> DateTime.parse(b["timestamp"])
63
+ end
64
+
65
+ # output first 3 commits
66
+ push["commits"][0..2].each do |c|
67
+ say repo, "\0030#{repo}:\0037 #{branch}\0033 #{c["author"]["name"]}\003 #{c["message"]}"
68
+ end
69
+
70
+ if push["commits"].length-2 > 0
71
+ say repo, "\0030#{repo}:\0037 #{branch}\003 ... and #{push["commits"].length-2} more"
72
+ end
73
+
74
+ push.inspect
75
+ end
@@ -0,0 +1,22 @@
1
+ # IRC connection settings
2
+ irc:
3
+ server: "irc.freenode.org"
4
+ port: 6667
5
+ nick: GitBot
6
+
7
+ # Here you can specify the channels that GitBot will join
8
+ channels:
9
+ - "#someproject"
10
+ - "#otherproject"
11
+
12
+ # HTTP server settings
13
+ http:
14
+ host: 0.0.0.0
15
+ port: 5651
16
+
17
+ # By default GitBot will announce all commits to all channels. You can limit
18
+ # a certain channel to only a specified group of repositories by adding a
19
+ # channel filter
20
+ filters:
21
+ "#someproject": [only_this_repo, and_that_repo]
22
+
@@ -0,0 +1,81 @@
1
+ #!/bin/bash
2
+
3
+ HOST=example.com
4
+ PORT=5651
5
+ URL=http://host.com/path/to/repo
6
+ NAME=repository_name
7
+
8
+ GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
9
+ if [ -z "$GIT_DIR" ]; then
10
+ echo >&2 "fatal: post-receive: GIT_DIR not set"
11
+ exit 1
12
+ fi
13
+
14
+ if [ -n "$1" -a -n "$2" -a -n "$3" ]; then
15
+ oldrev=$1
16
+ newrev=$2
17
+ refname=$3
18
+ else
19
+ read oldrev newrev refname
20
+ fi
21
+ oldrev=$(git rev-parse $oldrev)
22
+ newrev=$(git rev-parse $newrev)
23
+
24
+ function commits {
25
+ log=`git log --pretty="format:%h%n%an%n%ae%n%at%n%s" $oldrev..$newrev | tr '\n' '|'`
26
+ IFS="|"
27
+ arr=( $log )
28
+
29
+ # TODO: get creations/deletions from --shortstat
30
+
31
+ first=1
32
+ for (( i = 0; i < ${#arr[@]}; i+=5 )); do
33
+ # [[ ${arr[i+5]} =~ ^\ ([0-9]+)\ .*\ ([0-9]+)\ .*\ ([0-9]+)\ .*$ ]]
34
+ # changed=${BASH_REMATCH[1]}
35
+
36
+ [[ $first == 0 ]] && echo ","
37
+ echo "{
38
+ \"id\": \"${arr[i]}\",
39
+ \"message\": \"${arr[i+4]}\",
40
+ \"timestamp\": \"${arr[i+3]}\",
41
+ \"url\": \"$URL\",
42
+ \"added\": [],
43
+ \"removed\": [],
44
+ \"modified\": [],
45
+ \"author\": {
46
+ \"name\": \"${arr[i+1]}\",
47
+ \"email\": \"${arr[i+2]}\"
48
+ }
49
+ }"
50
+
51
+ first=0
52
+ done
53
+
54
+ }
55
+
56
+ function json {
57
+ echo "{
58
+ \"before\": \"$oldrev\",
59
+ \"after\": \"$newrev\",
60
+ \"ref\": \"$refname\",
61
+ \"repository\": {
62
+ \"name\": \"$NAME\",
63
+ \"url\": \"$URL\",
64
+ \"pledgie\": \"\",
65
+ \"description\": \"Unknown\",
66
+ \"homepage\": \"$URL\",
67
+ \"watchers\": 0,
68
+ \"forks\": 0,
69
+ \"private\": true,
70
+ \"owner\": {
71
+ \"name\": \"Unknown\",
72
+ \"email\": \"Unknown\"
73
+ }
74
+ },
75
+ \"commits\": [
76
+ $(commits)
77
+ ]
78
+ }"
79
+ }
80
+
81
+ json | curl --form "payload=<-" http://$HOST:$PORT/github
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{gitbot}
5
+ s.version = "1.0.0"
6
+ s.platform = Gem::Platform::RUBY
7
+ s.licenses = ["MIT"]
8
+ s.authors = ["Emil Loer"]
9
+ s.email = %q{emil@koffietijd.net}
10
+ s.homepage = %q{http://github.com/thedjinn/gitbot}
11
+ s.summary = %q{An IRC bot that listens to GitHub webhooks}
12
+ s.description = %q{An IRC bot that listens to GitHub webhooks}
13
+
14
+ #s.rubyforge_project = "gitbot"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.extra_rdoc_files = [
22
+ "LICENSE.txt",
23
+ "README.markdown"
24
+ ]
25
+
26
+ s.default_executable = %q{gitbot}
27
+
28
+ s.add_runtime_dependency(%q<cinch>, ["~> 1.0.0"])
29
+ s.add_runtime_dependency(%q<sinatra>, ["~> 1.1.0"])
30
+ s.add_runtime_dependency(%q<json>, [">= 0"])
31
+
32
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
33
+
34
+ s.required_ruby_version = Gem::Requirement.new(">= 1.9.1")
35
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitbot
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 0
9
+ version: 1.0.0
10
+ platform: ruby
11
+ authors:
12
+ - Emil Loer
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-10 00:00:00 +01:00
18
+ default_executable: gitbot
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
+ - 1
30
+ - 0
31
+ - 0
32
+ version: 1.0.0
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: sinatra
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ segments:
44
+ - 1
45
+ - 1
46
+ - 0
47
+ version: 1.1.0
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: json
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ name: bundler
65
+ prerelease: false
66
+ requirement: &id004 !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ~>
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 1
73
+ - 0
74
+ - 0
75
+ version: 1.0.0
76
+ type: :development
77
+ version_requirements: *id004
78
+ description: An IRC bot that listens to GitHub webhooks
79
+ email: emil@koffietijd.net
80
+ executables:
81
+ - gitbot
82
+ extensions: []
83
+
84
+ extra_rdoc_files:
85
+ - LICENSE.txt
86
+ - README.markdown
87
+ files:
88
+ - .gitignore
89
+ - Gemfile
90
+ - Gemfile.lock
91
+ - LICENSE.txt
92
+ - README.markdown
93
+ - bin/gitbot
94
+ - config.yml.example
95
+ - extra/post-receive
96
+ - gitbot.gemspec
97
+ has_rdoc: true
98
+ homepage: http://github.com/thedjinn/gitbot
99
+ licenses:
100
+ - MIT
101
+ post_install_message:
102
+ rdoc_options: []
103
+
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ segments:
112
+ - 1
113
+ - 9
114
+ - 1
115
+ version: 1.9.1
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ segments:
122
+ - 0
123
+ version: "0"
124
+ requirements: []
125
+
126
+ rubyforge_project:
127
+ rubygems_version: 1.3.7
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: An IRC bot that listens to GitHub webhooks
131
+ test_files: []
132
+