@@ -15,6 +15,15 @@ class Service::Email < Service
15
15
16
16
def receive_push
17
17
extend PushEmail
18
+ deliver_to_addresses
19
+ end
20
+
21
+ def receive_public
22
+ extend PublicEmail
23
+ deliver_to_addresses
24
+ end
25
+
26
+ def deliver_to_addresses
18
27
configure_mail_defaults unless mail_configured?
19
28
20
29
addresses . each do |address |
@@ -139,7 +148,27 @@ def noreply_address
139
148
@noreply_address ||= email_config [ 'noreply_address' ] || "GitHub <noreply@github.com>"
140
149
end
141
150
151
+ module RepositoryEmailHelpers
152
+ def name_with_owner
153
+ File . join ( owner_name , repository_name )
154
+ end
155
+
156
+ def owner_name
157
+ payload [ 'repository' ] [ 'owner' ] [ 'name' ]
158
+ end
159
+
160
+ def repository_name
161
+ payload [ 'repository' ] [ 'name' ]
162
+ end
163
+
164
+ def repo_url
165
+ payload [ 'repository' ] [ 'url' ]
166
+ end
167
+ end
168
+
142
169
module PushEmail
170
+ include RepositoryEmailHelpers
171
+
143
172
# Public
144
173
def mail_subject
145
174
if first_commit
@@ -250,10 +279,6 @@ def branch_ref
250
279
payload [ 'ref' ]
251
280
end
252
281
253
- def repo_url
254
- payload [ 'repository' ] [ 'url' ]
255
- end
256
-
257
282
def author_address
258
283
"#{ author_name } <#{ author_email } >"
259
284
end
@@ -275,18 +300,6 @@ def last_commit
275
300
payload [ 'commits' ] . last # assume that the last committer is also the pusher
276
301
end
277
302
278
- def name_with_owner
279
- File . join ( owner_name , repository_name )
280
- end
281
-
282
- def owner_name
283
- payload [ 'repository' ] [ 'owner' ] [ 'name' ]
284
- end
285
-
286
- def repository_name
287
- payload [ 'repository' ] [ 'name' ]
288
- end
289
-
290
303
def first_commit_sha
291
304
first_commit [ 'id' ]
292
305
end
@@ -301,4 +314,23 @@ def first_commit
301
314
payload [ 'commits' ] . first
302
315
end
303
316
end
317
+
318
+ module PublicEmail
319
+ include RepositoryEmailHelpers
320
+
321
+ # Public
322
+ def mail_subject
323
+ "#{ name_with_owner } has changed from Private to Public"
324
+ end
325
+
326
+ # Public
327
+ def mail_body
328
+ "#{ name_with_owner } has changed from Private to Public\n \n #{ repo_url } "
329
+ end
330
+
331
+ # Public
332
+ def mail_from
333
+ noreply_address
334
+ end
335
+ end
304
336
end
0 commit comments