-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIssue.cs
81 lines (75 loc) · 2.61 KB
/
Issue.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace LIRA
{
public class Issue
{
public readonly DateTime creationTime = DateTime.Now;
public IssueState state { get; private set; }
public readonly IssueType type;
private Issue? parent;
private List<Issue> children = new List<Issue>();
public readonly string title;
public Issue(string title, IssueType type)
{
state = IssueState.TODO;
this.title = title;
this.type = type;
}
public void SetState(IssueState state)
{
if (state == IssueState.DONE)
{
// Check if children and grandchildren are done
InvalidOperationException ex = new InvalidOperationException("Cannot set state to done when children/grandchildren aren't done");
if (!areChildrenDone()) throw ex;
foreach (var child in children)
{
if (!child.areChildrenDone()) throw ex;
}
}
this.state = state;
}
private bool areChildrenDone()
{
foreach (var child in children)
{
if (!(child.state == IssueState.DONE)) return false;
}
return true;
}
public void SetParent(Issue parent)
{
if (this.parent == parent) return;
switch(this.type)
{
case IssueType.EPIC:
throw new InvalidOperationException("Epics are always orphans :(");
case IssueType.FEATURE:
if (parent.type == IssueType.EPIC)
{
this.parent = parent;
this.parent.children.Add(this);
return;
} else
{
throw new InvalidOperationException("Features can only have Epics as parents");
}
case IssueType.TASK:
if (parent.type == IssueType.EPIC || parent.type == IssueType.FEATURE)
{
this.parent = parent;
this.parent.children.Add(this);
return;
} else
{
throw new InvalidOperationException("Tasks only have Features and Epics as parents");
}
}
}
}
}