issue 0.1.0 → 0.2.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
  SHA256:
3
- metadata.gz: 10960451c8f6e5f752cc0a2b892ae8b8d122a14e1aaedc3671daa2da41cb80b8
4
- data.tar.gz: b84a85ae117417a348dacfde4b387128190dcb72232e69abb96805eed8585926
3
+ metadata.gz: 88f61dcc894a75f1c8a140ed649a00415d5c1a53ef49df898b081afbfaa1c39f
4
+ data.tar.gz: 37e140e2a0313766e4be4001b472adb57aaee8f834fcda63b7a687155bde0c87
5
5
  SHA512:
6
- metadata.gz: 60caa264fa776efee538761cfa9d06794859bca2490247e9cfdc76e1ea2c86a6e78b6e19fead11f98f522607c26224114b7db564404dd39657c35043f605ef87
7
- data.tar.gz: 501ac0d34f7c80334a66ce90574b2677750b1b23287d2bb65682783fd21413504dec767e6decba5307ac8ddcf0c20beaa5df188f1e23d097ae2849baa66f2da0
6
+ metadata.gz: 13902a89b3863bc9d0a5b52e307737215644ee694ac05a6e1a1efb63dda0a5b41442783f729f09ab97da489da24bde28cad924293440ce116e7b89772f642610
7
+ data.tar.gz: c0bd2d55ace130663a56041b833e9d430b223c450a13877d6cf8872976c051eaba9fca5d6d9ed90a7e05b6d7b95f66318535be3ce669fba637fe019a322308dd
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2021-07-01)
4
+
5
+ - Added initial functionality and classes
6
+
7
+ - Issue::WebHook
8
+ - Issue::Payload
9
+ - Issue::Error
10
+
11
+ ## 0.0.1 (2021-06-29)
12
+
13
+ - Gem created
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Juanjo Bazán
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,2 +1,87 @@
1
- # issue
2
- Ruby gem to parse issue events coming from webhook payloads
1
+ # Issue
2
+ [![Gem Version](https://badge.fury.io/rb/issue.svg)](https://badge.fury.io/rb/issue)
3
+ [![Tests](https://github.com/xuanxu/issue/actions/workflows/tests.yml/badge.svg)](https://github.com/xuanxu/issue/actions/workflows/tests.yml)
4
+
5
+ Issue is a small library dedicated to parse requests coming from GitHub webhooks representing `issues`, `issue_comment` and `pull_request` events.
6
+
7
+ ## Getting started
8
+
9
+ Depending on your project you may:
10
+
11
+ Install the gem:
12
+ ```bash
13
+ $ gem install issue
14
+ ```
15
+ or add it to your Gemfile:
16
+ ```ruby
17
+ gem 'issue'
18
+ ```
19
+
20
+ Require the gem with:
21
+ ```ruby
22
+ require 'issue'
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ The `Issue::Webhook` is used to declare and parse a GitHub webhook. At initialization it accepts a hash of configuration settings:
28
+
29
+ - **secret_token**: The GitHub secret access token for authorization
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.
32
+ - **accept_events**: An Array of GitHub event types to accept. If nil all events will be accepted.
33
+
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.
35
+
36
+ ```ruby
37
+ webhook = Issue::Webhook.new(secret_token: ENV["GH_SECRET"],
38
+ origin: "myorg/reponame",
39
+ discard_sender: "myorg_bot"
40
+ accept_events: ["issues", "issue_comment"])
41
+
42
+ payload, error = webhook.parse_request(request)
43
+
44
+ if webhook.errored?
45
+ head error.status, msg: error.message
46
+ else
47
+ # do_something_based_on_the(payload)
48
+ head 200
49
+ end
50
+
51
+ ```
52
+
53
+ ### The Payload object
54
+
55
+ The `Issue::Payload` object includes all the parsed information coming from the webhook request. It has the following instance methods:
56
+
57
+ - **context**: This method returns a OpenStruct with the following structure:
58
+ ```ruby
59
+ action: # the webhook action,
60
+ event: # the GitHub event coming in the HTTP_X_GITHUB_EVENT request header
61
+ issue_id: # the issue number
62
+ issue_title: # issue title,
63
+ issue_body: # body of the issue
64
+ issue_author: # author of the issue
65
+ issue_labels: # labels of the issue
66
+ repo: # the full name of the origin repository
67
+ sender: # the login of the user triggering the webhook action
68
+ event_action: # a string: "event.action"
69
+ comment_body: # body of the comment
70
+ comment_created_at: # created_at value of the comment
71
+ comment_url: # the html url for the comment
72
+ raw_payload: # a hash with the complete parsed JSON request
73
+ ```
74
+ - **accesor methods** for every key in the context
75
+ - **opened?**: `true` if the action is `opened` or `reopened`
76
+ - **closed?**: `true` if the action is `closed`
77
+ - **commented?**: `true` if the action is `created`
78
+ - **edited?**: `true` if the action is `edited`
79
+ - **locked?**: `true` if the action is `locked`
80
+ - **unlocked?**: `true` if the action is `unlocked`
81
+ - **pinned?**: `true` if the action is `pinned` or `unpinned`
82
+ - **assigned?**: `true` if the action is `assigned` or `unassigned`
83
+ - **labeled?**: `true` if the action is `labeled` or `unlabeled`
84
+
85
+ ## License
86
+
87
+ Released under the MIT license.
data/lib/issue/payload.rb CHANGED
@@ -32,13 +32,22 @@ module Issue
32
32
  def initialize(json_data, event)
33
33
  action = json_data.dig("action")
34
34
  sender = json_data.dig("sender", "login")
35
- issue_id = json_data.dig("issue", "number")
36
- issue_title = json_data.dig("issue", "title")
37
- issue_body = json_data.dig("issue", "body")
38
- issue_labels = json_data.dig("issue", "labels")
39
- issue_author = json_data.dig("issue", "user", "login")
40
35
  repo = json_data.dig("repository", "full_name")
41
36
 
37
+ if event == "pull_request"
38
+ issue_id = json_data.dig("pull_request", "number")
39
+ issue_title = json_data.dig("pull_request", "title")
40
+ issue_body = json_data.dig("pull_request", "body")
41
+ issue_labels = json_data.dig("pull_request", "labels")
42
+ issue_author = json_data.dig("pull_request", "user", "login")
43
+ else
44
+ issue_id = json_data.dig("issue", "number")
45
+ issue_title = json_data.dig("issue", "title")
46
+ issue_body = json_data.dig("issue", "body")
47
+ issue_labels = json_data.dig("issue", "labels")
48
+ issue_author = json_data.dig("issue", "user", "login")
49
+ end
50
+
42
51
  @context = OpenStruct.new(
43
52
  action: action,
44
53
  event: event,
data/lib/issue/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Issue
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.0
4
+ version: 0.2.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-07-01 00:00:00.000000000 Z
11
+ date: 2021-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: openssl
@@ -66,13 +66,15 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.10'
69
- description: Receive, parse and manage GitHub webhook events for issues and issue's
69
+ description: Receive, parse and manage GitHub webhook events for issues, PRs and issue's
70
70
  comments
71
71
  email:
72
72
  executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - CHANGELOG.md
77
+ - LICENSE
76
78
  - README.md
77
79
  - lib/issue.rb
78
80
  - lib/issue/error.rb