issue 0.3.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +2 -1
- data/lib/issue/version.rb +1 -1
- data/lib/issue/webhook.rb +12 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9a0d24902085e9ef25c6765748362b06f5015bbd88848db03513c0cd7f33ce9c
|
4
|
+
data.tar.gz: '099f1cce4e61d95ab0ca87a6c057f59c5b4bae50e2b59cca25df9e334d3b1c39'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5a4bcfa1cb46b5b6a78184e235743cc846f213448c208e0f0da5345c8635e2c635437d57ad66d186f07feb63b5bd0bbcddfae35b42e9e2873d65b4525e8be7f
|
7
|
+
data.tar.gz: 81f10062dc2f189ea2ca8e891139718048a24072ec7d9168391a9ce5eaee5baaf5f6d0359c36cc0cb323fd717821989bb5941a194a6b8c4c3f08159522aeb661
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -28,7 +28,7 @@ The `Issue::Webhook` is used to declare and parse a GitHub webhook. At initializ
|
|
28
28
|
|
29
29
|
- **secret_token**: The GitHub secret access token for authorization
|
30
30
|
- **origin**: The repository to accept payloads from. If nil any origin will be accepted. If not nil any request from a different repository will be ignored
|
31
|
-
- **discard_sender**: The GitHub handle of a user whose events will be ignored. Usually the organization bot. If nil no user will be ignored.
|
31
|
+
- **discard_sender**: The GitHub handle of a user whose events will be ignored. Usually the organization bot. If nil no user will be ignored. To ignore only specific events use a Hash where keys are usernames and values are arrays of events to ignore for that username.
|
32
32
|
- **accept_events**: An Array of GitHub event types to accept. If nil all events will be accepted.
|
33
33
|
|
34
34
|
Once it is initialized a request can be parsed passing it to the **`parse_request`** method. After verifying the request signature and checking for the configurated conditions the `parse_request` method returns a [Payload, Error] pair, where the error is nil if nothing failed, and the payload is nil if an error ocurred.
|
@@ -66,6 +66,7 @@ The `Issue::Payload` object includes all the parsed information coming from the
|
|
66
66
|
repo: # the full name of the origin repository
|
67
67
|
sender: # the login of the user triggering the webhook action
|
68
68
|
event_action: # a string: "event.action"
|
69
|
+
comment_id: # id of the comment
|
69
70
|
comment_body: # body of the comment
|
70
71
|
comment_created_at: # created_at value of the comment
|
71
72
|
comment_url: # the html url for the comment
|
data/lib/issue/version.rb
CHANGED
data/lib/issue/webhook.rb
CHANGED
@@ -22,8 +22,8 @@ module Issue
|
|
22
22
|
def initialize(settings={})
|
23
23
|
@secret_token = settings[:secret_token]
|
24
24
|
@accept_origin = settings[:origin]
|
25
|
-
@discard_sender = settings[:discard_sender]
|
26
25
|
@accept_events = [settings[:accept_events]].flatten.compact.uniq.map(&:to_s)
|
26
|
+
@discard_sender = parse_discard_senders(settings[:discard_sender])
|
27
27
|
end
|
28
28
|
|
29
29
|
# This method will parse the passed request.
|
@@ -53,6 +53,16 @@ module Issue
|
|
53
53
|
|
54
54
|
private
|
55
55
|
|
56
|
+
def parse_discard_senders(discard_sender_settings)
|
57
|
+
if discard_sender_settings.is_a?(String)
|
58
|
+
return { discard_sender_settings => [] }
|
59
|
+
elsif discard_sender_settings.is_a?(Hash)
|
60
|
+
return discard_sender_settings.transform_keys {|k| k.to_s }.transform_values {|v| [v].flatten}
|
61
|
+
else
|
62
|
+
return {}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
56
66
|
def verify_signature
|
57
67
|
gh_signature = request.get_header "HTTP_X_HUB_SIGNATURE"
|
58
68
|
return error!(500, "Can't compute signature") if secret_token.nil? || secret_token.empty?
|
@@ -78,7 +88,7 @@ module Issue
|
|
78
88
|
return error!(422, "No payload") if json_payload.nil? || json_payload.empty?
|
79
89
|
return error!(422, "No event") if event.nil?
|
80
90
|
return error!(200, "Event discarded") unless (accept_events.empty? || accept_events.include?(event))
|
81
|
-
return error!(200, "Event origin discarded") if (discard_sender
|
91
|
+
return error!(200, "Event origin discarded") if (discard_sender[sender] == [] || discard_sender[sender].to_a.include?(event))
|
82
92
|
return error!(403, "Event origin not allowed") if (accept_origin && origin != accept_origin)
|
83
93
|
|
84
94
|
@payload = Issue::Payload.new(json_payload, event)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: issue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juanjo Bazán
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: openssl
|