forked from jbenet/depviz
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GetNodes: Shuffle around to return an array of nodes
This lets us use initial slugs that may map to multiple nodes (e.g. a per-repo slug) instead of the old keys which had to be one-to-one with nodes (e.g. a per-issue slug). Also some test shenanigans to get everything passing with 100% coverage. For reasons I don't understand, my attempt at atomic state pivots are still not sticking, which is why we still can't throw an error in the duplicate-dummy-requests-for-a-single-key case. I'm suspicious of [1]. But a change at duplicate requests isn't the end of the world either. [1]: facebook/react#6895
- Loading branch information
Showing
12 changed files
with
449 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
class GitHub { | ||
getIssues(user, repo) { | ||
return new Issues(user, repo); | ||
} | ||
|
||
search() { | ||
return new Search(); | ||
} | ||
} | ||
|
||
class Issues { | ||
constructor(user, repo) { | ||
this._user = user; | ||
this._repo = repo; | ||
this._calls = {}; | ||
} | ||
|
||
_getIssue(number) { | ||
if (this._calls[number]) { | ||
throw new Error( | ||
'duplicate call for github.com/' + | ||
this._user + '/' + this._repo + '#' + number | ||
); | ||
} | ||
this._calls[number] = true; | ||
if (number > 100) { | ||
return Promise.reject(new Error( | ||
'error making request GET https://api.github.com/repos/' + | ||
this._user + '/' + this._repo + '/issues/' + number | ||
)); | ||
} | ||
|
||
var dependencies = function (number) { | ||
switch (number) { | ||
case 1: | ||
return ['#10']; | ||
case 3: | ||
return ['#2', 'd3/d3#4356', 'gitlab.com/foo/bar#234']; | ||
case 5: | ||
return ['#3']; | ||
case 7: | ||
return ['#3']; | ||
case 10: | ||
return ['#3', '#7', '#5']; | ||
case 20: | ||
return ['foo/#3']; /* will be skipped */ | ||
default: | ||
return []; | ||
} | ||
}; | ||
|
||
return { | ||
body: dependencies(number).map(function (dep) { | ||
return 'depends on ' + dep; | ||
}).join('\n') + '\n', | ||
html_url: `https://github.com/${this._user}/${this._repo}/issues/${number}`, | ||
number: number, | ||
repository_url: `https://api.github.com/repos/${this._user}/${this._repo}`, | ||
state: number < 10 ? 'open' : 'closed', | ||
title: 'Some title for ' + number, | ||
user: { | ||
login: 'author' + number, | ||
}, | ||
}; | ||
} | ||
|
||
getIssue(number) { | ||
return Promise.resolve({data: this._getIssue(number)}); | ||
} | ||
|
||
listIssues() { | ||
return Promise.resolve({ | ||
data: [ | ||
this._getIssue(1), | ||
this._getIssue(2), | ||
] | ||
}); | ||
} | ||
} | ||
|
||
export class Search { | ||
forIssues(options) { | ||
var issues = new Issues('jbenet', 'depviz'); | ||
return issues.listIssues(); | ||
} | ||
} | ||
|
||
export default GitHub; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.