-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create vendor agnostic JSON format between issue data sources and consumers #74
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see the doc that you were putting together include some information about the structures involved here. For instance, a diagram showing the flow of data and what format the data is in at each point. I find the dashboard codebase difficult to navigate and, while much of that would be in the scope of a broader dashboard doc rather than your doc, diagrams would help with that.
|
||
if (window.Issue && window.IssueList) { | ||
if (window.Issue) { | ||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Since you're modifying this file, can you update the _reviewLevelMetadata query fields to use the casing now used in Monorail (Update-Daily, etc.)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
var label = data[i].labels[j]; | ||
registerSource('cz-monorail-issues', {owner: user.email}, function(issues) { | ||
for (var issue of issues) { | ||
for (var label of issue.labels) { | ||
if (label.substring(0, 2).toLowerCase() == 'm-') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this 'm-xx' label processing belongs in Issue.create as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
M doesn't really make sense for issues other than monorail, nor is it used by any other dash. I'd rather leave this behaviour scoped to this particular dash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added diagram to doc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm with nits
summary, | ||
labels, | ||
priority: undefined, | ||
_lastUpdatedMS: Date.parse(lastUpdatedString), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just occurred to me: Can we rely on Monorail and GitHub both providing lastUpdatedString in the same format, or at least both in formats that Date.parse will accept? Might need to add a precondition for Issue.create that specifies the format of the arguments (mainly lastUpdatedString, but possibly also labels).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added assertion.
var label = data[i].labels[j]; | ||
registerSource('cz-monorail-issues', {owner: user.email}, function(issues) { | ||
for (var issue of issues) { | ||
for (var label of issue.labels) { | ||
if (label.substring(0, 2).toLowerCase() == 'm-') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair call.
static reviewLevelWithBackoff(issue) { | ||
var result = issue._reviewLevel; | ||
if (result == _defaultReviewLevel) { | ||
result += ' (P' + this.priority + ')'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, missed this before. this.priority --> issue.priority?
This code assumed that this.priority would be defined because all Monorail issues had a Pri-X label. I don't think this will hold for GitHub. That might be something to change in future patches, however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, thanks!
Yes, I intend to deal with priority later when adding GitHub as a source.
Changed description to use BUG= notation. |
See associated bug. |
9f39135
to
00bcff2
Compare
This moves the abstraction from an IssueList to individual Issue objects. While I don't object to this, I'd like to see the change (and a justification) described in your design doc. |
In particular: everything is static on Issue now, including: Why the paradigm shift? |
|
||
// This class uses C style programming with JSON objects (representing issues) | ||
// and static methods. | ||
// This is to maintain the ability to clone the object in chromez-behaviours.js. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need to do this to allow objects to be cloned. You can either explicitly provide a clone() method, or serialize the representation automatically with json. Either way, methods on the object won't get in the way.
As I mentioned in the other comments, this is a major detail that needs to be included in design documentation. We should have been able to review this proposal before you went to the effort of coding it up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, this was a significant refactor to the Issue class that I should have included it in the design doc. I wouldn't have blocked coding it up on a proposal review though, a mechanical restructure of a single class takes <30 minutes while design review cycles are significantly longer than that.
I'll update design docs with refactor plans before starting them in future.
Extended clone() instead of changing the paradigm of Issue. Added IssueList back. PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Please change the Issue constructor to avoid it being a copy constructor, unless there are more users than the clone() method. I don't think copy constructors are idiomatic JavaScript).
behaviors: [ChromeZBehaviors.AJAXBehavior], | ||
|
||
onResponse: function(data) { | ||
data = JSON.parse(data); | ||
if (data.items == undefined) | ||
return []; | ||
return data.items.filter(a => a.ID !== ""); | ||
return new IssueList(data.items.filter(a => a.ID !== "").map(item => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider moving the crbug-specific constructor into the issue library?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issues-lib is supposed to be vendor agnostic code, I don't think it makes sense to put Crbug specific code in there. This function performs the transformation from Crbug issue data into generic issue data. Would you prefer it live in crbug-lib.js?
class Issue { | ||
constructor(params) { | ||
// Copy constructor | ||
if (params instanceof Issue) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is only used by clone, then it's simpler to directly construct around a copy of the params in clone than to switch every time an issue is constructed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed copy constructor.
Ping @shans. |
This change rewrites Monorail issue data in terms of a JSON format defined in issue-lib.js.
Producers of Monorail issue data (just cz-monorail-issues) pass data through issue-lib.js before calling callbacks.
Consumers of issue data use the JSON format defined in issue-lib.js along with associated helper functions.
The purpose of this change is to allow consumers of issue data to consume GitHub issue data via a common JSON format without needed rewrites in future patches.
There are no behavioural changes in this patch.
This change built on top of #73.
BUG=#72