gh-events 0.5.0 → 0.6.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: 4aa33330e1cf347818446e7309be67a9a23c8111b830189d29047c017363cee5
4
- data.tar.gz: d0928eed123ec7a5c5fd69122f6502f9158ada6bf3fce30af23c7026a1ac4fc4
3
+ metadata.gz: 2008b1c5311735ce045e5007f3fb77a30df7881c2a2e3eae4b01ee11b93feda4
4
+ data.tar.gz: 8df066ce105675449515e12fe44c404d5683d55bc74fee7454d90dde9168f372
5
5
  SHA512:
6
- metadata.gz: 0bba3c1239377764f4cca8756a3fb2865f583a9b879722dcfb2f089c7f9c26ed8d9a46df9b69cf8cb52c5119f9cb9ad60e1f5add610a12bf9d3325bfd7fc4893
7
- data.tar.gz: 4af3c4728fd84e62c89ee4fdd18bd683df65d8fd71d99657816f7da811b529c86746fc2bb60720bf3062b3a33cde7c718adadec323610b0dc88f15671b2203eb
6
+ metadata.gz: f303f779bbdd664d88e5225c3eb73176d4b4b8784c1c7463423be4a4a9c0103df6632ef4c68032bcb8cea6dfb0d2fb3ba95f94c2fc19dadceefef1e9c234762f
7
+ data.tar.gz: 01a062898625a3195113d8d79d19c2c0c4a3edfd7e673bcf68ef5fec2349e6bfe3af94120a843a9677fe9025d1c1f11a3b41654dc64dfc34da2fabbd76f1805d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gh-events (0.5.0)
4
+ gh-events (0.6.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -7,6 +7,10 @@ module GH::Events::Slack
7
7
 
8
8
  extend self
9
9
 
10
+ # this is a carefully curated list of fields in gh events that might
11
+ # be helpful when filtering events
12
+ ASPECTS = %i[type action state context]
13
+
10
14
  def translate(payload)
11
15
  event = JSON.parse(payload, object_class: OpenStruct)
12
16
  type = GH::Events.typeof(event).to_s
@@ -16,8 +20,29 @@ module GH::Events::Slack
16
20
  event.ref_type = 'tag' if event.ref&.match(/^refs\/tags\//)
17
21
  event.ref = event.ref&.split('/')&.last
18
22
 
19
- template = templates[[type, event.action]*'.']
20
- template ||= (templates[type] || "No template for type: #{type}.")
23
+ # add type to the event
24
+ event.type = type
25
+
26
+ # collect the aspects
27
+ aspects = ASPECTS.map { |a| event.send(a) }.compact
28
+
29
+ # add the specific type (stype) to the event
30
+ event.stype = aspects * '.'
31
+
32
+ # lookup the template by type and all the specific types
33
+ _result = aspects.reduce({as: [], ts: []}) do |r, aspect|
34
+ r[:as] << aspect
35
+ r[:ts] << templates[r[:as] * '.']
36
+ r
37
+ end
38
+ template = _result[:ts].compact.last
39
+
40
+ # if the event was set to `false` abort
41
+ exit(1) if template === false
42
+
43
+ # if there is no template use a default
44
+ template ||= templates['no_template']
45
+
21
46
  render(template, event)
22
47
  end
23
48
 
@@ -1,5 +1,5 @@
1
1
  module GH
2
2
  module Events
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
data/res/slack.yml CHANGED
@@ -1,9 +1,5 @@
1
1
  # refs are unified. So all events have `ref` and `ref_type`.
2
2
 
3
- unknown:
4
- text: >-
5
- An unknown event occurred.
6
-
7
3
  push:
8
4
  text: >-
9
5
  :arrow_up:
@@ -50,7 +46,7 @@ create:
50
46
 
51
47
  delete:
52
48
  text: >-
53
- :collision:
49
+ :wastebasket:
54
50
  <<%= sender.html_url %>|<%= sender.login %>>
55
51
  deleted
56
52
  <%= ref_type %> `<%= ref %>`
@@ -77,7 +73,20 @@ issues:
77
73
  <%= action %>
78
74
  issue <<%= issue.html_url %>|<%= issue.title %>>
79
75
  on <<%= repository.html_url %>|<%= repository.full_name %>>
80
- <% if action == 'opened' %>: <%= issue.body %><% end %>
76
+
77
+ issues.opened:
78
+ text: >-
79
+ :inbox_tray:
80
+ new issue
81
+ <<%= issue.html_url %>|<%= issue.title %>>
82
+ on <<%= repository.html_url %>|<%= repository.full_name %>>
83
+ attachments:
84
+ - fallback: <%= issue.body %>
85
+ color: red
86
+ author_name: <%= sender.login %>
87
+ author_link: <%= sender.html_url %>
88
+ author_icon: <%= sender.avatar_url %>
89
+ text: <%= issue.body %>
81
90
 
82
91
  issues.labeled:
83
92
  text: >-
@@ -96,6 +105,21 @@ pull_request:
96
105
  PR <<%= pull_request.html_url %>|<%= pull_request.title %>>
97
106
  on <<%= repository.html_url %>|<%= repository.full_name %>>
98
107
 
108
+ pull_request.opened:
109
+ text: >-
110
+ :gift:
111
+ <<%= sender.html_url %>|<%= sender.login %>>
112
+ opened
113
+ PR <<%= pull_request.html_url %>|<%= pull_request.title %>>
114
+ on <<%= repository.html_url %>|<%= repository.full_name %>>
115
+ attachments:
116
+ - fallback: <%= pull_request.body %>
117
+ color: red
118
+ author_name: <%= sender.login %>
119
+ author_link: <%= sender.html_url %>
120
+ author_icon: <%= sender.avatar_url %>
121
+ text: <%= pull_request.body %>
122
+
99
123
  pull_request.labeled:
100
124
  text: >-
101
125
  <<%= sender.html_url %>|<%= sender.login %>>
@@ -107,9 +131,15 @@ pull_request.labeled:
107
131
  pull_request_review_comment:
108
132
  text: >-
109
133
  :left_speech_bubble:
110
- <<%= sender.html_url %>|<%= sender.login %>>
111
- commented
112
- on <<%= comment.html_url %>|<%= .pull_request.title %>>: <%= comment.body %>
134
+ new review comment
135
+ on <<%= comment.html_url %>|<%= pull_request.title %>>
136
+ attachments:
137
+ - fallback: <%= comment.body %>
138
+ color: red
139
+ author_name: <%= sender.login %>
140
+ author_link: <%= sender.html_url %>
141
+ author_icon: <%= sender.avatar_url %>
142
+ text: <%= comment.body %>
113
143
 
114
144
  star:
115
145
  text: >-
@@ -119,18 +149,11 @@ star:
119
149
  <<%= repository.html_url %>|<%= repository.full_name %>>
120
150
  :star: <%= repository.stargazers_count %>
121
151
 
122
- watch:
123
- text: >-
124
- :eye:
125
- <<%= sender.html_url %>|<%= sender.login %>>
126
- <%= action == 'created' ? 'started' : 'stopped' %> watching
127
- <<%= repository.html_url %>|<%= repository.full_name %>>
128
- :eye: <%= repository.watchers_count %>
129
-
130
152
  # Ignore other status udpates than CircleCI failures for the moment
131
153
  status:
132
154
  text: >-
133
155
  <% if context.match(/circleci/) and state == 'failure' %>
156
+ [`<%= stype %>`]
134
157
  <<%= target_url %> | CircleCI build >
135
158
  fails for commit
136
159
  <<%= commit.html_url %> | <%= commit.commit.message %>>
@@ -138,12 +161,17 @@ status:
138
161
  <<%= sender.html_url %>|<%= sender.login %>>
139
162
  <% end %>
140
163
 
164
+ fork:
165
+ text: >-
166
+ :fork_and_knife:
167
+ [`<%= stype >`]
168
+ <<%= sender.html_url %>|<%= sender.login %>>
169
+ forked <<%= repository.html_url %>|<%= repository.full_name %>>
170
+
141
171
  deployment:
142
172
  text: An event of type `deployment` occurred.
143
173
  deployment_status:
144
174
  text: An event of type `deployment_status` occurred.
145
- fork:
146
- text: An event of type `fork` occurred.
147
175
  gollum:
148
176
  text: An event of type `gollum` occurred.
149
177
  member:
@@ -160,3 +188,29 @@ repository:
160
188
  text: An event of type `repository` occurred.
161
189
  team_add:
162
190
  text: An event of type `team_add` occurred.
191
+
192
+ # `false` will make it end with exit code 1
193
+ watch: false
194
+
195
+ # `no_template` will be used for recognized events which have no
196
+ # template assigned.
197
+ no_template:
198
+ text: No template for event of type `<%= stype %>`.
199
+ attachments:
200
+ - fallback: Event details as json.
201
+ color: gray
202
+ text: |
203
+ ```
204
+ <%= JSON.unparse(self.marshal_dump) %>
205
+ ```
206
+
207
+ # `unknown` will be used for events that could not be recognized.
208
+ unknown:
209
+ text: An unknown event occurred (stype: `<%=stype%>`)
210
+ attachments:
211
+ - fallback: Event details as json.
212
+ color: gray
213
+ text: |
214
+ ```
215
+ <%= JSON.unparse(self.marshal_dump) %>
216
+ ```
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gh-events
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Phil Hofmann