deployer/contrib/yammer.php

122 lines
3.2 KiB
PHP
Raw Normal View History

2020-04-25 23:00:08 +03:00
<?php
2020-10-02 00:11:13 +02:00
/*
Add hook on deploy:
```php
before('deploy', 'yammer:notify');
```
## Configuration
- `yammer_url` The URL to the message endpoint, default is https://www.yammer.com/api/v1/messages.json
- `yammer_token` *(required)* Yammer auth token
- `yammer_group_id` *(required)* - Group ID
- `yammer_title` the title of application, default `{{application}}`
- `yammer_body` notification message template, default:
```
<em>{{user}}</em> deploying {{branch}} to <strong>{{target}}</strong>
```
- `yammer_success_body` success template, default:
```
Deploy to <strong>{{target}}</strong> successful
```
- `yammer_failure_body` failure template, default:
```
Deploy to <strong>{{target}}</strong> failed
```
2020-04-25 23:00:08 +03:00
2020-10-02 00:11:13 +02:00
## Usage
If you want to notify only about beginning of deployment add this line only:
```php
before('deploy', 'yammer:notify');
```
If you want to notify about successful end of deployment add this too:
```php
2020-10-29 23:16:36 +01:00
after('deploy:success', 'yammer:notify:success');
2020-10-02 00:11:13 +02:00
```
If you want to notify about failed deployment add this too:
```php
after('deploy:failed', 'yammer:notify:failure');
```
*/
2020-04-25 23:00:08 +03:00
namespace Deployer;
use Deployer\Utility\Httpie;
set('yammer_url', 'https://www.yammer.com/api/v1/messages.json');
// Title of project
set('yammer_title', function () {
return get('application', 'Project');
});
// Deploy message
set('yammer_body', '<em>{{user}}</em> deploying {{branch}} to <strong>{{target}}</strong>');
set('yammer_success_body', 'Deploy to <strong>{{target}}</strong> successful');
set('yammer_failure_body', 'Deploy to <strong>{{target}}</strong> failed');
2021-11-08 22:59:39 +01:00
desc('Notifies Yammer');
2020-04-25 23:00:08 +03:00
task('yammer:notify', function () {
$params = [
'is_rich_text' => 'true',
'message_type' => 'announcement',
'group_id' => get('yammer_group_id'),
'title' => get('yammer_title'),
'body' => get('yammer_body'),
];
Httpie::post(get('yammer_url'))
2021-11-07 10:49:16 +01:00
->header('Authorization', 'Bearer ' . get('yammer_token'))
->header('Content-type', 'application/json')
->jsonBody($params)
2020-04-25 23:00:08 +03:00
->send();
})
->once()
->hidden();
2021-11-08 22:59:39 +01:00
desc('Notifies Yammer about deploy finish');
2020-04-25 23:00:08 +03:00
task('yammer:notify:success', function () {
$params = [
'is_rich_text' => 'true',
'message_type' => 'announcement',
'group_id' => get('yammer_group_id'),
'title' => get('yammer_title'),
'body' => get('yammer_success_body'),
];
Httpie::post(get('yammer_url'))
2021-11-07 10:49:16 +01:00
->header('Authorization', 'Bearer ' . get('yammer_token'))
->header('Content-type', 'application/json')
->jsonBody($params)
2020-04-25 23:00:08 +03:00
->send();
})
->once()
->hidden();
2021-11-08 22:59:39 +01:00
desc('Notifies Yammer about deploy failure');
2020-04-25 23:00:08 +03:00
task('yammer:notify:failure', function () {
$params = [
'is_rich_text' => 'true',
'message_type' => 'announcement',
'group_id' => get('yammer_group_id'),
'title' => get('yammer_title'),
'body' => get('yammer_failure_body'),
];
Httpie::post(get('yammer_url'))
2021-11-07 10:49:16 +01:00
->header('Authorization', 'Bearer ' . get('yammer_token'))
->header('Content-type', 'application/json')
->jsonBody($params)
2020-04-25 23:00:08 +03:00
->send();
})
->once()
->hidden();