-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathdomain.js
More file actions
247 lines (223 loc) · 8.32 KB
/
domain.js
File metadata and controls
247 lines (223 loc) · 8.32 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/**
* @fileoverview General definitions for the domain layer of the project
* dashboard. See the following diagram for an organizational breakdown of all
* the different structures present in the layer, their relationships, and how
* they correspond to data defined on GitHub.
*
* +---------------+
* | Product |
* +-----------------| (GitHub Repo) |---------------------+
* | +-------+-------+ |
* | | |
* | | |
* +--------v--------+ +----------v----------+ +-------------v----------+
* | Product Board | | Product | | |
* | (GitHub | | Milestones | | Team Boards |
* | Project Board) | | (GitHub Milestones) | |(GitHub Project Boards) |
* | | | | | |
* +-----------------+ +---------------------+ +------------------------+
* | | | | |
* | | | | |
* | +----v------------+ | | +----------------v----+
* | | Bugs + Misc. | | | | Bugs + Misc. |
* | | (GitHub Issues) | | | | (GitHub Issues) |
* | +-----------------+ | | +---------------------+
* | | |
* +------------------------------------------+
* |
* |
* +-------------|-------------+
* |Projects | |
* | | |
* | | |
* | +----------v----------+ |
* | | PTI: Project | |
* | | Tracking Issue | |
* | | (GitHub Issue) | |
* | +---------------------+ |
* | | |
* | | |
* | +----------v----------+ |
* | | Project Milestones | |
* | | (GitHub Milestones) | |
* | +---------------------+ |
* | | |
* | | |
* | +----------v----------+ |
* | | Bugs + Tasks | |
* | | (GitHub Issues) | |
* | +---------------------+ |
* | |
* +---------------------------+
*/
let _parseIssuesFromTitle = function(issueTitle, expectedPrefixes) {
const pattern = new RegExp(
`\\[(${expectedPrefixes.join("|")}):(#\\d+(,?#\\d+)*)\\]`, 'i');
const issueMatches = issueTitle.replaceAll(/\s/g, "").match(pattern);
if (issueMatches == null || issueMatches.length < 3) {
return []; // No issues are contained in the issue title.
}
// Retrieve just the group which corresponds to the list of issues.
const issueNumbers = issueMatches[2].split(",");
return issueNumbers.map(issueReference => issueReference.substr(1));
};
let _parseBlockingIssueFromTitle = function(issueTitle) {
return _parseIssuesFromTitle(issueTitle, ["blocking"]);
};
let _parseBlockedIssueFromTitle = function(issueTitle) {
return _parseIssuesFromTitle(issueTitle, ["blocked", "blockedby"]);
};
/** Represents an issue filed on GitHub. */
class Issue {
/** {String} - The issue number. */
id;
/** {String} - The title of the issue. */
title;
/** {String} - The body text of the issue's opening comment. */
bodyText;
/** {String} - A URL directly to the issue on GitHub. */
url;
/**
* {Array} - An array of strings corresponding to issue numbers that are
* blocking this issue.
*/
blockingIssueNumbers;
/**
* {Array} - An array of strings corresponding to issue numbers that are
* blocked by this issue.
*/
blockedIssueNumbers;
constructor(
id, title, bodyText, url, blockingIssueNumbers, blockedIssueNumbers) {
this.id = id;
this.title = title;
this.bodyText = bodyText;
this.url = url;
this.blockingIssueNumbers = blockingIssueNumbers;
this.blockedIssueNumbers = blockedIssueNumbers;
}
/**
* Creates a new issue object from a GraphQL-derived object. Note that this is
* heavily dependent on the query used to fetch the GraphQL data.
*
* @param {Object} issueObject - An object containing GraphQL query results
* for a single issue.
* @return {Issue} - The derived issue object.
**/
static createFromGraphql(issueObject) {
const id = issueObject.number;
const title = issueObject.title;
const bodyText = issueObject.bodyText;
const url = issueObject.url;
const blockingIssueNumbers = _parseBlockingIssueFromTitle(title);
const blockedIssueNumbers = _parseBlockedIssueFromTitle(title);
const projectCards = (issueObject.projectCards || {}).nodes || [];
// const projectIds = projectCards.map(card => card.project.number);
// const projectStages = projectCards.map(card => card.column.name);
// const milestoneId = (issueObject.milestone || {}).number;
return new Issue(
id, title, bodyText, url, blockingIssueNumbers, blockedIssueNumbers);
}
}
/**
* Represents a repository used for retrieving & performing operations on
* issues.
*/
class IssueRepository {
/** {Map} - A map from issue ID (String) to Issue. */
issueMap;
constructor(issueMap) {
this.issueMap = issueMap;
}
/**
* Returns an [Issue] corresponding to the specified issue number.
*
* @param {String} number - The issue number.
* @return {Issue} - The retrieved issue, or null if there is none
* corresponding to the specified number.
*/
retrieveIssue(number) {
return this.issueMap.get(number);
}
/**
* Creates a new issue repository from the results of specific GraphQL
* queries.
*
* @param {Object} ptisObject - An object containing GraphQL query results for
* all project tracking issues (PTIs) in the connected repository.
* @param {Object} allIssuesObject - An object containing GraphQL query results
* for all issues in the connected repository.
* @return {IssueRepository} - The derived issue repository object.
**/
static createFromGraphql(ptisObject, allIssuesObject) {
const ptiIssues = ptisObject.nodes.map(
ptiNode => Issue.createFromGraphql(ptiNode));
const ptiIssueIds = ptiIssues.map(ptiIssue => ptiIssue.id);
const nonPtiIssueNodes = allIssuesObject.nodes.filter(
node => !ptiIssueIds.includes(node.number));
const nonPtiIssues = nonPtiIssueNodes.map(
issueNode => Issue.createFromGraphql(issueNode));
const issueMap = new Map();
for (const ptiIssue of ptiIssues) {
issueMap.set(ptiIssue.id, ptiIssue);
}
for (const nonPtiIssue of nonPtiIssues) {
issueMap.set(nonPtiIssue.id, nonPtiIssue);
}
return new IssueRepository(issueMap);
};
};
/** Corresponds to a milestone that's part of a broader project. */
class ProjectMilestone {
milestoneId;
estimatedDurationDays;
}
class Project {
id;
title;
description;
projectLead;
productManagers;
technicalLead;
productStage;
productMilestoneId;
teamId;
projectMilestones;
estimatedStartDate;
actualStartDate;
roughEstimatedProjectDurationDays;
estimatedProductDesignDurationDays;
estimatedTechnicalDesignDurationDays;
estimatedVerificationDurationDays;
actualFinishDate;
}
class ProjectDatabase {
projectMap;
// TODO(jasamina13): Add support for:
// - Retrieving dependent issues for a project.
// - Retrieving dependent projects for a project.
}
export const MilestoneType = Object.freeze({
UNKNOWN: 0,
PRODUCT: 1,
PROJECT: 2
});
class Milestone {
id;
url;
title;
description;
progressPercentage;
issueIds;
}
class MilestoneRepository {
milestoneMap;
}
class Team {
id;
projectBoardUrl;
teamName;
}
class TeamRepository {
teamMap;
}