gwooks 0.0.1 → 0.0.2
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/README.md +68 -29
- data/lib/gwooks/base.rb +4 -0
- data/lib/gwooks/version.rb +1 -1
- data/spec/gwooks/base_spec.rb +11 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Gwooks
|
2
2
|
|
3
|
-
A DSL for quickly creating endpoints for
|
3
|
+
A DSL for quickly creating endpoints for
|
4
|
+
[GitHub post-receive webhooks](https://help.github.com/articles/post-receive-hooks).
|
5
|
+
It makes it easy to perform some actions whenever one of your GitHub repos receives a push matching someone
|
6
|
+
custom conditions.
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -18,38 +21,45 @@ Or install it yourself as:
|
|
18
21
|
|
19
22
|
## Usage
|
20
23
|
|
21
|
-
|
24
|
+
First extend the `Gwooks::Base` class and use the DSL to create actions to be performed in response to a push:
|
22
25
|
|
23
26
|
```ruby
|
24
|
-
class
|
27
|
+
class MyHookHandler < Gwooks::Base
|
25
28
|
|
26
|
-
repository_name "
|
27
|
-
# this block gets
|
28
|
-
#
|
29
|
+
repository_name "my_cool_project" do
|
30
|
+
# this block gets executed when GitHub receives
|
31
|
+
# a push to a repo named "my_cool_project"
|
32
|
+
|
33
|
+
# Here you can also access the payload sent by GitHub:
|
34
|
+
contributors = payload["commits"].map { |c| c["author"]["name"] }
|
35
|
+
send_email "someone@email.com", "my_cool_project received changes by: #{ contributors.join(', ') }"
|
29
36
|
end
|
30
37
|
|
31
|
-
|
32
|
-
# this block gets called when a
|
33
|
-
#
|
34
|
-
# matching the Regexp. The block gets passed an array of
|
35
|
-
# MatchData objects, one for every match.
|
38
|
+
commit_message /Bump new version v(\d+\.\d+\.\d+)/ do |matches|
|
39
|
+
# this block gets called when GitHub receives a push
|
40
|
+
# with at least one commit message matching the Regexp.
|
36
41
|
matches.each do |match|
|
37
|
-
|
38
|
-
# we can tweet about the new version released:
|
39
|
-
publish_tweet("New version released: #{match[1]}")
|
42
|
+
send_email("someone@email.com", "New version released: #{match[1]}")
|
40
43
|
end
|
41
44
|
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def send_email(to, msg)
|
49
|
+
# assume we define here a method to send an email
|
50
|
+
end
|
42
51
|
|
43
52
|
end
|
44
53
|
```
|
45
54
|
|
46
|
-
Then set up an application providing an endpoint for the post-receive
|
55
|
+
Then set up an application providing an endpoint for the GitHub post-receive webhook and make use of the
|
56
|
+
class you created:
|
47
57
|
|
48
58
|
```ruby
|
49
59
|
require "sinatra"
|
50
60
|
|
51
61
|
post "/webhook" do
|
52
|
-
|
62
|
+
MyHookHandler.call(params[:payload])
|
53
63
|
end
|
54
64
|
```
|
55
65
|
|
@@ -57,26 +67,51 @@ Alternatively, you can use the sinatra application provided by the class `Gwooks
|
|
57
67
|
|
58
68
|
```ruby
|
59
69
|
# In your config.ru
|
70
|
+
require "gwooks"
|
60
71
|
|
61
|
-
Gwooks::App
|
62
|
-
|
72
|
+
# Tell Gwooks::App to use your class
|
73
|
+
Gwooks::App.use_webhook MyHookHandler
|
74
|
+
|
75
|
+
# Gwooks::App sets up an endpoint on POST /"
|
76
|
+
run Gwooks::App
|
63
77
|
```
|
64
78
|
|
65
|
-
|
79
|
+
Finally [set up your GitHub repo](https://help.github.com/articles/post-receive-hooks) to trigger a
|
80
|
+
post-receive hook pointing to your endpoint. Whenever GitHub receives a push, your endpoint will be
|
81
|
+
notified, and _all_ the matching actions will be performed.
|
82
|
+
|
83
|
+
### DSL methods
|
84
|
+
|
85
|
+
Each DSL method matches a corresponding property in the payload sent by the GitHub post-receive hooks
|
86
|
+
(e.g. `repository_owner_email` matches `payload["repository"]["owner"]["email"]`). Note that all the methods
|
87
|
+
starting with `commits` are also aliased with the singular `commit` to improve code readability.
|
88
|
+
|
89
|
+
The signature is identical for all methods:
|
66
90
|
|
67
|
-
|
91
|
+
```ruby
|
92
|
+
dsl_method_name(pattern, &block)
|
93
|
+
```
|
94
|
+
|
95
|
+
**pattern** can be any object. If it is a Regexp, it is matched against
|
96
|
+
the target property in the payload, otherwise it is checked for equality.
|
97
|
+
|
98
|
+
**block** is called passing the match, or array of matches if the target
|
99
|
+
property is an array (which is, in all commit* methods). The match is a
|
100
|
+
MatchData object when regexp matching is used, or the matched pattern otherwise.
|
101
|
+
|
102
|
+
Here is the full list of the DSL methods:
|
68
103
|
```
|
69
104
|
after
|
70
105
|
before
|
71
|
-
commits_added
|
72
|
-
commits_author_email
|
73
|
-
commits_author_name
|
74
|
-
commits_id
|
75
|
-
commits_message
|
76
|
-
commits_modified
|
77
|
-
commits_removed
|
78
|
-
commits_timestamp
|
79
|
-
commits_url
|
106
|
+
commits_added (alias: commit_added)
|
107
|
+
commits_author_email (alias: commit_author_email)
|
108
|
+
commits_author_name (alias: commit_author_name)
|
109
|
+
commits_id (alias: commit_id)
|
110
|
+
commits_message (alias: commit_message)
|
111
|
+
commits_modified (alias: commit_modified)
|
112
|
+
commits_removed (alias: commit_removed)
|
113
|
+
commits_timestamp (alias: commit_timestamp)
|
114
|
+
commits_url (alias: commit_url)
|
80
115
|
ref
|
81
116
|
repository_description
|
82
117
|
repository_forks
|
@@ -89,3 +124,7 @@ repository_private
|
|
89
124
|
repository_url
|
90
125
|
repository_watchers
|
91
126
|
```
|
127
|
+
|
128
|
+
## Beta
|
129
|
+
|
130
|
+
Please take into consideration that this is a beta release, and as such the API may change
|
data/lib/gwooks/base.rb
CHANGED
data/lib/gwooks/version.rb
CHANGED
data/spec/gwooks/base_spec.rb
CHANGED
@@ -61,6 +61,17 @@ describe "subclass of Gwooks::Base" do
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
64
|
+
|
65
|
+
method_names.select { |n| n.start_with? "commits_" }.each do |method_name|
|
66
|
+
aliased_method_name = method_name.gsub(/^commits_/, "commit_")
|
67
|
+
|
68
|
+
describe aliased_method_name do
|
69
|
+
it "is an alias for #{method_name}" do
|
70
|
+
aliased_method = GwooksBaseSub.method(aliased_method_name.to_sym)
|
71
|
+
aliased_method.should == GwooksBaseSub.method(method_name.to_sym)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
64
75
|
|
65
76
|
describe "instance" do
|
66
77
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gwooks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Luca Ongaro
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2013-01-
|
18
|
+
date: 2013-01-14 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
requirement: &id001 !ruby/object:Gem::Requirement
|