Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bad transition update fields logic #23

Open
alpoprosi opened this issue Aug 31, 2021 · 0 comments
Open

Bad transition update fields logic #23

alpoprosi opened this issue Aug 31, 2021 · 0 comments

Comments

@alpoprosi
Copy link

alpoprosi commented Aug 31, 2021

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?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant