pushpop-slack 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +144 -17
- data/lib/pushpop-slack/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e09451bfe1d62cf7aad3d1cda7579f1f7fe95d1
|
4
|
+
data.tar.gz: f091b0e336e72347cbe3456ce84ffceafca57fe0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 499e1b5cda4338e1f1992e5529c04a812da51919e85f66c9878ca5441aae4d351866bfdb94776ca8c8f6ee8736c1b294c9368b750d073338f695b855dbf56ed0
|
7
|
+
data.tar.gz: fca4e494f792234613818b929723196e9b81fff5efeb31d09fbf1ad839d1905f76f93e9995dc642effd13f75c1aed7f8dbd5f04887a2af0271db43de8b63bceb
|
data/README.md
CHANGED
@@ -1,32 +1,159 @@
|
|
1
1
|
## pushpop-plugin
|
2
2
|
|
3
|
-
A
|
4
|
-
be published as gems and easily included in Pushpop projects.
|
3
|
+
A [Pushpop](https://github.com/pushpop-project/pushpop) plugin for sending messages to Slack
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
### Installation
|
6
|
+
|
7
|
+
Add `pushpop-slack` gem to your Gemfile
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'pushpop-slack'
|
11
|
+
```
|
12
|
+
|
13
|
+
or install it as a gem
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ gem install pushpop-slack
|
17
|
+
```
|
18
|
+
|
19
|
+
You will also need to set an environment variable for your Slack Webhook. Here's how:
|
20
|
+
|
21
|
+
1. Go to your Slack team site and [create an Incoming Webhooks integration](slack.com/services/new).
|
22
|
+
2. Choose a default channel for pushpop messages. You can override this in the actual job.
|
23
|
+
3. Copy the `Webhook URL`.
|
24
|
+
4. Set that to `SLACK_WEBHOOK_URL` in your environment ([heroku](https://devcenter.heroku.com/articles/config-vars), [shell](https://www.digitalocean.com/community/tutorials/how-to-read-and-set-environmental-and-shell-variables-on-a-linux-vps))
|
8
25
|
|
9
26
|
### Usage
|
10
27
|
|
11
|
-
|
12
|
-
|
28
|
+
`pushpop-slack` has a pretty easy DSL for sending messages to slack, and also handles all of the weird formatting that Slack requires. It copies much of the functionality of the [slack-notifier](https://github.com/stevenosloan/slack-notifier) gem, which is used internally.
|
29
|
+
|
30
|
+
Here's a very basic example of sending a message to slack:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
job 'send "Hello, World!" to #general'
|
13
34
|
|
14
|
-
|
15
|
-
|
35
|
+
slack do
|
36
|
+
message 'Hello, World!'
|
37
|
+
end
|
16
38
|
|
17
|
-
|
18
|
-
$ gem build pushpop-<plugin>.gemspec
|
19
|
-
$ gem push pushpop-<plugin>-0.1.0.gem
|
39
|
+
end
|
20
40
|
```
|
21
41
|
|
22
|
-
|
42
|
+
#### Links
|
43
|
+
|
44
|
+
We use slack-notifier's [`LinkFormatter`](https://github.com/stevenosloan/slack-notifier#links) internally. That means you can either use HTML or Markdown format for your links
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
job 'send "Hello, World!" to #general'
|
48
|
+
|
49
|
+
slack do
|
50
|
+
message 'Where [in the world](http://en.wikipedia.org/wiki/Carmen_Sandiego) is Carmen Sandiego?'
|
51
|
+
# or
|
52
|
+
message 'Have you seen this <a href="http://en.wikipedia.org/wiki/Carmen_Sandiego">in the world</a> is Carmen Sandiego?'
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
#### Setting the channel
|
59
|
+
|
60
|
+
Your webhook has a default channel that it sends to, but you can also choose a custom channel at runtime
|
61
|
+
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
job 'send "Hello, World!" to #general'
|
65
|
+
|
66
|
+
slack do
|
67
|
+
message 'Hello, World!'
|
68
|
+
channel '#alerts'
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
Slack expects the `#` before your channel name. However, if you forget it, pushpop-slack will insert it there for your convenience
|
75
|
+
|
76
|
+
#### Username
|
77
|
+
|
78
|
+
You can choose a custom username for your message to "come from". This can be a completely new username, or an existing one.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
job 'send "Hello, World!" to #general'
|
82
|
+
|
83
|
+
slack do
|
84
|
+
message 'Hello, World!'
|
85
|
+
username 'Carmen Sandiego'
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
```
|
90
|
+
|
91
|
+
#### Icon
|
92
|
+
|
93
|
+
You can also set the avatar/icon for the "user" sending the message. Paired with the [Username](#username), this can make your pushpop messages look like they're from a real user.
|
94
|
+
|
95
|
+
You can use emoji icons, or just use an image anywhere on the internet. For emoji, use the slack formatting (ie: `:ghost:`). For an image on the internet, just enter a URL (must start with `http`).
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
job 'send "Hello, World!" to #general'
|
99
|
+
|
100
|
+
slack do
|
101
|
+
message 'Hello, World!'
|
102
|
+
icon ':ghost:'
|
103
|
+
# or
|
104
|
+
icon 'https://upload.wikimedia.org/wikipedia/en/e/ed/Carmen_Sandiego.png'
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
110
|
+
#### Unfurl
|
111
|
+
|
112
|
+
By default, Slack does not [unfurl](https://api.slack.com/docs/unfurling) links from Webhooks (only media, like images). You can override that default by calling unfurl.
|
113
|
+
|
114
|
+
Calling `unfurl` with no parameter will default to true, or you can pass it a boolean.
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
job 'send "Hello, World!" to #general'
|
118
|
+
|
119
|
+
slack do
|
120
|
+
message 'Where [in the world](http://en.wikipedia.org/wiki/Carmen_Sandiego) is Carmen Sandiego?'
|
121
|
+
unfurl
|
122
|
+
# or
|
123
|
+
unfurl true
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
```
|
128
|
+
|
129
|
+
#### Attachments
|
130
|
+
|
131
|
+
You can send attachments over Slack as well. Attachments have a lot of options, so you have to pass in a pretty heavy configuration block. If you're going to use attachments, it's worth reading the slack-notifier [paramters docs](https://github.com/stevenosloan/slack-notifier#additional-parameters) and the Slack [Attachments Reference](https://api.slack.com/docs/attachments).
|
132
|
+
|
133
|
+
```
|
134
|
+
job do
|
135
|
+
|
136
|
+
slack do
|
137
|
+
|
138
|
+
first_attachment = {
|
139
|
+
fallback: 'This is the fallback',
|
140
|
+
pretext: 'Hey check out this attachment',
|
141
|
+
color: '#b0b0b0',
|
142
|
+
fields: [
|
143
|
+
{
|
144
|
+
title: 'Field Title',
|
145
|
+
value: 'This is the value of the first field!',
|
146
|
+
short: false
|
147
|
+
}
|
148
|
+
]
|
149
|
+
}
|
23
150
|
|
24
|
-
|
25
|
-
|
26
|
-
|
151
|
+
message 'Hello, World!'
|
152
|
+
attachment first_attachment
|
153
|
+
end
|
154
|
+
end
|
27
155
|
```
|
28
156
|
|
29
157
|
### Contributing
|
30
158
|
|
31
|
-
Code and documentation issues and pull requests are welcome.
|
32
|
-
useful as possible!
|
159
|
+
Code and documentation issues and pull requests are welcome.
|