Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auto-activates and resolves work items when child work items change
<rule name="AutoActivate" appliesTo="Task,User Story,Feature,Bug">
<![CDATA[
if((string)self["System.State"] == "Active")
{
string currentParentState = null;
var requirementTypeNames = new[] { "User Story", "Feature", "Epic" };
if(self.HasParent() && (currentParentState = (string)self.Parent["System.State"]) != "Active")
{
string reason;
if (requirementTypeNames.Contains(self.Parent.TypeName))
{
switch (currentParentState)
{
case "Closed":
reason = "Reintroduced in Scope";
break;
case "Resolved":
reason = "Acceptance tests fail";
break;
default: // New, Removed
reason = "Implementation started";
break;
}
}
else if (self.Parent.TypeName == "Bug")
{
switch (currentParentState)
{
case "Closed":
reason = "Reactivated";
break;
case "Resolved":
reason = "Not fixed";
break;
default:
reason = "Investigate";
break;
}
}
else
{
// Task
if (currentParentState == "Closed")
{
reason = "Reactivated";
}
else
{
reason = "Work started";
}
}
if(string.IsNullOrEmpty((string)self.Parent["System.AssignedTo"]) && !string.IsNullOrEmpty((string)self["System.AssignedTo"]))
{
self.Parent["System.AssignedTo"] = self["System.AssignedTo"];
}
self.Parent.TransitionToState("Active", reason);
}
}
]]>
</rule>
<rule name="AutoResolve" appliesTo="Task,User Story,Feature,Bug">
<![CDATA[
if(((string)self["System.State"] == "Closed" || (string)self["System.State"] == "Resolved") && self.HasParent() && ((string)self.Parent["System.State"]) != "Resolved")
{
var requirementTypeNames = new[] { "User Story", "Feature", "Epic", "Bug" };
var possibleStates = new [] { "Closed", "Removed", "Resolved" };
if(requirementTypeNames.Contains(self.Parent.TypeName))
{
if(self.Parent.Children.All(child => possibleStates.Contains((string)child["System.State"])))
{
string reason;
switch(self.Parent.TypeName)
{
case "User Story":
reason = "Code complete and unit tests pass";
break;
case "Feature":
reason = "Stories complete";
break;
case "Epic":
reason = "Features complete";
break;
case "Bug":
reason = "Fixed";
break;
default:
reason = "Work done - automatic resolve";
break;
}
self.Parent.TransitionToState("Resolved", reason);
}
}
}
]]>
</rule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment