Search for Jira Issues with Ease Using Jql Builder

jql-builder is a package that provides an expressive way to create Jira Query Language (Jql) to use it with jira search.

Installation

composer require devmoath/jql-builder

Usage

This is how to generate a simple query:

use JqlBuilder\Jql;

$query = (new Jql)->where('project', 'MY PROJECT');

echo $query;

The result is:

project = "MY PROJECT"

And this is more complex query:

use JqlBuilder\Jql;

$query = (new Jql)->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;

The result is:

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');

echo $query;

The result is:

custom = "1"

Finally, of course the package have laravel support out of the box:

use JqlBuilder\Facades\Jql;

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

echo $query;

The result is:

summary = "value"