Add API to query work item lifecycles for a namespace
What does this MR do and why?
As part of the configurable work item statuses initiative, this MR introduces a GraphQL API to fetch work item lifecycles for a given namespace.
The API works with both system-defined and custom lifecycles and uses the newly introduced read_lifecycle
policy.
Notes
Fetching lifecycles for a given namespace requires the read_lifecycle
permission (that reuses the read_work_item
rules), the relevant feature flag to be enabled, and an active work_item_status
license feature.
Since system-defined lifecycles and statuses are global and not tied to a specific namespace, authorization needs to be handled at the resolver level (not at the type level), where we have access to the namespace, its feature flags, and license details.
References
- BE: Implement lifecycle and status management APIs
- BE: Query lifecycle
- Work Items Custom Status Design Doc
- Configurable Work Item Statuses Epic
Screenshots or screen recordings
With system-defined statuses
With custom statuses
How to set up and validate locally
- Enable the
work_item_status_feature_flag
feature flag. - Use the query below to fetch system-defined statuses defined for a given namespace.
View query
query getLifecycles {
namespace(fullPath: "flightjs") {
id
lifecycles {
nodes {
id
name
defaultOpenStatus {
id
name
}
defaultClosedStatus {
id
name
}
defaultDuplicateStatus {
id
name
}
workItemTypes {
id
name
}
statuses {
id
name
iconName
color
}
}
}
}
}
- To fetch custom statuses defined for a given namespace, follow the steps below before running the query again. I'd recommend using a separate namespace for custom statuses. Once you switch to custom statuses, there's no way back to system-defined statuses.
View instructions
- Find a namespace
project = Project.find(7) # flightjs/Flight
namespace = project.root_ancestor
- Create custom statuses for a given namespace
open_status = WorkItems::Statuses::Custom::Status.create!(
namespace: namespace,
name: "Custom to do",
color: "#737278",
category: :to_do
)
closed_status = WorkItems::Statuses::Custom::Status.create!(
namespace: namespace,
name: "Custom done",
color: "#108548",
category: :done
)
duplicate_status = WorkItems::Statuses::Custom::Status.create!(
namespace: namespace,
name: "Custom duplicate",
color: "#DD2B0E",
category: :cancelled
)
- Create a custom lifecycle with default statuses
lifecycle = WorkItems::Statuses::Custom::Lifecycle.create!(
namespace: namespace,
name: "Engineering",
default_open_status: open_status,
default_closed_status: closed_status,
default_duplicate_status: duplicate_status
)
- Associate task and issue work item types with the lifecycle (namespace is automatically populated)
issue_type = WorkItems::Type.find_by(base_type: :issue)
type_custom_lifecycle = WorkItems::TypeCustomLifecycle.create!(
work_item_type: issue_type,
lifecycle: lifecycle
)
task_type = WorkItems::Type.find_by(base_type: :task)
type_custom_lifecycle = WorkItems::TypeCustomLifecycle.create!(
work_item_type: task_type,
lifecycle: lifecycle
)
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.