예제 #1
0
        public async Task UpdateClosedState(AdoWebHookMessage message)
        {
            if (!message.IsChangeToClosed())
            {
                return;
            }

            const string reason = "closed state rule";

            logger.LogInformation("Executing {0} for work item {1}", reason, message.WorkItemId());

            var parent = await GetParentWorkItem(message.WorkItemId());

            var allChildren = GetChildrenWorkItems(parent).Select(ac => ac.Result);

            logger.LogTrace("Parent work item {0} has {1} children", parent?.Id, allChildren.Count());

            if (allChildren
                .All(c => c.GetState() == WorkItemState.Closed.ToString() || c.GetState() == WorkItemState.Removed.ToString()))
            {
                logger.LogTrace("Parent work item {0} has all children in Closed or Removed", parent?.Id);
                var targetState =
                    allChildren.Any(c => c.GetState() == WorkItemState.Closed.ToString()) ?
                    WorkItemState.Closed.ToString() :
                    WorkItemState.Removed.ToString();

                await UpdateWorkItemState(parent.Id.GetValueOrDefault(), targetState, reason);
            }
        }
예제 #2
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;
            }
        }