Coder Social home page Coder Social logo

stichoza / jira-webhooks-data Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kommuna/jirawebhook

0.0 1.0 0.0 152 KB

๐Ÿ—‚๏ธ Data structures for Atlassian Jira WebHook

License: The Unlicense

PHP 100.00%
atlassian events jira webhook webhooks

jira-webhooks-data's Introduction

Jira Webhooks Data

Latest Stable Version Total Downloads Downloads Month Petreon donation PayPal donation

This is PHP library for processing and handling Atlassian Jira webhook data.

If you're looking for the Laravel package with events and routes, check out stichoza/jira-webhooks-laravel package that includes this package as data structures.

Note: This package was originally forked from kommuna/jirawebhook which is meant to be used with the kommuna/vicky and has support of League events and message converters. This package, on the other hand, is a separate package because the whole structure is rewritten to the point that it's no longer compatible with the original repo. Kudos to the developers of the original package!

Installation

Install this package via Composer:

composer require stichoza/jira-webhook-data

Usage

// Example payload received from Jira webhook
$data = [
    "timestamp" => 1629835026055,
    "webhookEvent" => "jira:issue_updated",
    // ... other webhook data ...
    "issue" => [
        // ... issue data ...
    ],
    "changelog" => [
        // ... changelog data ...
    ],
    // ... other data ...
];

Create an instance of JiraWebhookData:

use Stichoza\JiraWebhooksData\Models\JiraWebhookData;

$webhookData = new JiraWebhookData($data);

Now you can access the parsed data from the webhook:

$message = 'New comment by ' . $webhookData->comment->author->displayName
    . ' on issue ' . $webhookData->issue->key;
    . ': ' . $webhookData->comment->body;

More properties listed below:

$timestamp = $webhookData->timestamp;
$webhookEvent = $webhookData->webhookEvent;
$issueEvent = $webhookData->issueEvent;
$user = $webhookData->user; // JiraUser instance
$issue = $webhookData->issue; // JiraIssue instance
$changelog = $webhookData->changelog; // JiraChangelog instance
$worklog = $webhookData->worklog; // JiraWorklog instance

Access specific properties from the JiraIssue instance

$issueId = $issue->id;
$issueKey = $issue->key;
$issueTypeName = $issue->issueTypeName;
$priorityName = $issue->priorityName;

Access specific properties from the JiraUser instance

if ($user) {
    $userAccountId = $user->accountId;
    $userDisplayName = $user->displayName;
    // ... and other properties ...
}

Access specific properties from the JiraChangelog instance

$changelogId = $changelog->id;
$changelogItems = $changelog->items; // Array of JiraChangelogItem instances
// ... and other properties ...

You can also perform additional checks or operations based on the parsed data

if ($issue && $issue->isStatusResolved()) {
    // Do something for resolved issues
}

if ($user && $user->active) {
    // Do something for active users
}

Read more about properties and methods in the src/Models folder.

Error Handling

Object constructors will throw a Stichoza\JiraWebhooksData\Exceptions\JiraWebhookDataException exception when incorrect or insufficient data is provided. Make sure you wrap your code in try-catch block.

use Stichoza\JiraWebhooksData\Models\JiraWebhookData;
use Stichoza\JiraWebhooksData\Exceptions\JiraWebhookDataException;

try {
    $webhookData = new JiraWebhookData($data);
} catch (JiraWebhookDataException $e) {
    // Handle the error
}

Also keep in mind that certain properties will not be present in response depending on the Jira event. Make sure you check that objects/properties are not null.

$to = $webhookData->issue?->assignee?->email;

if ($to !== null) {
    // Do something
}

jira-webhooks-data's People

Contributors

alebedev80 avatar chewbacca96 avatar elenakolevska avatar kommuna avatar l80 avatar stichoza avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.