devmoath/jql-builder

Simple JQL builder for Jira search

v0.0.3 2021-09-20 10:15 UTC

README

logo

Jql Builder

Latest Version on Packagist Packagist Downloads Tests Workflow Status phpstan Workflow Status php-cs-fixer Workflow Status

Simple JQL builder for Jira search

Installation

composer require devmoath/jql-builder

Usage

Generate query with one condition:

use JqlBuilder\Jql;

Jql::query()
    ->whereProject('MY PROJECT')
    ->getQuery(); // "project = 'MY PROJECT'"

// Or just cast it to string
(string) Jql::query()
    ->whereProject('MY PROJECT'); // "project = 'MY PROJECT'"

Generate query with many conditions:

use JqlBuilder\Jql;

Jql::query()
    ->whereProject('MY PROJECT')
    ->whereIssueType('support')
    ->whereStatus(['wip', 'created'], 'in')
    ->getQuery(); // "project = 'MY PROJECT' and issuetype = 'support' and status in ('wip', 'created')"

Generate query with many conditions and order by:

use JqlBuilder\Jql;

Jql::query()
    ->whereProject('MY PROJECT')
    ->whereIssueType('support')
    ->whereStatus(['wip', 'created'], 'in')
    ->orderBy('created', 'asc')
    ->getQuery(); // "project = 'MY PROJECT' and issuetype = 'support' and status in ('wip', 'created') order by created asc"

generate query with custom filed conditions:

use JqlBuilder\Jql;

Jql::query()
    ->where('customfild_111', '=', 'value')
    ->where('customfild_222', '=', 'value')
    ->getQuery(); // "customfild_111 = 'value' and customfild_222 = 'value'"

generate query conditions based on your condition:

use JqlBuilder\Jql;

Jql::query()
    ->when('MY PROJECT', fn (Jql $builder, $value) => $builder->whereProject($value))
    // or you can use callback 
    ->when(fn (Jql $builder) => false, fn (Jql $builder, $value) => $builder->whereIssueType($value))
    ->getQuery(); // "project = 'MY PROJECT'"

generate query using raw query:

use JqlBuilder\Jql;

Jql::query()
    ->rawQuery("project = 'MY PROJECT' order by created asc")
    ->getQuery(); // "project = 'MY PROJECT' order by created asc"

Also, you can add macro functions as well:

use JqlBuilder\Jql;

$builder = new Jql;

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

$builder->whereCustom('1')->getQuery(); // "custom = '1'"

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.