hanoii/platformsh2slack

Platform.sh -> Slack incoming webhook adapter.

Installs: 11 650

Dependents: 0

Suggesters: 0

Security: 0

Stars: 20

Watchers: 6

Forks: 5

Open Issues: 5

Type:project

1.9 2022-06-05 03:29 UTC

This package is auto-updated.

Last update: 2024-10-05 08:43:48 UTC


README

This is a simple php script that translates Platform.sh webhook into a Slack formatted message.

You can install this in your php app container and host it there for your project's specific webhooks.

Sponsored by Infomagnet - builds websites to any design using Drupal.

slack-example

Installation

You can install the package using the Composer package manager. You can install it by running this command in your project root:

composer require hanoii/platformsh2slack

Then create an incoming webhook on your Slack account for the package to use. You'll need the webhook URL to instantiate the adapter.

Basic Usage

<?php

// Optional settings
$settings = [
  'channel' => '#random',
  'project' => 'Some project',
  // Environment will be appended to the URL
  'project_url' => 'https://console.platform.sh/USER/PROJECTID',
];

$platformsh2slack = new Hanoii\Platformsh2Slack\Platformsh2Slack(
  'https://hooks.slack.com/...',
  $settings
);

// Optionally protect the request with a token that has to be present in the Platform.sh webhook
$platformsh2slack->validateToken('1234');

// Send the information to slack
$platformsh2slack->send();

Platform.sh build hook

If your application (.platform.app.yaml) is already being built with composer:

build:
    flavor: composer

You can simply add:

    "hanoii/platformsh2slack": "^1.0"

To your composer.json file of the project and create a small script as per above.

If not, you will have to add a script to the repository and run composer install on your build hook manually.

Settings

Token

This is an optional feature you can choose to use on the script. It's a nice simple validation so that you script is not abused.

If you added:

$platformsh2slack->validateToken('1234');

to your script, you will have to append the token the Platform.sh's webhook integration URL.

Add the integration on platform

Run the following:

platform integration:add --type=webhook --url="https://www.example.com/platformsh2slack.php?token=TOKEN"

Environoments

You can have this script on any environment, even master. As far as my trials went, even pushing to master works.