Skip to content
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

Merged
merged 14 commits into from
Oct 19, 2016

Conversation

alancutter
Copy link
Collaborator

@alancutter alancutter commented Oct 13, 2016

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

@alancutter alancutter changed the title Create vender agnostic JSON protocol between issue data sources and consumers Create vendor agnostic JSON protocol between issue data sources and consumers Oct 13, 2016
@alancutter alancutter changed the title Create vendor agnostic JSON protocol between issue data sources and consumers Create vendor agnostic JSON format between issue data sources and consumers Oct 13, 2016
Copy link
Collaborator

@suzyh suzyh left a 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;
}

Copy link
Collaborator

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.)?

Copy link
Collaborator Author

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-') {
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair call.

Copy link
Collaborator Author

@alancutter alancutter left a 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.

Copy link
Collaborator

@suzyh suzyh left a 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),
Copy link
Collaborator

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).

Copy link
Collaborator Author

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-') {
Copy link
Collaborator

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 + ')';
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

@alancutter
Copy link
Collaborator Author

Changed description to use BUG= notation.

@alancutter
Copy link
Collaborator Author

Where is the doc?

See associated bug.

@shans
Copy link
Owner

shans commented Oct 17, 2016

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.

@shans
Copy link
Owner

shans commented Oct 17, 2016

In particular: everything is static on Issue now, including:
(1) things that don't look like they should be static (e.g. computational methods that take a single issue)
(2) functions that take lists of issues (which is quite weird to do as a static method on Issue).

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.
Copy link
Owner

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.

Copy link
Collaborator Author

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.

@alancutter
Copy link
Collaborator Author

Extended clone() instead of changing the paradigm of Issue. Added IssueList back. PTAL.

Copy link
Owner

@shans shans left a 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 => {
Copy link
Owner

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?

Copy link
Collaborator Author

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) {
Copy link
Owner

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed copy constructor.

@alancutter
Copy link
Collaborator Author

Ping @shans.

@shans shans merged commit 2128369 into shans:master Oct 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants