2017 © Pedro Peláez
 

library jirawebhook

PHP classes for Atlassian Jira webhook data structure with events

image

kommuna/jirawebhook

PHP classes for Atlassian Jira webhook data structure with events

  • Wednesday, September 13, 2017
  • by kommuna
  • Repository
  • 3 Watchers
  • 3 Stars
  • 106 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 7 Versions
  • 1 % Grown

The README.md

What is this?

This is PHP library for processing and handling Atlassian JIRA webhook data., (*1)

It contains classes that can parse data from JIRA webhooks, create listeners for custom events and interface for creating converters for parsed data., (*2)

The package is meant to be used with the Vicky slackbot, but it can also be used independently., (*3)

Installation

With composer, create a new composer.json file and add the following code:, (*4)

{
    "minimum-stability" : "dev",
    "require": {
        "kommuna/jirawebhook": "dev-master"
    }
}

Then run command composer install., (*5)

Usage

JIRA data events

To create a new event use following example code:, (*6)

use JiraWebhook\JiraWebhook;
use JiraWebhook\Models\JiraWebhookData;

require __DIR__.'/vendor/autoload.php';
$config = require '/etc/vicky/config.php';

$jiraWebhook = new JiraWebhook();

$jiraWebhook->addListener('jira:event_name', function($e, $data)
{
    /**
     * Your code here
     */ 
});

try {
    $f = fopen('php://input', 'r');
    $data = stream_get_contents($f);

    if (!$data) {
        throw new JiraWebhookException('There is no data in the Jira webhook');
    }

    $jiraWebhook->run();
} catch (\Exception $e) {
     error_log($e->getMessage());
}

JIRA data converters

To create a new converter create a new class that implements the JiraWebhookDataConverter interface. Then to set and use a new converter use the following example code:, (*7)

use JiraWebhook\JiraWebhookDataConverter;
use JiraWebhook\Models\JiraWebhookData;

class NewConverterClass implements JiraWebhookDataConverter
{
    public function convert(JiraWebhookData $data)
    {
        $issue        = $data->getIssue();
        $assigneeName = $issue->getAssignee()->getName();
        $comment      = $issue->getIssueComments()->getLastComment();

        $message = vsprintf(
            ":no_entry_sign: <%s|%s> %s: %s ➠ @%s\n@%s ➠ %s",
            [
                $issue->getUrl(),
                $issue->getKey(),
                $issue->getStatusName(),
                $issue->getSummary(),
                $assigneeName,
                $comment->getAuthor()->getName(),
                $comment->getBody(0, 178)
            ]
        );

        return $message;
    }
}

JiraWebhook::setConverter('converterName', new NewConverterClass());
$message = JiraWebhook::convert('converterName', $data);

Please refer to Slack's documentation for message formatting for more details., (*8)

Testing

Run vendor/bin/phpunit or just phpunit if you have it installed globally., (*9)

The Versions

13/09 2017

dev-master

9999999-dev https://github.com/kommuna/jirawebhook

PHP classes for Atlassian Jira webhook data structure with events

  Sources   Download

Unlicense

The Requires

 

The Development Requires

reflection atlassian jira webhook

12/09 2017

dev-TL-80

dev-TL-80 https://github.com/kommuna/jirawebhook

PHP classes for Atlassian Jira webhook data structure with events

  Sources   Download

Unlicense

The Requires

 

The Development Requires

reflection atlassian jira webhook

26/07 2017

dev-TL-83

dev-TL-83 https://github.com/kommuna/jirawebhook

PHP classes for Atlassian Jira webhook data structure with events

  Sources   Download

Unlicense

The Requires

 

The Development Requires

reflection atlassian jira webhook

02/06 2017

dev-TL-76

dev-TL-76 https://github.com/kommuna/jirawebhook

PHP classes for Atlassian Jira webhook data structure with events

  Sources   Download

Unlicense

The Requires

 

The Development Requires

reflection atlassian jira webhook

12/05 2017

dev-TL-48

dev-TL-48 https://github.com/kommuna/jirawebhook

PHP classes for Atlassian Jira webhook data structure with events

  Sources   Download

Unlicense

The Requires

 

The Development Requires

reflection atlassian jira webhook

27/03 2017

1.0.1

1.0.1.0 https://github.com/kommuna/jirawebhook

PHP classes for Atlassian Jira webhook data structure with events

  Sources   Download

Unlicense

The Requires

 

The Development Requires

reflection atlassian jira webhook

27/03 2017

1.0.0

1.0.0.0 https://github.com/kommuna/jirawebhook

PHP classes for Atlassian Jira webhook data structure with events

  Sources   Download

Unlicense

The Requires

 

The Development Requires

reflection atlassian jira webhook