GitLab integration not able to close JIRA issue when transition workflow has screen requiring resolution

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

Summary

When a JIRA transition workflow includes a screen requiring user to select resolution, the GitLab integration is unable to auto-transition the corresponding JIRA issue from a merge request.

This happens because the JIRA issue does not return any resolutions via API.

This was reported by a 50-seat premium customer via Zendesk (internal use only).

Steps to reproduce

  1. Create a screen with "Resolution" as a field.
  2. Edit Workflow Transition to add the screen to the Transition View
  3. Transitioning a JIRA issue now requires the user to select a Resolution
  4. Create a merge request with "Closes JIRA-1" in the description
  5. Merge the MR. JIRA issue is not closed.

Note: I have this set up reproduced in the WMTP project in the GitLab JIRA test instance.

What is the current bug behavior?

If this behaviour is intended:

  • The MR reports that the JIRA issue is closed when this is not the case, i.e. GitLab is aware that the JIRA issue cannot be closed but does not indicate this to the user

If this behaviour is not intended:

  • The JIRA issue is not transitioned

What is the expected correct behavior?

If this behaviour is intended:

  • The MR should give a warning that the JIRA issue cannot be closed as it does not have any available resolutions

If this behaviour is not intended:

  • The JIRA issue should be transitioned

Relevant logs and/or screenshots

ei = MergeRequest.last.closes_issues.last
project = MergeRequest.last.project
issue = project.jira_service.client.Issue.find(ei.iid)
issue.resolution

Here, with the reproduction set up above, issue.resolution returns nil. As a result, this conditional check fails and the JIRA issue is not closed.

I am able to use the API to manually transition the JIRA issue:

irb(main):025:0> issue.transitions.build.save!(transition: { id: 41 })
=> true

So it does not seem like the lack of resolutions should block the JIRA issue from being closed in all cases

I looked into the commit history for this and was able to find the following:

Commit 85dd05b5:

This is where a issue.resolution.present? check was first added. I was not able to discern the reason.

Commit 03d199fb:

This is where the resolution check was expanded and a test case added to ensure JiraService does not send comment or remote links to issues with unknown resolution. Again, I was not able to discern the reason.

Output of checks

This happens on GitLab 12.2.

Possible fixes

Remove the conditional check, or figure out when we should check this? https://gitlab.com/gitlab-org/gitlab/blob/v12.2.0-ee/app/models/project_services/jira_service.rb#L120

Background

GitLab closes Jira issues by calling the Transition Issue endpoint at https://gitlab.com/gitlab-org/gitlab/blob/67d8c854d8fec7ff9ed3580739e85743eb49291e/app/models/integrations/jira.rb#L340-342, and currently only passes the (configured or auto-detected) transition ID.

Depending on the configured Jira workflow, this also automatically sets the resolution ("Completed" here is the status, "Done" the resolution):

image

But when the workflow requires explicitly passing a resolution, it's not set, and we don't post the "Issue solved" comment at https://gitlab.com/gitlab-org/gitlab/blob/67d8c854d8fec7ff9ed3580739e85743eb49291e/app/models/integrations/jira.rb#L237.

Proposal

Manual configuration

  • Add a new field Custom resolution in the Jira integration settings.

    • Users can enter the name of a resolution here (e.g. Fixed).
    • By default this field is blank, to preserve the current behaviour.
  • If set, we also pass this value along to the Transition Issue endpoint as part of the fields::

    "fields": { "resolution": { "name": "Fixed" } }

Auto-detection

In a future iteration we could also implement auto-detection, similar to the one for transition IDs at https://gitlab.com/gitlab-org/gitlab/blob/67d8c854d8fec7ff9ed3580739e85743eb49291e/app/models/integrations/jira.rb#L334-336.

Edited by 🤖 GitLab Bot 🤖