devmoath/jql-builder

JQL builder is a supercharged PHP package that allows you to create Jira Query Language (JQL)

v1.4.0 2023-01-04 15:28 UTC

This package is auto-updated.

Last update: 2023-01-13 18:15:43 UTC


README

JQL Builder

GitHub Workflow Status (master) Total Downloads Latest Version License

JQL builder is a supercharged PHP package that allows you to create Jira Query Language (JQL).

Get Started

Requires PHP 8.0+

First, install devmoath/jql-builder via the Composer package manager:

composer require devmoath/jql-builder

Then, interact with JQL builder:

$query = new Jql();

$query->where('project', 'PROJECT')->where('summary', '~', 'title');

echo $query; // 'project = "PROJECT" and summary ~ "title"'

Usage

This is how to generate query:

use JqlBuilder\Jql;

$builder = new Jql();

// Simple query
$query = $builder->where('project', 'MY PROJECT')->getQuery();

echo $query;
// 'project = "MY PROJECT"'

$builder = new Jql();

// Complex query
$query = $builder->where('project', 'MY PROJECT')
    ->where('status', ['New', 'Done'])
    ->orWhere('summary', '~', 'sub-issue for "TES-xxx"')
    ->orWhere('labels', 'support')
    ->when(false, fn (Jql $builder, mixed $value) => $builder->where('creator', 'admin'))
    ->when(true, fn (Jql $builder, mixed $value) => $builder->where('creator', 'guest'))
    ->orderBy('created', 'asc')
    ->getQuery();

echo $query;
// 'project = "MY PROJECT" and status in ("New", "Done") or summary ~ "sub-issue for \"TES-xxx\"" or labels = "support" and creator = "guest" order by created asc'

Also, you can add macro functions as well to encapsulate your logic:

use JqlBuilder\Jql;

$builder = new Jql();

$builder::macro('whereCustom', function (mixed $value) {
    /*
     * your code...
     */
    
    /** @var Jql $this */
    return $this->where('custom', $value);
});

$query = $builder->whereCustom('1')->getQuery();

echo $query;
// 'custom = "1"'

laravel facade support out of the box:

use JqlBuilder\Facades\Jql;

$query = Jql::where('summary', '=', 'value')->getQuery();

echo $query;
// 'summary = "value"'

JQL builder is an open-sourced software licensed under the MIT license.