-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemplate.rb
executable file
·69 lines (54 loc) · 1.29 KB
/
template.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'json'
class SlackUp
def self.render
print "Ticket: "
@@ticket = gets.chomp
print "PR: "
@@pr = gets.chomp
print "Deploy: "
@@deploy = gets.chomp
print "Title: "
@@title = gets.chomp
print "Update: "
@@concerns = gets.chomp
@@slack_up = self.format(@@ticket, @@pr, @@title, @@deploy, @@concerns)
end
def self.post_to_slack
print "#{@@slack_up}\nWould you like to post to slack? (y/n): "
response = gets.chomp
if response.downcase == "y"
uri = URI.parse("Your Slack Web Hook")
request = Net::HTTP::Post.new(uri)
request.content_type = "application/json"
request.body = JSON.dump({
"text" => "#{@@slack_up}"
})
req_options = {
use_ssl: uri.scheme == "https",
}
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end
elsif response.downcase == "n"
puts "Aborted"
else
puts "Invalid entry aborted."
end
end
private
def self.format(ticket, pr, title, deploy, concerns)
"
Jonny's Slackup
*Ticket*: #{ticket}
*PR*: #{pr}
*Title*: #{title}
*Deploy*: #{deploy}
*Update*: #{concerns}
"
end
end
SlackUp.render
SlackUp.post_to_slack