Ejemplo n.º 1
0
        private async Task UpdateParentState(
            AdoWebHookMessage message,
            WorkItemState state,
            bool allChildrenMustBeInState  = true,
            WorkItemState?checkSourceState = null,
            bool recursive = false)
        {
            if (!message.IsChangeToState(state))
            {
                return;
            }

            var id = message.WorkItemId();

            while (id > 0)
            {
                string reason = string.Format("{0} state rule", state);
                logger.LogInformation("Executing {0} for work item {1}", reason, id);

                var parent = await GetParentWorkItem(id);

                bool updateParent = true;
                if (parent != null && allChildrenMustBeInState)
                {
                    var allChildren = GetChildrenWorkItems(parent).Select(ac => ac.Result);
                    logger.LogTrace("Parent work item {0} has {1} children", parent?.Id, allChildren.Count());

                    updateParent = allChildren.All(c => c.GetState() == state.ToString());
                }

                logger.LogTrace("Parent work item {0} in state {1}", parent?.Id, parent.GetState());
                if (updateParent && parent != null && (!checkSourceState.HasValue || parent.IsInState(checkSourceState.Value)))
                {
                    await UpdateWorkItemState(parent.Id.GetValueOrDefault(), state.ToString(), reason);
                }

                id = (recursive && parent != null) ? parent.Id.GetValueOrDefault() : 0;
            }
        }
Ejemplo n.º 2
0
 private static AdoWebHookMessage GenerateUpdatedMessage(int workItemId, WorkItemState oldState, WorkItemState active)
 {
     return(new AdoWebHookMessage()
     {
         eventType = "workitem.updated",
         resource = new Resource()
         {
             workItemId = workItemId,
             fields = new Fields()
             {
                 SystemState = new StringChange()
                 {
                     oldValue = oldState.ToString(),
                     newValue = active.ToString(),
                 }
             }
         }
     });
 }
Ejemplo n.º 3
0
 public static bool IsChangeToState(this AdoWebHookMessage message, WorkItemState state)
 {
     return
         (message.IsStateChange() &&
          message?.resource?.fields?.SystemState.newValue == state.ToString());
 }
Ejemplo n.º 4
0
 public static bool IsInState(this WorkItem workItem, WorkItemState state)
 {
     return(GetState(workItem) == state.ToString());
 }