badoo / jira-client

Badoo JIRA API Client with code generator
GNU General Public License v3.0
66 stars 19 forks source link

Bad transition update fields logic #23

Open alpoprosi opened 3 years ago

alpoprosi commented 3 years ago

Hi!

In IssueTransition::get method returns first element of transitions info, and its very uncomfortable to use IssueTransition::do_safe method?

How it works now:

public function do_safe(string $issue_key, int $transition_id, array $fields = [], array $update = []) : void
    {
        $TransitionInfo = $this->get($issue_key, $transition_id, true);

        foreach ($fields as $field_id => $value) {
            if (!isset($TransitionInfo->fields->{$field_id})) {
                unset($fields[$field_id]);
            }
        }

        foreach ($update as $field_id => $value) {
            if (!isset($TransitionInfo->fields->{$field_id})) {
                unset($update[$field_id]);
            }
        }

        $this->do($issue_key, $transition_id, $fields, $update);
    }

public function get(string $issue_key, int $transition_id, bool $expand_fields = false) : \stdClass
    {
        $args = [
            'transitionId' => $transition_id,
        ];

        if ($expand_fields) {
            $args = ['expand' => 'transitions.fields'];
        }

        $transitions = $this->Jira->get("/issue/{$issue_key}/transitions", $args)->transitions;

        if (empty($transitions)) {
            $user = $this->Jira->getLogin();
            throw new \Badoo\Jira\REST\Exception(
                "Transition '{$transition_id}' of '{$issue_key}' is not available for '{$user}' in current issue status"
            );
        }

        return $transitions[0];
    }

As you can see the get method returns first element but there can be more than one. And now I had situation where I need the second element cause it contains transition_id I do and "fields" I need.

Would you fix it please?