Mark stories done if tasks are completed

The following flow demonstrates how to check if a user story's tasks are completed, and if so, mark the user story as done.

Entity relationship diagram

We need to access the following entities for this flow, and understand the relationships between these entities.

Entity relationship diagram for marking stories done if tasks are completed.

The following shows the relations in the flow.

Entity Relationships in this flow Description of relationship Reference / relationship fields
Work items Epics, features, defects, quality stories, and user stories This aggregate resource collection represents types of work items, including epics, features, defects, user stories, and quality stories. subtype
Work items Tasks Work items can be associated with tasks. child_task
Tasks Work items

Tasks must be associated with one user story, quality story, or defect. User stories, quality stories, and defects are work items.

Tasks cannot be associated with other work items, such as epics and features.

User stories, quality stories, and defects can be associated with multiple tasks.

stories

defects

Tasks Phases Tasks must be associated with a phase. phase
Tasks Users Tasks must have one owner. owner
Tasks Attachments Tasks can have attachments. attachments
Epics Work items

Epics are subtypes of work_items.

There is no field that relates back to the aggregate resource collection, work_items.

None
Epics Features

Epics can be associated with features.

None
Features Work items

Features are subtypes of work_items.

There is no field that relates back to the aggregate resource collection, work_items.

None
Features

Epics

Features can be associated with epics.

parent
Features

Stories, and defects

Features can be associated with user stories, quality stories, and defects.

None
User Stories Work items

User stories are subtypes of work_items.

There is no field that relates back to the aggregate resource collection, work_items.

None
User Stories Features

User stories can be associated with features.

parent
User Stories Defects

User stories can be associated with defects.

None
User Stories Tasks

User stories can be associated with tasks.

story
Quality Stories Work items

Quality stories are subtypes of work_items.

There is no field that relates back to the aggregate resource collection, work_items.

None
Quality Stories Features

Quality stories can be associated with features.

parent
Quality Stories Defects

Quality stories can be associated with defects.

None
Quality Stories Tasks

Quality stories can be associated with tasks.

story
Defects Work items

Defects are subtypes of work_items.

There is no field that relates back to the aggregate resource collection, work_items.

None
Defects Features

Defects can be associated with features.

parent
Defects User stories and quality stories

Defects can be associated with user stories and quality stories.

None
Defects Tasks

Defects can be associated with tasks.

defect
Phases Features, user stories, quality stories, and defects Features, stories, and defects must be associated with a phase. phase
Users All work items Epics, features, use stories, quality stories, and defects can be associated with an owner. owner

Back to top

Flow

Let's create the REST API call step-by-step.

  1. We want to see all stories that are still in-progress.

    To do this, we enter a query clause that lists only those work items whose subtype is story and whose phase is still in progress. Phase is a reference field, and we find the phase by id.

    We use the fields clause to control which fields are returned by the API call. Not all fields are returned automatically, so here we are going to be specific.  We want to see if any of the in-progress stories are associated with tasks, so we make sure to add tasks_number to our list of fields.

    GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/work_items?fields=phase,release,name,id,tasks_number,subtype&query="(subtype EQ ^story^;phase EQ {id EQ ^phase.story.inprogress^})"

  2. For each story, we will check if the corresponding tasks are done.

    Here, we are checking the task corresponding to story 1019, because the previous API call showed that this story has one task, 1002, associated with it.

    This example also demonstrates the use of reference fields. We use the story reference field using the id to specify the story.

    GET .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/tasks?query="(story EQ {id EQ ^1019^ } )"

  3. After looking at the response, we see that task 1002 did complete. We can now update the phase of the corresponding story, 1019, to done.

    PUT .../api/shared_spaces/<space_id>/workspaces/<workspace_id>/work_items//1019/

    Payload 

    {
       "phase":{ 
            "type":"phase",
            "id":"phase.story.done"
           },
       "id":"1019"
    }

Back to top

See also: