Skip to content

Add autoClosedByClosingMergeRequests field to work items API

Mario Celi requested to merge 470440-add-auto-close-enabled-field into master

What does this MR do and why?

Added willAutoCloseByMergeRequest to work items development widget. Field indicates if the work item will be closed when the listed merge requests in closingMergeRequests are merged (if any of them are open). This can be disabled at the project level but not for group level work items.

DB review

Query executed with the issue record that has the most associated merge_requests_closing_issues records.

When no open merge request is associated (worst case scenario as it scans all possible records)

Query returns 0 rows

https://console.postgres.ai/gitlab/gitlab-production-main/sessions/29783/commands/92519
SELECT 
  1 AS one 
FROM 
  "merge_requests_closing_issues" 
  INNER JOIN "merge_requests" ON "merge_requests"."id" = "merge_requests_closing_issues"."merge_request_id" 
WHERE 
  "merge_requests_closing_issues"."issue_id" = 88515414 
  AND "merge_requests"."state_id" = 1 
LIMIT 
  1

When at least one open merge request is associated (we limit to 1 anyway so all it's needed)

Query returns 1 row (created a matching record to get the plans)

https://console.postgres.ai/gitlab/gitlab-production-main/sessions/29783/commands/92521
SELECT 
  1 AS one 
FROM 
  "merge_requests_closing_issues" 
  INNER JOIN "merge_requests" ON "merge_requests"."id" = "merge_requests_closing_issues"."merge_request_id" 
WHERE 
  "merge_requests_closing_issues"."issue_id" = 88515414 
  AND "merge_requests"."state_id" = 1 
LIMIT 
  1

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

How to set up and validate locally

  1. Make sure autoclose issues is enabled in the project in Settings -> Repository -> Branch defaults -> Auto-close referenced issues on default branch
  2. Use the closing pattern in a merge request description. Example Closes #21 where 21 is the IID of an issue
  3. Use the following GraphQL query where 825 is the ID of the referenced issue (the one from the issues.id column)
{
  workItem(id: "gid://gitlab/WorkItem/825") {
    widgets {
      type
      ... on WorkItemWidgetDevelopment {
        willAutoCloseByMergeRequest
        closingMergeRequests {
          nodes {
            id
            mergeRequest {
              id
              iid
            }
          }
        }
      }
    }
  }
}

willAutoCloseByMergeRequest should return true only if the work item is open, the project setting is enabled and at least 1 merge request returned in closingMergeRequests is still open. Should return false otherwise

Related to #470440 (closed) Closes #470440 (closed)

Edited by Mario Celi

Merge request reports