forked from deployphp/deployer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ms-teams.php
135 lines (113 loc) · 3.47 KB
/
ms-teams.php
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
/*
## Installing
Require ms-teams recipe in your `deploy.php` file:
Setup:
1. Open MS Teams
2. Navigate to Teams section
3. Select existing or create new team
4. Select existing or create new channel
5. Hover over channel to get three dots, click, in menu select "Connectors"
6. Search for and configure "Incoming Webhook"
7. Confirm/create and copy your Webhook URL
8. Setup deploy.php
Add in header:
```php
require 'contrib/ms-teams.php';
set('teams_webhook', 'https://outlook.office.com/webhook/...');
```
Add in content:
```php
before('deploy', 'teams:notify');
after('deploy:success', 'teams:notify:success');
after('deploy:failed', 'teams:notify:failure');
```
9.) Sip your coffee
## Configuration
- `teams_webhook` – teams incoming webhook url, **required**
```
set('teams_webhook', 'https://outlook.office.com/webhook/...');
```
- `teams_title` – the title of application, default `{{application}}`
- `teams_text` – notification message template, markdown supported
```
set('teams_text', '_{{user}}_ deploying `{{branch}}` to *{{target}}*');
```
- `teams_success_text` – success template, default:
```
set('teams_success_text', 'Deploy to *{{target}}* successful');
```
- `teams_failure_text` – failure template, default:
```
set('teams_failure_text', 'Deploy to *{{target}}* failed');
```
- `teams_color` – color's attachment
- `teams_success_color` – success color's attachment
- `teams_failure_color` – failure color's attachment
## Usage
If you want to notify only about beginning of deployment add this line only:
```php
before('deploy', 'teams:notify');
```
If you want to notify about successful end of deployment add this too:
```php
after('deploy:success', 'teams:notify:success');
```
If you want to notify about failed deployment add this too:
```php
after('deploy:failed', 'teams:notify:failure');
```
*/
namespace Deployer;
use Deployer\Utility\Httpie;
// Title of project
set('teams_title', function () {
return get('application', 'Project');
});
// Deploy message
set('teams_text', '_{{user}}_ deploying `{{branch}}` to *{{target}}*');
set('teams_success_text', 'Deploy to *{{target}}* successful');
set('teams_failure_text', 'Deploy to *{{target}}* failed');
// Color of attachment
set('teams_color', '#4d91f7');
set('teams_success_color', '#00c100');
set('teams_failure_color', '#ff0909');
desc('Notifies Teams');
task('teams:notify', function () {
if (!get('teams_webhook', false)) {
warning('No MS Teams webhook configured');
return;
}
Httpie::post(get('teams_webhook'))->jsonBody([
"themeColor" => get('teams_color'),
'text' => get('teams_text')
])->send();
})
->once()
->hidden();
desc('Notifies Teams about deploy finish');
task('teams:notify:success', function () {
if (!get('teams_webhook', false)) {
warning('No MS Teams webhook configured');
return;
}
Httpie::post(get('teams_webhook'))->jsonBody([
"themeColor" => get('teams_success_color'),
'text' => get('teams_success_text')
])->send();
})
->once()
->hidden();
desc('Notifies Teams about deploy failure');
task('teams:notify:failure', function () {
if (!get('teams_webhook', false)) {
warning('No MS Teams webhook configured');
return;
}
Httpie::post(get('teams_webhook'))->jsonBody([
"themeColor" => get('teams_failure_color'),
'text' => get('teams_failure_text')
])->send();
})
->once()
->hidden();