Skip to content

Instantly share code, notes, and snippets.

@dasMulli
Created March 24, 2017 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dasMulli/b89d545c68a7de4c455280b31314f50e to your computer and use it in GitHub Desktop.
Save dasMulli/b89d545c68a7de4c455280b31314f50e to your computer and use it in GitHub Desktop.
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